The microBeat – DIY Rhythmbox

microBeat

Need a tempo maker or metronome for your jam session?
How about this key fob sized drum machine?

Comes in 2 flavours, Minipops or Dance.

This is the PCB for the 8-Pin u02 Minipops or the uD8 Dance chip.

Render

uO2chipuD8chipuO2sch

It has potentiometers for tempo and pattern, switch for run/stop and power, leds for clock/reset outputs and a CR2032 battery holder in the back.
(Can also run on dual AA or AAA batteries, 3V)

Measuring only 61x41mm makes the microBeat rhythmbox pocket sized.

The PCB and u02/uD8 chip can be purchased at DSP Synthesizers

Here you can order the PCB/Chip combo or a full kit:

Order the PCB/Chip Combo $30

Order the Full kit including knobs $50

The code is the same as the O2 source-code but adapted for the ATtiny85 flash size.

Here is a demo for the microBeat Minipops version:

And for sure you want the code.

How did I squeeze the O2 into a tiny with only 8kb flash?

My work on these free synthesizers is based on donations from people.
If you find the code useful, please consider a $3 donation to keep future developments open source.

Donate $3

Here is the code:

// The uO2 minipops rhythmbox

// https://janostman.wordpress.com/the-microbeat-diy-rhythmbox/

 

// Copyright 2017 DSP Synthesizers Sweden.

//

// Author: Jan Ostman

//

// This program is free software: you can redistribute it and/or modify

// it under the terms of the GNU General Public License as published by

// the Free Software Foundation, either version 3 of the License, or

// (at your option) any later version.

// This program is distributed in the hope that it will be useful,

// but WITHOUT ANY WARRANTY; without even the implied warranty of

// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

// GNU General Public License for more details.

 

//Set fuses to E2 DF FF

 

#include <avr/interrupt.h>

#include <avr/io.h>

#include <avr/pgmspace.h>

 

 

#ifndef cbi

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#endif

#ifndef sbi

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#endif

 

 

 

 

 

 

//——— Ringbuf parameters ———-

uint8_t Ringbuffer[256];

uint8_t RingWrite=0;

uint8_t RingRead=0;

volatile uint8_t RingCount=0;

volatile uint16_t SFREQ;

//—————————————–

 

//Patterns GU BG2 BD CL CW MA CY QU

/*

16 steps

————

Hard rock

Disco

Reggae

Rock

Samba

Rumba

Cha-Cha

Swing

Bossa Nova

Beguine

Synthpop

 

12-steps

———

Boogie

Waltz

Jazz rock

Slow rock

Oxygen

 

*/

 

//const unsigned char patlen[16] PROGMEM = {15,15,15,11,15,11,11,11,15,15,15,15,15,15,15,11};

 

const unsigned char patlen[16] PROGMEM = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 11, 11, 11, 11, 11};

 

 

