PDA

View Full Version : Generating square-wave of 200kHz



sirvo
- 2nd March 2011, 19:18
I've to build a square-wave generator and it should range from 1Hz to 220kHz.

The difficult is on the 220kHz.
If I use a @48MHz on these 18F family, I would have 12MHz (FOSC/4) of clock instruction and the fastest interrupt I can achieve is around 1.5MHz.

Using this config, It is impossible to vary the wanted square-wave, for example, from 220kHz to 219kHz cause my resolution does not allow this. The best I can do is 222kHz or 218kHz.

Is there a solution to solve this? As I read the datasheet, @48MHz is the maximum clocking for these 18F.

What do you think about using a dsPIC30F2010? Is it easy programming like the 18F? It works @120MHz.... would solve my problem..

Thanks in advance.

ronsimpson
- 2nd March 2011, 20:52
Why interrupts?
Why not use PWM?
Why not use CCP1, CCP2?
One of the PWM examples shows changing the dutycycle by 25nS. This gives me the idea you could change the frequency in 25nS steps.

sirvo
- 2nd March 2011, 21:06
Why interrupts? -> Can't get 1kHz steps on "high" frequencies: Ex. 201kHz then 202kHz..
Why not use PWM? -> Same as above...and also can't get low frequencies like 1Hz, 2Hz
Why not use CCP1, CCP2?
One of the PWM examples shows changing the dutycycle by 25nS. This gives me the idea you could change the frequency in 25nS steps.

Where is this example?

Thanks again.