Hi, I need a PWM function to use with a frequency of as low as a minute or two. For example, a freq of 1 minute would provide a 30 secs on/30 secs off with a 50% duty cycle. I'm using a 32.768kHz external crystal attached to the XTAL pins, and have a bus frequency of 4MHz. Unfortunately, dividing the clock by 128 and doing a full count in the TPM counter 0xFFFF does not provide a sufficiently long time period.
There is a statement in my user manual that an internal "XCLK" could be used. After reading what I could find in this forum, I still cannot figure out if there's a way to provide a lower clock freq to the TPM without changing the bus clock frequency. If using the "XCLK" is an option, any suggestions about what registers to alter to provide a lower clock freq for the TPM ? I am using the HCS08LG32 (C coding). Thanks.
Thanks Rocco, your suggestions work well.
I also went back to look into changing the clock input to the TPM. It seems that XCLK, the internal clock, is the signal pre-filter to the DCO. In my case, it is correlated to the 32.768kHz crystal frequency which is being used external to the processor. With RDIV=0 and setting this clock for TPM input (plus divide by 128), I am able to get a very low frequency. I'm still having a few problems setting the modulus (the program memory doesn't seem to want to accept any changes to this register for some reason), but that's another problem.
I should be able to use either method for generating the PWM. Thanks again.
Hi Thunder,
With a frequency that low, you don't need a PWM module at all. You could more easily bit-bang it. Here is how I have done it:
Expand the timer to 24 or 32 bits. Simply allocate the byte or two in ram, and increment it in the timer-overflow interrupt-service routine.
Check the expanded timer at a predetermined interval to see if it is time to toggle the output-bit. You can simply use the timer-overflow if you don't need much precision, or if you do need precision, you can use the timer's compare function.
I've used this technique for a PWM with a 20 second cycle-time and 1/8 second resolution.
mark