const unsigned char pattern[256] PROGMEM = {

B00101100, //Hard rock16

B00000000,

B00000100,

B00000000,

B00101110,

B00000000,

B00100100,

B00000000,

B00101100,

B00000000,

B00000100,

B00000000,

B00101110,

B00000000,

B00000100,

B00000000,

 

B00100100, //Disco16

B00000000,

B00000100,

B00010100,

B00100110,

B00000000,

B00000001,

B00000100,

B00100100,

B00000000,

B00000100,

B00000100,

B01100110,

B00000100,

B01000001,

B00000000,

 

B01000001, //Reegae16

B00000100,

B10000000,

B00000000,

B00010110,

B00000000,

B10010000,

B00000000,

B00100000,

B00000000,

B10010000,

B00000000,

B00000110,

B00000000,

B10000100,

B00000000,

 

B00100100, //Rock16

B00000000,

B00000100,

B00000000,

B00000110,

B00000000,

B00100100,

B00000000,

B00100100,

B00000000,

B00000100,

B00000000,

B00000110,

B00000000,

B00000110,

B00000000,

B10110101, //Samba16

B00010100,

B10000100,

B00010100,

B10110100,

B00000100,

B01000100,

B10010100,

B00100100,

B10010100,

B01000100,

B10010100,

B10110101,

B00000100,

B10010100,

B00000100,

 

B00100110, //Rumba16

B00000100,

B00000001,

B00110100,

B00100100,

B00000001,

B00010110,

B00000100,

B00100100,

B00000100,

B00010001,

B00100100,

B00110100,

B00000100,

B01000001,

B00000100,

 

B00100100, //Cha-Cha16

B00000000,

B00000000,

B00000000,

B00000110,

B00000000,

B01000000,

B00000000,

B00100100,

B00000000,

B00000010,

B00000000,

B01000101,

B00000000,

B00000010,

B00000000,

 

B00100100, //Swing16

B00000000,

B00000000,

B00000000,

B00000100,

B00000000,

B00000000,

B00000100,

B00000100,

B00000000,

B00000000,

B00000000,

B00000100,

B00000000,

B00000000,

B00000100,

 

B00100001, //Bossa Nova16

B00000100,

B00000100,

B00100100,

B00100001,

B00000100,

B01000100,

B00000100,

B00100001,

B00000100,

B00000100,

B00100000,

B00100001,

B01000101,

B00000100,

B00000100,

 

B00100110, //Beguine16

B00000000,

B00000001,

B00000000,

B00000100,

B00000000,

B01100110,

B00000000,

B00100100,

B00000000,

B01000100,

B00000100,

B00100110,

B00000000,

B00000100,

B00000000,

 

B10100000, //Synthpop16

B00000000,

B10100010,

B00000000,

B00100000,

B00000000,

B00100110,

B00000100,

B01100000,

B00000000,

B01100110,

B00000100,

B00100000,

B00000000,

B00100010,

B10001000,

 

B00100000, //Boogie12

B00000000,

B00100100,

B00000110,

B00000000,

B00100100,

B00100100,

B00000000,

B00100100,

B00000110,

B00000000,

B00100100,

 

B00000000,

B00000000,

B00000000,

B00000000,

 

B00100100, //Waltz12

B00000000,

B00000000,

B00000000,

B00010010,

B00000000,

B00000000,

B00000000,

B00010010,

B00000000,

B00000000,

B00000000,

 

B00000000,

B00000000,

B00000000,

B00000000,

 

B00100110, //Jazz rock12

B00000000,

B00000100,

B00000000,

B00000110,

B00000000,

B00000100,

B00000000,

B00000110,

B00000000,

B01100000,

B00000000,

 

B00000000,

B00000000,

B00000000,

B00000000,

 

B00100100, //Slow rock12

B00000000,

B00000100,

B00000000,

B00000100,

B00000000,

B00000110,

B00000000,

B00000100,

B00000000,

B00100100,

B00000000,

 

B00000000,

B00000000,

B00000000,

B00000000,

 

B00100101, //Oxygen12

B00001100,

B00000100,

B00101110,

B00000100,

B00010100,

B00100101,

B00000100,

B00000100,

B00101100,

B00000100,

B11100100,

B00000000,

B00000000,

B00000000,

B00000000

 

};

 

const unsigned char BD[270] PROGMEM =

{

125,111,101,95,93,92,92,94,96,99,102,105,108,112,115,118,122,125,129,132,135,138,141,144,147,150,153,155,157,159,161,163,164,165,166,167,168,168,168,168,167,167,166,165,164,162,161,159,157,155,152,150,148,145,142,140,137,134,131,129,126,123,120,118,115,113,110,108,106,104,102,100,99,97,96,95,94,93,92,92,92,91,91,92,92,93,93,94,95,96,97,99,100,102,104,106,

108,110,112,114,116,118,120,123,125,127,129,132,134,136,138,140,142,144,145,147,148,150,151,152,153,154,155,155,156,156,156,156,156,155,155,154,153,152,151,150,149,147,146,144,143,141,139,138,136,134,133,131,130,128,126,125,124,122,121,120,119,118,117,116,115,114,114,113,113,112,112,112,112,112,112,112,113,113,113,114,114,115,116,116,117,118,119,119,120,121,122,123,124,125,125,126,127,128,129,129,

130,131,131,132,133,133,134,134,134,135,135,135,135,135,136,136,136,135,135,135,135,135,135,134,134,134,133,133,133,132,132,132,131,131,131,130,130,130,129,129,129,128,128,128,128,127,127,127,127,127,127,127,127,127,126,127,127,127,127,127,127,127,127,127,127,127,127,127,128,128,128,128,128,128

};

 

const unsigned char BG2[284] PROGMEM =

