R/C Pulse or PWM

This forum is for posts that might be considered off-topic but that may be useful or interesting to members. Examples include posts about electronics or programming in general, other microcontrollers or interesting devices, useful websites, etc.
Post Reply
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

R/C Pulse or PWM

Post by liam.zbasic »

Interested in controlling 2 motors (up to 6amp continuous, forward & reverse). PWM Motor Controllers are difficult to find, whereas R/C-Pulse type controllers are very common. On the other hand, Zbasic makes it simple to interface with PWM controllers with the PWM command. I like that it essentially remains in the background, thus preserving speed. Now I want to explore R/C methods. It seems this approach will slow an equivalent Zbasic program with PWM because PULSEOUT pulse-trains take time. Is this reasoning correct? Thank you.
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Post by pjc30943 »

You can set the PWM to simulate an RC pulse train--that way the PWM will just run in the background. The PWM just has to have the right duty cycle and period.
Paul
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

Thanks for your response. In theory, your suggestion sounds good. Have you tried it? I did find a good resource for PWM motor controllers from www.RobotShop.us. They have over a dozen models dedicated to PWM. They also sell various microcontrollers; I was a bit bummed that zbasic is not represented. Anyway, I'll research whether your good suggestion works in practice before I purchase anything. Thanks very much.
pjc30943
Posts: 220
Joined: 01 December 2005, 18:45 PM

Post by pjc30943 »

Yes, I have tried it. There are two servos controlled from a 1280n dev board via PWM. One potential issue is sharing the timer resource that the specific PWM requires (depending on which you use) if you are doing many other timing-related activities.
Paul
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

pjc30943 wrote:One potential issue is sharing the timer resource that the specific PWM requires (depending on which you use) if you are doing many other timing-related activities.
This is less of a problem, of course, on the ZX-1280 because it has twelve possible 16-bit PWM channels distributed across four different timers. At the other end of the spectrum, the ZX-24 has but two 16-bit PWM channels that use the only 16-bit timer.
- Don Kinzer
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

Thanks for your responses. So, what problems arise in a ZX-40 with "sharing the timer resource" if both PWM channels are used in the same program loop? Let's say the loop commands duty cycle to each PWM channel in response to ADC feedback from two IR range sensors. Thanks.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

liam.zbasic wrote:So, what problems arise in a ZX-40 with "sharing the timer resource" if both PWM channels are used in the same program loop?
Virtually all System Library routines that involve time-related I/O utilize the I/O Timer (Timer1 on a ZX-40). Since there is only one I/O Timer, ony one of these routines may be active at a time. There is a table in the ZBasic System Library manual that lists all of the routines that use the I/O Timer.

This restriction is less onerous than it might at first seem because most of the timer-dependent routines run to completion in the foreground of the task. This means that you can use the routines sequentially, e.g. PulseOut() followed by ShiftIn(). Some of the routines, however, use the I/O Timer in the background; OpenPWM() is an example of such a routine. Consequently, once you invoke OpenPWM() on a channel that uses the I/O Timer, you can't invoke any other routine that uses the I/O Timer until you invoke ClosePWM().

All routines that use the I/O Timer set a Boolean "busy" flag while the timer is being used; for most ZX devices the flag is Register.Timer1Busy. You can test this flag before invoking a routine that needs the I/O Timer so you will know that the timer is available.

Note, also, that 8-bit PWM is available. This capability is mutually exclusive with the use of the software UART channels (3-6), however. Moreover, on the ZX devices based on the mega32 (of which the ZX-40 is an example) there is only one 8-bit PWM channel available. ZX devices based on other AVR chips all have two 8-bit PWM channels.
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

liam.zbasic wrote:So, what problems arise in a ZX-40 with "sharing the timer resource" if both PWM channels are used in the same program loop? Let's say the loop commands duty cycle to each PWM channel in response to ADC feedback from two IR range sensors. Thanks.
This should work. The two PWM channels for timer1 have separate "output compare" registers which means you can set different PWM duty cycles for each one.

Don was alluding to the case of sharing timer1 for different jobs which is not the case in your example. However if you started to use InputCapture instead of ADC for the IR range sensors then this would cause a problem.
Mike Perks
Post Reply