R/C Pulse or PWM
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
R/C Pulse or PWM
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.
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
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.
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.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.
- Don Kinzer
-
- Posts: 163
- Joined: 24 March 2008, 23:33 PM
- Location: Southern California (Blue)
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.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?
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
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.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.
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