{

125,88,82,120,166,206,221,210,174,122,67,23,2,10,43,95,153,203,234,239,219,179,129,81,48,36,49,82,127,172,206,222,215,188,149,105,68,47,46,65,99,139,175,198,204,191,163,127,91,65,54,61,84,116,150,177,192,190,173,146,115,87,70,66,78,101,130,157,177,184,178,159,134,109,88,77,79,93,115,139,160,173,175,166,148,126,105,90,85,90,104,124,144,160,168,166,

156,139,120,103,93,92,99,113,131,147,158,162,158,147,132,116,103,98,99,107,120,135,148,155,156,151,140,126,114,105,102,105,114,126,138,147,152,151,144,134,123,113,107,106,111,119,130,139,146,148,146,139,130,120,113,110,110,116,124,132,140,144,145,141,135,127,119,114,112,114,119,127,134,139,142,141,137,131,125,119,115,115,118,123,129,135,139,140,139,134,129,123,119,117,117,121,125,131,135,138,

138,136,132,127,123,120,119,120,123,127,131,135,136,136,134,130,126,122,120,120,122,125,129,132,134,135,134,132,128,125,123,121,122,124,126,130,132,134,134,133,130,127,125,123,122,123,125,128,130,132,133,133,131,129,127,125,123,123,124,126,128,130,132,132,132,130,128,126,125,124,125,126,127,129,130,131,131,130,129,128,127,126,126,127,127,128,129,129

};

 

const unsigned char CL[188] PROGMEM =

{

92,140,118,88,199,86,217,108,166,133,90,147,49,151,71,145,132,133,182,116,184,104,144,105,98,123,81,148,101,162,137,150,158,120,151,94,129,94,113,120,113,152,124,164,133,147,131,115,125,96,124,102,130,128,137,150,134,152,123,134,113,114,115,108,129,119,144,135,146,141,132,134,114,123,108,119,118,125,136,133,146,135,141,128,125,121,113,120,115,129,127,137,139,138,140,129,

130,118,120,116,119,125,126,136,134,140,135,133,129,122,122,116,122,121,128,131,134,138,134,135,127,126,120,119,120,121,127,128,134,134,135,133,129,127,121,122,119,122,124,128,132,133,135,132,131,127,124,122,120,123,124,128,130,133,134,133,131,127,126,122,122,122,124,127,129,132,132,133,130,129,126,125,125,124,126,127,129,129,130,130,129,128,128,127,127,127,128,128

};

 

const unsigned char CW[208] PROGMEM =

{

150,127,118,144,152,139,113,103,117,143,152,139,114,105,118,142,150,136,114,107,121,142,149,134,113,108,122,143,148,133,113,108,123,142,147,132,113,109,124,143,146,131,113,111,126,143,144,129,113,112,127,143,143,128,113,113,128,143,142,126,113,114,129,143,140,126,113,116,130,142,139,125,113,117,132,142,138,124,114,118,132,142,137,123,114,120,134,141,135,122,114,121,134,141,134,121,

115,122,135,140,133,120,116,123,135,140,132,120,116,124,136,139,131,120,117,125,136,138,129,119,118,127,137,137,128,119,119,128,137,137,127,119,119,129,137,136,126,119,120,129,137,135,126,119,121,130,137,134,125,119,122,131,136,133,124,119,123,132,136,132,123,119,124,132,136,131,123,119,125,133,136,130,122,120,126,133,135,129,122,121,127,133,134,128,123,123,127,132,132,128,124,125,128,131,130,128,

125,126,128,130,129,128,127,127,128,128,128,128

};

 

const unsigned char CY[2358] PROGMEM =

