Frequency Generator


hi,
i using arduino uno generate different frequency square waves modulate led. using toggle on compare match mode of 16mhz clock on atmega 328 this. datasheet atmega 328 has nice formula calculating ocrna register value needed generate desired output frequency. when calculate register value , hardcode ocr1a register, 500hz register value 1999, outputs correct frequency. have int variable frequency can enter 500 , calculate ocr1a value when try implement frequency outputted random. can't seem figure out why is. here little bit of code:
for 500hz
//this works
ocr1a =1999 ;

//this doesn't work
int freq = 500;
int eq = ((16*10^6)/(2*8*500))-1; //this formula datasheet ,
                                              // used 1999 above
ocr1a = eq;

can see doing wrong? in advance.

don't crosspost!

pete


Arduino Forum > Using Arduino > LEDs and Multiplexing > Frequency Generator


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial