Show Posts
Pages: 1 ... 38 39 [40] 41 42
586  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Midi Clock (PPQ) Wrong Math? on: December 11, 2010, 08:09:40 am
Nermind, my math for counting the PPQ and Beats was a bit wrong. <ultra shame face>

Here's the correct code for a very simple MIDI Clock with variable BPM and PPQ.

Code:
// Wusik.com (c) WilliamK 2010
// Serial 115200 //

boolean Started = false;
boolean badClock = false;
unsigned long startTime;
unsigned long currentTime;
unsigned long processedtime;
float BPM = 95.0f;
float PPQ = 96.0f;
float ppqtime;
float currentmicroTime;
float ppqmicroTime;
int beats = 0;
int ppqcounter = 0;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if (!Started)
  {
      Started = true;
      ppqtime = 60000000.0f / (BPM*PPQ);  // (60 x 1,000,000) / (BPM*PPQ)
      Serial.print("BPM: ");
      Serial.println(BPM);
      Serial.print("PPQ: ");
      Serial.println(PPQ);
      Serial.print("Micros PPQ: ");    
      Serial.println(ppqtime);
      beats = 0;
      ppqcounter = 0;
      startTime = millis();
      ppqmicroTime = (float)micros() + ppqtime;
  }  

  currentmicroTime = (float)micros();
  if (currentmicroTime >= ppqmicroTime)
  {
    currentTime = millis();    
    ppqmicroTime += ppqtime;
    ppqcounter++;
    if (ppqcounter == PPQ)
    {
      ppqcounter = 0;
      beats++;
      if (beats == BPM)
      {
        processedtime = currentTime - startTime;
        Serial.println("All BPM Done!");
        Serial.print("Processed Time MS: ");        
        Serial.println(processedtime);
        BPM += 25;
        Started = false;        
      }
    }
  }
}

Here's the output from the Serial, which is 99.9% correct in terms of timing.  8-)

Code:
BPM: 95.00
PPQ: 96.00
Micros PPQ: 6578.95
All BPM Done!
Processed Time MS: 60002

BPM: 120.00
PPQ: 96.00
Micros PPQ: 5208.33
All BPM Done!
Processed Time MS: 59996

BPM: 145.00
PPQ: 96.00
Micros PPQ: 4310.34
All BPM Done!
Processed Time MS: 59938

Best Regards, WilliamK
587  Forum 2005-2010 (read only) / Frequently-Asked Questions / Midi Clock (PPQ) Wrong Math? on: December 10, 2010, 06:01:33 pm
Guys, trying to figure out why my midi clock is running a bit slower. Can someone check if my math is correct?  :-[

Code:
int bpm = 140;
#define PPQ 96
unsigned long ppqtime = 60000000 / (bpm*PPQ);

In C++ I would actually do like this:

Code:
float ppqtime = 60000000.0f / (float(bpm)*float(PPQ));

So I'm not sure if my Arduino code is correct or not...

Thanks, Wk
588  Forum 2005-2010 (read only) / Frequently-Asked Questions / Midi Clock (PPQ) and micros() ? Reliable? on: December 07, 2010, 05:13:05 pm
Guys, I'm trying to get a good midi clock with 16 to 96 PPQ, but somehow, it doesn't seem that the micros() is returning perfect timing information. Any comments on this?

Here's an example.

Code:
ppqtime = 60000000 / (bpm*PPQ);  // (60 x 1,000,000) / (BPM*PPQ) - done at SETUP or Time BPM Changed

// In the LOOP //

if (micros() >= prevtime)
{
     prevtime += ppqtime;
     // send notes now //
}


Best Regards, WilliamK
589  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to connect 74HC165 ? on: December 02, 2010, 06:39:08 pm
BTW: Vss is Ground on the picture, not sure if Vss is a common nomenclature?

Wk
590  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to connect 74HC165 ? on: December 02, 2010, 06:38:20 pm
Yup, that one did the trick.



It was easy to setup, and it did even use less pins compared to the tutorial on the arduino site. ;-)

I also managed to get everything working with less code. Its very easy to understand indeed. Thanks again.

Wk
591  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to connect 74HC165 ? on: December 01, 2010, 05:54:03 pm
Ah, very nice indeed. I had that page in another language. Nice to see in English.  8-)

