Designing a variable squarewave generator. (by Juan)
Hi,
Could you help me design a variable square wave generator able to vary the square wave frequency with up and down push buttons in 1Hz increments from 1Hz to 1000Hz?
I don't really know where to begin.
I tried manipulating the Ton and Toff timer values by writing an ADD function to the Ton and Toff registers adding Ton + "value" but this does not seem to work.
Can you also give me an example on how to operate the look up table?
Thanks.
(no subject) (by Jonathan Westhues)
The highest possible resolution for the period of a software timer is the cycle time. This means that you can't get 1 Hz resolution around 1 kHz without an impractical cycle time (of around 1 us). But that resolution is easy on the slow side.
See the attachment. The highest possible output frequency is 1/(2*Tcycle). So you want to set the cycle time to at most 0.5 ms. This means that you should use the fastest crystal allowed, and keep the rest of the program short.
Note that we specify the period of the timer, not the frequency. If you wanted to specify the frequency instead, then you would have to divide to calculate the period from that.