{

131,116,126,129,96,38,42,119,141,135,108,167,150,141,163,138,129,165,154,117,146,139,156,106,139,165,127,118,149,129,138,116,141,116,117,148,112,140,127,116,131,135,129,127,127,92,161,125,127,125,121,112,154,104,120,152,108,150,118,132,121,118,148,110,123,148,111,138,120,130,141,122,122,117,138,118,133,115,150,117,118,142,126,137,102,155,109,132,118,138,136,115,132,115,138,124,

131,127,138,121,128,130,114,142,119,125,134,130,120,132,122,145,106,137,124,154,104,132,130,113,134,127,132,120,129,125,139,118,124,136,111,148,120,132,128,112,160,109,124,135,138,110,143,124,112,149,112,136,125,128,126,123,133,127,134,119,139,123,124,126,133,125,126,125,133,127,117,126,143,120,122,123,134,121,124,133,116,130,122,138,113,125,139,115,130,129,123,127,127,123,123,129,127,128,130,122,

127,130,123,129,127,123,134,121,142,115,128,131,126,120,139,118,129,132,123,134,119,133,131,133,122,135,115,137,128,124,129,125,127,125,135,119,134,117,135,134,121,129,136,125,122,137,121,130,132,125,129,128,125,133,126,129,131,120,142,119,131,124,123,133,121,141,119,136,115,138,133,120,139,121,131,124,137,123,130,122,137,119,133,134,118,128,137,127,114,143,127,121,136,130,125,125,126,126,132,128,

125,132,129,119,133,131,130,130,125,130,130,130,121,133,130,126,134,121,132,124,134,127,123,129,131,119,139,123,129,126,134,123,131,131,123,131,124,135,123,133,128,133,121,141,116,135,131,126,125,129,133,121,138,126,129,127,132,132,121,143,123,121,133,121,144,120,127,137,120,134,125,134,127,125,132,123,131,135,119,131,130,129,120,135,129,126,129,128,129,124,129,131,122,134,129,118,134,125,127,130,

134,125,126,129,128,128,130,135,123,130,131,125,132,122,135,127,132,124,128,136,123,135,121,132,133,129,126,125,133,130,121,139,123,132,131,128,129,124,140,122,130,131,122,132,126,131,136,121,137,128,130,123,130,135,129,121,136,131,121,138,124,139,124,127,127,131,132,132,124,130,125,130,131,125,131,128,126,129,126,134,123,131,131,122,133,124,133,124,131,125,133,131,121,129,128,130,131,131,125,132,

123,134,119,135,127,123,129,128,132,126,134,121,136,118,142,120,131,129,122,134,128,133,121,128,134,121,138,128,126,126,130,130,129,127,123,133,130,130,121,144,125,129,128,129,129,124,135,127,129,135,128,126,132,133,123,138,125,127,133,127,139,118,134,126,136,122,130,134,125,131,127,132,127,128,125,129,128,127,131,132,125,129,127,134,122,133,126,129,130,128,123,130,129,130,130,124,136,123,130,131,

123,130,131,123,130,129,123,141,121,129,126,132,123,132,129,128,131,133,128,128,130,120,135,129,133,127,131,125,132,129,128,129,128,131,127,134,127,123,136,128,129,128,134,127,130,127,131,129,125,138,128,128,127,129,131,129,125,132,130,128,129,129,129,129,129,128,127,127,130,132,129,128,127,127,133,124,133,127,128,129,128,124,133,128,120,136,129,122,132,127,125,131,123,136,125,128,130,123,137,119,

133,131,125,131,127,127,130,128,123,138,122,133,127,124,133,130,128,130,127,131,130,127,129,129,132,127,126,133,127,133,131,120,132,128,128,130,127,132,129,129,132,128,132,123,128,135,127,132,131,127,137,122,128,128,127,132,131,126,129,130,129,130,127,131,126,128,126,131,128,127,129,128,130,128,128,126,133,127,129,127,132,132,123,129,129,129,128,127,127,129,131,126,129,129,121,136,123,131,128,125,

134,123,134,125,131,128,128,128,122,135,123,132,122,134,130,127,127,129,132,126,128,123,134,128,129,127,130,130,128,132,124,129,127,134,128,123,133,126,130,128,131,128,127,132,126,130,131,128,129,130,130,129,129,133,128,131,128,128,131,131,127,130,129,129,131,122,136,125,129,132,125,130,126,131,128,131,128,126,131,124,130,129,126,128,126,130,126,129,124,130,125,131,129,124,129,127,133,127,126,129,

127,132,127,126,129,129,128,129,130,127,135,124,131,126,131,128,129,130,127,134,123,132,130,130,132,124,127,133,128,125,134,125,131,126,135,125,128,130,124,134,128,126,130,129,125,135,125,130,131,130,129,127,136,129,127,130,130,131,126,127,135,127,129,130,125,136,124,130,126,131,128,127,128,126,134,127,130,127,129,126,131,126,130,125,131,128,130,127,129,127,128,131,127,125,130,131,127,126,129,128,

127,128,128,130,127,129,125,131,129,129,128,129,127,129,129,127,132,129,125,134,127,127,132,128,127,128,130,130,130,129,134,126,129,130,127,129,129,130,129,132,125,132,125,133,131,131,123,135,129,127,131,125,136,129,127,130,128,132,125,130,130,127,130,126,134,127,128,128,128,131,127,130,126,131,130,128,127,131,127,130,130,127,131,126,130,127,128,128,129,128,130,127,130,126,128,129,126,130,128,129,

127,131,124,128,131,128,128,129,127,123,133,126,132,126,130,128,129,126,130,128,126,131,129,129,129,124,131,126,128,128,129,129,125,135,127,128,132,126,130,128,129,129,130,130,128,127,127,132,127,131,125,131,131,126,129,129,127,131,131,128,130,127,127,132,128,129,128,130,129,130,131,127,127,128,131,131,128,127,127,126,128,127,129,126,129,128,127,127,128,130,127,126,127,129,126,128,127,129,130,127,

130,126,129,129,127,129,130,126,129,126,128,129,129,129,129,129,127,129,127,132,123,129,133,126,129,128,128,127,131,128,131,130,125,131,130,127,129,131,129,124,133,126,133,125,131,129,127,129,129,129,127,130,127,132,128,126,130,130,127,129,130,130,127,126,131,127,130,125,133,125,129,129,130,129,128,130,126,132,126,131,127,128,127,128,128,129,127,128,128,128,126,131,129,128,124,129,128,124,131,130,

128,125,129,129,127,130,128,130,128,126,131,128,128,127,128,127,129,126,129,126,129,126,129,129,128,126,127,133,128,126,130,129,127,129,127,127,128,129,127,131,130,130,127,129,127,129,129,129,130,125,135,127,129,134,127,129,129,131,129,125,135,127,130,129,128,128,127,129,127,130,126,130,128,127,128,128,128,126,129,127,127,129,129,128,127,129,129,130,126,128,126,129,128,128,129,126,129,128,128,130,

128,128,126,127,127,128,128,127,128,129,128,130,128,130,130,124,129,127,128,129,128,127,129,130,130,125,131,127,128,128,127,129,125,130,129,131,127,130,129,129,128,128,130,127,130,129,130,130,129,129,127,129,130,129,130,128,128,128,131,128,129,128,128,132,126,128,130,130,127,129,130,127,128,128,130,126,129,127,130,124,127,131,125,127,128,127,129,130,129,125,128,128,125,131,124,128,128,130,128,126,

130,126,131,127,128,128,127,129,129,128,129,128,130,126,131,128,128,129,125,129,128,129,127,130,129,129,128,129,128,128,128,127,127,131,130,130,129,128,129,129,130,127,131,126,130,130,129,129,130,128,131,127,129,128,129,128,128,129,129,126,130,128,129,131,123,130,127,129,127,129,130,127,130,127,131,125,129,128,129,128,127,128,129,129,128,128,129,128,128,129,129,129,125,127,130,126,127,129,126,127,

125,131,127,129,126,127,129,128,130,126,130,130,128,128,127,129,127,128,128,131,126,128,131,129,129,129,131,124,131,124,130,128,128,129,128,130,127,130,127,131,129,126,128,128,127,130,130,127,130,129,127,130,128,128,129,127,129,125,129,129,127,130,127,129,126,129,130,128,128,130,127,129,127,127,128,129,128,125,130,126,127,128,130,127,125,131,127,129,129,126,129,127,127,129,128,128,128,125,130,127,

127,128,128,126,129,127,126,128,129,131,127,128,129,130,128,129,129,127,127,128,128,130,127,128,129,128,128,127,127,128,129,130,129,128,128,129,129,128,129,128,129,130,128,127,131,127,132,127,132,128,128,131,128,130,129,130,127,129,130,129,129,128,131,127,130,128,128,128,129,130,128,130,128,128,129,127,129,128,128,128,127,127,127,126,129,128,127,129,127,127,126,127,129,129,127,130,128,126,128,127,

128,127,127,128,125,130,130,129,126,128,128,129,128,127,131,127,128,129,129,128,129,128,127,128,128,128,128,130,127,129,128,130,128,128,130,128,129,130,129,129,129,128,131,128,131,127,130,130,127,130,128,128,129,130,128,128,128,131,128,128,129,128,127,127,128,128,129,129,128,128,127,130,127,129,129,128,129,125,129,126,131,126,130,129,126,129,128,129,128,130,125,128,128,126,129,127,128,127,130,126,

130,127,126,128,130,127,130,126,128,128,127,129,126,128,129,128,127,130,128,130,128,128,126,129,127,128,130,128,126,129,128,129,128,128,126,128,129,127,129,125,130,127,128,128,129,128,128,130,127,129,129,129,128,132,127,129,129,127,129,129,130,128,127,130,129,129,129,128,128,129,127,129,126,129,129,127,128,128,128,127,128,125,129,127,129,128,128,128,127,128,128,127,127,128,127,127,126,128,128,126,

128,128,127,127,129,125,129,128,129,126,128,128,127,129,127,130,127,129,127,128,130,127,129,130,130,129,128,129,129,130,128,128,129,128,130,127,129,128,128,130,128,128,129,129,128,129,128,129,129,127,129,129,128,129,131,128,130,130,128,128,128,128,128,128,130,126,128,131,128,127,128,130,127,128,128,129,128,126,128,128,127,126,130,126,128,126,127,128,128,129,126,129,128,125,128,127,127,128,128,128,

128,128,128,127,126,127,127,127,129,128,127,130,126,130,129,128,126,128,127,128,129,125,130,128,127,130,128,130,127,125,130,129,129,128,128,127,129,129,128,128,128,129,127,128,129,130,127,129,128,129,130,129,130,129,130,129,127,131,129,128,129,128,128,127,130,128,128,128,128,128,127,129,127,127,128,127,126,128,130,127,128,127,128,127,127,126,127,130,128,129,126,127,129,128,127,128,128,128,127,130,

127,126,128,126,129,129,129,128,127,126,129,128,128,128,128,129,130,128,128,128,130,130,128,129,129,128,128,128,127,127,129,129,129,129,128,129,128,127,128,129,128,128,128,129,127,128,128,130,130,130,129,129,130,129,128,127,129,129,129,129,129,128,128,129,128,128,129,127,127,129,128,129,127,129,128,128,129,129,130,128,128,128,128,128,128,128,129,128,127,128,128,126,127,129,128,129,129,129,127,129,

128,127,128,128,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128

};

 

