Go Down

Topic: Digital Outputs (Read 2056 times) previous topic - next topic

ShensMobile

#15
Apr 03, 2012, 12:04 am Last Edit: Apr 03, 2012, 02:47 am by ShensMobile Reason: 1
So your code works amazingly, I'm just having an issue, at frequencies above 1.5Mhz, I can't really get it to work.  I either lock it to 1.6Mhz, 2Mhz or 2.6Mhz.  I need it at either 1.8 or 2.3 Mhz but I can't get it to those values.  Does anyone have any suggestions?

floresta

Quote
Does anyone have any suggestions?


Not if you are going to use the 'Toggle OC2A on Compare Match'  &  'Clear Timer on Compare Match (CTC)' technique.  If you rework the equation used to calculate the 'timer data' you find that the output frequency is determined by dividing the clock frequency by 2 * prescaleFactor * (1+timerData).  This is the equation in section 17.7.2 of the datasheet.  Since the timerData is an integer there are a limited number frequencies that you can get and they are widely spaced at the upper frequency end.

You can probably use the timer/counter to get a lot closer to the frequency you desire, but not without using some combination of processor time and interrupts.


Don



Graynomad

#17
Apr 03, 2012, 03:02 am Last Edit: Apr 03, 2012, 03:05 am by Graynomad Reason: 1
Quote
You can probably use the timer/counter to get a lot closer to the frequency you desire

Changing the crystal can help, at the possible expense of stuffing up other thing like serial and of course actual programming the chip :)

As Don said you are working with integer division and at the high freqs there aren't many options.

It may be better to go back to the software loop with NOP padding idea but I guess that was a problem because you want to run other code at the same time.

Maybe an external clock generator of some kind is needed.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up