Best Regards, WilliamK
592  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to connect 74HC165 ? on: December 01, 2010, 05:09:09 pm
Thanks guys, I get that, but how do I daisy chain two chips to get 16 inputs?  :-[

Wk
593  Forum 2005-2010 (read only) / Frequently-Asked Questions / How to connect 74HC165 ? on: December 01, 2010, 07:07:50 am
Guys, I'm trying to use 2 chained 74HC165 to read 16 buttons. But the following link tutorial got me lost.

http://www.arduino.cc/playground/Code/ShiftRegSN74HC165N

I did find the correct PDF file, but I'm still lost on how to use the chip.

Any information would be much appreciated.

Thanks, Wk
594  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: 16 LEDs On makes the LCD display weak? on: December 03, 2010, 05:34:42 am
Thanks guys.

I don't know yet the current for each led. I'm using 220ohm resistors and a shift-parallel out chip.

Can I use an external power and still have the usb plug, or I have to keep the usb unpluged while not using it, unplug the power, plug the usb, upload, unplug usb, plug power, ... ??

Wk
595  Forum 2005-2010 (read only) / Frequently-Asked Questions / 16 LEDs On makes the LCD display weak? on: December 02, 2010, 06:41:11 pm
Just checking a silly thing. I'm using the USB power, so I wonder if when I use an external power supply with more mA it will work better?

What happens is that when I light all my 16 blue LEDs the LCD display gets a bit dim. But not the LCD backlight. Its like the contrast gets weird somehow. Its a blue LCD with white digits. But the "white" gets a bit gray.

Is that the mA power output of the USB that is weak?

Just checking, not a really big deal for now...

Wk
596  Forum 2005-2010 (read only) / Frequently-Asked Questions / Encoder and Interrupts on: December 02, 2010, 06:45:37 pm
Guys, I got a nice encode code working on my Arduino MEGA. BUT, I wish to use Interrupts, so I can check when the encoder is moved very fast and jump to MAX or MIN. Also bypass any problems of not checking the encoder code often...

So, here's the code I'm using. But I got no clue on how to make it work with an Interrupt...  :-[
Code:
#define dpInEncoderA 20
#define dpInEncoderB 19
int EncoderPos = 120;
int Position, Press;
int isForward = 0;
int Position2, Press2;

void ReadEncoder(int &rotate) { rotate = (digitalRead(dpInEncoderB) * 2) + digitalRead(dpInEncoderA); }
void ReadEncoderI()
{
  ReadEncoder(Position2);
  if (Position2 != Position)
  {
    int isFwd = ((Position == 0) && (Position2 == 1)) ||
                ((Position == 1) && (Position2 == 3)) ||
                ((Position == 3) && (Position2 == 2)) ||
                ((Position == 2) && (Position2 == 0));
    if (isFwd) EncoderPos++; else EncoderPos--;
    if (EncoderPos <= 0) EncoderPos = 1;
    if (EncoderPos > 255) EncoderPos = 255;
  }
  Position = Position2;
};

void setup()
{    
  // Encoder //
  pinMode(dpInEncoderA, INPUT);
  digitalWrite(dpInEncoderA, HIGH);
  pinMode(dpInEncoderB, INPUT);
  digitalWrite(dpInEncoderB, HIGH);
  attachInterrupt(3,ReadEncoderI,CHANGE);
}

void loop()
{  
}

I'm pretty sure the code is all wrong, as its very late here and I'm very tired...  :o  :'(

Tomorrow I will run more tests and see if I can figure this one out. If I can't, I will give up for the moment....  smiley-sad

Wk
597  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Audio Synth chips? Atmel Dream? Other chips? on: October 29, 2010, 06:07:00 pm
Hey, tell me more about your dream-based project. That youtube video got me curious. ;-)

Wk
598  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Audio Synth chips? Atmel Dream? Other chips? on: October 15, 2010, 11:49:39 am
I'm talking more of some serious sound chips. ;-)

Like the Atmel Dream chips. Sadly, hard to handle and not easy to find...

Wk
599  Forum 2005-2010 (read only) / Frequently-Asked Questions / Audio Synth chips? Atmel Dream? Other chips? on: October 15, 2010, 05:11:38 am
Just wondering what are the chip alternatives for dealing with synthesis that are easy to use with the Arduino.

Wk
600  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Midi-Sequencer - how to? on: October 17, 2010, 09:54:10 am
One thing I was thinking about is to have 2 parts on the SD card. The whole sequence in a stream way, so its like playing a .midi file. And another structure which is the sequence in parts: song, patterns, events.

So, when you record or edit something, the code must update the complete-sequence. That could slow things down. But if I recall right, my old Roland MC-50 worked like that. Every time I changed something, it would do some sort of process. Just simple things, like event changes, wouldn't do that. But moving things around would...

Wk
Pages: 1 ... 38 39 [40] 41 42