const unsigned char GU[704] PROGMEM =

{

169,55,207,138,99,153,105,145,113,139,115,139,119,136,121,134,122,133,124,132,125,131,125,130,126,130,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,127,129,127,129,127,129,127,128,128,128,128,127,129,126,131,124,133,115,135,117,143,105,159,55,187,116,102,149,110,141,112,139,113,137,120,135,121,134,123,133,124,132,

125,131,126,130,126,130,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,129,127,130,126,130,126,130,126,129,127,129,127,129,128,127,129,126,132,115,136,111,155,61,202,85,108,134,110,136,113,135,115,135,121,134,122,133,123,132,124,132,125,131,125,130,126,130,126,129,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,

128,129,127,129,127,129,127,129,127,129,127,129,126,130,126,130,126,130,126,130,126,129,127,129,128,128,129,125,133,118,136,110,155,55,217,92,116,140,112,136,113,136,115,136,118,134,122,133,123,133,124,132,125,131,125,130,126,130,126,129,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,128,128,128,127,

129,126,131,117,128,117,141,103,161,52,201,112,109,145,107,143,114,138,114,137,120,135,122,134,123,133,124,132,125,131,125,130,126,130,127,129,127,129,127,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,130,126,130,126,130,126,130,126,130,126,130,126,130,124,124,120,122,125,123,134,115,149,57,198,74,122,131,115,132,116,133,121,135,122,134,123,133,

123,132,124,132,125,131,125,130,126,130,126,129,127,129,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,128,128,128,128,129,127,130,119,126,115,131,115,142,103,158,52,207,118,101,149,106,140,112,139,113,137,119,136,121,134,123,133,124,132,125,131,125,130,126,130,127,129,127,129,127,129,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,129,127,130,126,130,126,130,126,129,127,129,127,128,128,127,130,125,133,118,133,112,154,54,218,99,117,138,113,139,112,136,115,136,121,135,122,134,123,133,124,132,125,131,125,130,126,130,126,129,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,128,128,

128,127,129,127,130,125,129,115,131,118,143,107,162,59,196,102,95,146,108,141,112,139,113,137,120,135,121,134,123,133,124,132,125,131,126,130,126,130,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,129,126,130,126,130,126,130,126,130,126,130,127,129,127,128,129,126,131,122,135,111,149,59,218,88,122,135,114,138,113,135,115,135,

121,135,122,134,123,133,124,132

};

 

 

