Hello,
i build a small 8 step sequencer, how can I get it to work with real BPM?
right now I have a default delay of 50ms between each step, and another 50ms for LED blink.
If my math is right it should be 7500ms for each step to get 60 BPM. is that right?
I also have a button to increase the delay by 50ms.
Is there a usual way to do this?
Use a Timer, much better timing. Here's my code for the timer.
void timerStart()
{
TCCR1A = TCCR1B = 0;
bitWrite(TCCR1B, CS11, 1);
bitWrite(TCCR1B, WGM12, 1);
timerSetFrequency();
bitWrite(TIMSK1, OCIE1A, 1);
}
void timerSetFrequency()
{
// Calculates the Frequency for the Timer, used by the PPQ clock (Pulses Per Quarter Note) //
// This uses the 16-bit Timer1, unused by the Arduino, unless you use the analogWrite or Tone functions //
#define frequency (((midiClockBPM)*(PPQ))/60)
OCR1A = (F_CPU/ 8) / frequency - 1;
}
void timerStop(void)
{
bitWrite(TIMSK1, OCIE1A, 0);
TCCR1A = TCCR1B = OCR1A = 0;
}
ISR(TIMER1_COMPA_vect)
{
// here's your clock code
}
BTW: on my code for Beat707 I use less PPQ, so I just use a counter variable to check when a step is due or not. I like to keep things at 96 PPQ for the midi clock shuffle. I can get you more details over this after tomorrow if you want me to.
thnx for that code, i still dont understand a thing of that, but I will take my time to do so.
I seens some videso of your sequencer, very nice project.
solved:
Right now(after i included a play button) I have the problem that the sequence changes tempo each
time, one fast one slower. Would this be gone if I could include your code?
(it was the switch i was using, this happens only if the circuit ist closed)
Now, just add some code to change midiClockSteps[] in real-time to edit the steps for each of the 4 tracks. And its easy to add more tracks if you want to.
Now, there's an important thing I forgot to mention... you can't use millis() or delay() at all. Use the following code instead, otherwise midi-timing will be bad...
// The Following is to implement millis() and delay() without messing up with the midi clock interrupt calls //
extern volatile unsigned long timer0_millis;
unsigned long millisNI(void) { return timer0_millis; }
void delayNI(unsigned long ms)
{
unsigned long endtime;
endtime = timer0_millis + ms;
while (((long)endtime - (long)timer0_millis) > 0)
{
;
}
}
i tried to exchange my delay with your delayNI.
sadly the sequencer doenst start at all, it doesnt even start when I just enter your function and use the normal delay.
Did you realize your project alone or did you have help?
Im thinking about joining someone, i have good iedas, but my C programming lacks a bit
is my code that bad?
Its supposed to be a old style sequencer where you have a potentiometer for each step.
Is it wise to use a simple "for" to programm a sequence or are there better ways in microcontroller programming?