Shop OBEX P1 Docs P2 Docs Learn Events
Using the SX48's built-in PWM — Parallax Forums

Using the SX48's built-in PWM

John BondJohn Bond Posts: 369
edited 2008-03-27 06:25 in General Discussion
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?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • BeanBean Posts: 8,129
    edited 2008-03-26 13:01
    John,
    · 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.
    John Bond said...

    Can you use this built-in PWM in SX/B?
    Yes, using the TIMERx PWM command

    How do you address T1 and T2?
    TIMERx R1and TIMERx R2·commands

    How do you set the fuse byte that enables this function?
    There is no fuse setting to enable the hardware timers

    Can you use just one of these I/O ports, leaning the other for some other functionality?
    Sure, they are fully independent
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com



    Post Edited (Bean (Hitt Consulting)) : 3/26/2008 1:08:51 PM GMT
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-03-26 15:31
    If you subscribe to SERVO magazine you'll see that there is an article in this months issue (April 2008) which uses the SX48 Timer to do control a motor. The Serial routines and encoder routines are in the ISR.

    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
  • John BondJohn Bond Posts: 369
    edited 2008-03-27 06:25
    Thanks Bean! Wow, a response within just 6 minutes!!!! (I read your post just after you sent it but the telephone cables were stolen again last night so I couldn't reply. Any wonder why we're the leaders in the 3rd world in GSM, 3G, Satelite and radio. Less cables to steal and sell as scrap copper. They even steal the live 110KV power cables from time to time.)

    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.