const unsigned char MA[142] PROGMEM =

{

124,112,125,118,135,129,144,127,125,132,119,154,118,121,122,149,115,128,123,106,156,100,149,132,110,132,125,142,115,125,134,146,101,139,147,128,133,102,138,119,133,126,124,146,115,138,119,160,113,134,122,120,132,148,123,134,129,142,132,129,123,137,137,109,156,119,151,124,128,140,123,138,131,131,129,133,124,140,119,141,127,139,131,123,143,125,140,122,141,123,135,134,130,136,136,126,

138,128,130,140,133,134,123,135,137,123,133,130,131,133,128,131,128,136,132,127,133,124,127,133,128,135,126,127,128,128,127,128,121,133,128,126,121,129,129,124,124,126,128,126,129,127

};

 

const unsigned char QU[1928] PROGMEM =

{

108,185,83,139,127,120,139,113,143,111,144,112,142,115,140,117,137,120,135,122,133,124,131,126,129,128,127,131,124,134,121,138,115,147,100,195,45,155,126,137,155,89,158,102,151,109,145,114,140,118,137,122,134,124,132,126,131,127,130,128,129,128,129,129,128,129,128,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,126,130,126,130,126,131,125,131,124,132,124,133,123,133,122,134,122,135,121,135,120,136,121,135,172,38,183,101,149,118,137,124,131,128,127,130,126,130,126,131,126,131,126,130,126,130,126,130,126,130,126,130,127,129,127,129,127,129,127,129,127,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,127,129,127,129,127,129,127,129,127,121,142,121,132,124,130,127,129,128,129,128,128,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,127,130,126,130,125,131,124,132,123,133,122,135,120,138,116,142,109,158,120,94,160,108,147,115,140,119,136,122,133,124,132,125,130,

126,130,127,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,130,126,129,131,126,130,127,129,128,129,128,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,

126,130,125,132,123,136,116,156,100,131,133,124,135,122,133,123,132,124,132,125,131,125,130,126,130,126,130,127,129,127,129,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,127,129,127,129,127,129,127,129,127,129,126,130,126,130,126,130,125,131,125,132,124,133,136,105,144,120,135,124,132,126,130,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,127,129,126,130,125,132,122,141,116,128,132,126,131,126,131,126,130,126,130,127,130,127,129,127,129,127,129,127,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,127,129,127,129,127,130,126,130,125,132,130,119,135,125,132,126,131,127,129,128,129,128,129,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,127,129,126,133,121,130,

128,128,128,128,129,127,128,127,128,127,129,127,129,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,129,127,129,127,129,126,131,126,126,130,126,129,127,129,127,129,127,129,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,

128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128

};

 

