|
|
| Author |
Message |
liam.zbasic
Joined: 25 Mar 2008
Posts: 143
Location: Southern California (Blue)
|
|
Posted: 07 June 2009, 6:30 AM Post subject: 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. |
|
| Back to top |
|
 |
pjc30943
Joined: 02 Dec 2005
Posts: 220
|
|
Posted: 12 June 2009, 1:37 AM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
liam.zbasic
Joined: 25 Mar 2008
Posts: 143
Location: Southern California (Blue)
|
|
Posted: 12 June 2009, 21:22 PM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
pjc30943
Joined: 02 Dec 2005
Posts: 220
|
|
Posted: 13 June 2009, 0:59 AM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 13 June 2009, 2:04 AM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
liam.zbasic
Joined: 25 Mar 2008
Posts: 143
Location: Southern California (Blue)
|
|
Posted: 13 June 2009, 13:23 PM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 13 June 2009, 15:19 PM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX
|
|
Posted: 13 June 2009, 15:27 PM Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
|