Using the SX48's built-in PWM
Reading the SX48 manual, I see that the SX48 has a built-in PWM function. This can be configured so that the internal timer updates T1 and T2, switching I/O RB.6 and RC.2. This means you have a PWM signal·switching RB.6 and RC2, the one a mirror image of the other. T1 and T2 can each be set independantly to byte variables. In addition, if you’re not using the prescaler(postscaler) elsewhere, you van stretch the T1/T2 times.
·
I’m working on a motor control circuit that uses PWM. I’ll probably need an ISR so this is an academic question, a question to help me understand the SX architecture.
·
Can you use this built-in PWM in SX/B?
How do you address T1 and T2?
How do you set the fuse byte that enables this function?
Can you use just one of these I/O ports, leaning the other for some other functionality?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
I’m working on a motor control circuit that uses PWM. I’ll probably need an ISR so this is an academic question, a question to help me understand the SX architecture.
·
Can you use this built-in PWM in SX/B?
How do you address T1 and T2?
How do you set the fuse byte that enables this function?
Can you use just one of these I/O ports, leaning the other for some other functionality?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
· The prescalers for the hardware timers are independent from the RTCC and watchdog prescaler. IOW you can always use them.
· The outputs from the two timers are independent too, they are not mirror images of each other (they could be programmed to be if·you needed that).
· The T1 and T2 times are words (16 bits) not bytes (8 bits). They are referred to as R1 and R2.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
Post Edited (Bean (Hitt Consulting)) : 3/26/2008 1:08:51 PM GMT
The 16-bit timers seem to work great but I haven't seen a lot of other people using them in other projects. I expect that once people try them they will start using them a lot more.
One issue that I had when using them is how to turn them off when I was done. Bean suggested using TIMERx TIMER to change the timer to timer more. This worked but caused another issue of extra interrupts being generated from the timer mode. To get around that I just had to set a couple of the option bits to mask off any interrupts from the timer mode to prevent them from coming through. Once that was done it worked out great!
Robert
Very interesting Robert...
Could I keep the PWM running, but with a duty cycle of 0? I'm using Automotive relays to control direction (I have a dozen Automotive relays in my scrap bins and big P channel Mosfets are difficult to get here in the veldt - South African countryside.)
I'll play with it this weekend but like you say, I'll probably just put it in an ISR.
Thanks for your input
John Bond
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