ISR(TIMER0_COMPA_vect) {

//——————- Ringbuffer handler ————————-

if (RingCount) { //If entry in FIFO..

OCR1A = Ringbuffer[(RingRead++)]; //Output LSB of 16-bit DAC

RingCount–;

}

//—————————————————————–

}

 

 

 

 

void setup() {

OSCCAL=255;

// Enable 64 MHz PLL and use as source for Timer1

PLLCSR = 1<<PCKE | 1<<PLLE;

 

// Set up Timer/Counter1 for PWM output

TIMSK = 0; // Timer interrupts OFF

TCCR1 = 1<<PWM1A | 2<<COM1A0 | 1<<CS10; // PWM A, clear on match, 1:1 prescale

//GTCCR = 1<<PWM1B | 2<<COM1B0; // PWM B, clear on match

OCR1A = 128; //OCR1B = 128; // 50% duty at start

 

pinMode(1, OUTPUT); // Enable PWM output pin

pinMode(2, OUTPUT); // Reset output

pinMode(0, OUTPUT); // Clock output

 

//Set up Timer/Counter0 for 5kHz interrupt to output samples.

TCCR0A = 3<<WGM00; // Fast PWM

TCCR0B = 1<<WGM02 | 2<<CS00; // 1/8 prescale

TIMSK = 1<<OCIE0A; // Enable compare match, disable overflow

OCR0A = 199; // Divide by 400

 

uint16_t dummy=analogRead(0);

}

 

 

 

 

void loop() {

 

uint16_t samplecntBD,samplecntBG2,samplecntCL,samplecntCW,samplecntCY,samplecntGU,samplecntMA,samplecntQU;

 

samplecntBD=0;

samplecntBG2=0;

samplecntCL=0;

samplecntCW=0;

samplecntCY=0;

samplecntGU=0;

samplecntMA=0;

samplecntQU=0;

 

uint16_t samplepntBD,samplepntBG2,samplepntCL,samplepntCW,samplepntCY,samplepntGU,samplepntMA,samplepntQU;

int16_t total;

 

uint8_t stepcnt=0;

uint16_t tempo=1;

uint16_t tempocnt=1;

uint16_t LEDclock=1;

uint8_t MUX=2;

 

uint8_t patselect=13;

uint8_t patlength=pgm_read_byte_near(patlen + patselect);

 

sbi(ADCSRA, ADSC); //start next conversation

while(1) {

 

//—— Add current sample word to ringbuffer FIFO ——————–

if (RingCount<8) { //if space in ringbuffer

total=0;

if (samplecntBD) {

total+=(pgm_read_byte_near(BD + samplepntBD++)-128);

samplecntBD–;

}

if (samplecntBG2) {

total+=(pgm_read_byte_near(BG2 + samplepntBG2++)-128);

samplecntBG2–;

}

if (samplecntCL) {

total+=(pgm_read_byte_near(CL + samplepntCL++)-128);

samplecntCL–;

}

if (samplecntCW) {

total+=(pgm_read_byte_near(CW + samplepntCW++)-128);

samplecntCW–;

}

if (samplecntCY) {

total+=(pgm_read_byte_near(CY + samplepntCY++)-128);

samplecntCY–;

}

if (samplecntGU) {

total+=(pgm_read_byte_near(GU + samplepntGU++)-128);

samplecntGU–;

}

if (samplecntMA) {

total+=(pgm_read_byte_near(MA + samplepntMA++)-128);

samplecntMA–;

}

if (samplecntQU) {

total+=(pgm_read_byte_near(QU + samplepntQU++)-128);

samplecntQU–;

}

if (total<-127) total=-127;

if (total>127) total=127;

cli();

Ringbuffer[RingWrite]=total+128;

RingWrite++;

RingCount++;

sei();

 

//—————————————————————————-

 

//——— sequencer block ———————————————-

 

if (!(tempocnt–)) {

tempocnt=tempo;

LEDclock=tempocnt>>3;

digitalWrite(0,HIGH); //Clock out Hi

uint8_t trig=pgm_read_byte_near(pattern + (patselect<<4) + stepcnt);

if (stepcnt==0) digitalWrite(2,HIGH); //Reset out Hi

if (stepcnt!=0) digitalWrite(2,LOW); //Reset out Lo

if (trig & 1) {

samplepntQU=0;

samplecntQU=1928;

}

if (trig & 2) {

samplepntCY=0;

samplecntCY=2358;

}

if (trig & 4) {

samplepntMA=0;

samplecntMA=142;

}

if (trig & 8) {

samplepntCW=0;

samplecntCW=208;

}

if (trig & 16) {

samplepntCL=0;

samplecntCL=188;

}

if (trig & 32) {

samplepntBD=0;

samplecntBD=270;

}

if (trig & 64) {

samplepntBG2=0;

samplecntBG2=284;

}

if (trig & 128) {

samplepntGU=0;

samplecntGU=704;

}

stepcnt++;

if (stepcnt>patlength) stepcnt=0; //Reset pattern

}

if (!(LEDclock–)) {

digitalWrite(0,LOW); //Clock out Lo

LEDclock=tempocnt>>1;

}

}

 

//————————————————————————

 

 

 

//————— ADC block ————————————-

if (!(ADCSRA & 64)) {

 

uint16_t value=((ADCL+(ADCH<<8))>>3)+1;

if (MUX==3) tempo=((128-value)<<5)+312; //17633-1250

if (MUX==2) patselect=(value-1)>>3;

if (MUX==2) patlength=pgm_read_byte_near(patlen + patselect);

MUX++;

if (MUX==4) MUX=2;

ADMUX = MUX; //Select MUX

sbi(ADCSRA, ADSC); //start next conversation

}

//—————————————————————

}

}

 

 

Advertisements

%d bloggers like this: