How do I get the co processors on a BS2PE moboo to run an un-attended PWM signa
Deano1936
Posts: 15
I'm new at PBASIC and I'm really enjoying this language. I have
> a BS2pe MoBOo and I'm trying to get the co processors to generate a
> constant PWM signal to run an H bridge motor circuit. Can you give me
> a link where I can find a sample program that will help me understand
> this procedure ?
Post Edited (Deano1936) : 12/17/2008 10:10:15 PM GMT
> a BS2pe MoBOo and I'm trying to get the co processors to generate a
> constant PWM signal to run an H bridge motor circuit. Can you give me
> a link where I can find a sample program that will help me understand
> this procedure ?
Post Edited (Deano1936) : 12/17/2008 10:10:15 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Here is the documentation for GPIO3, the firmware that comes preloaded on the MoBoStamp-pe's coprocessors. It details how to set up the AVR's outputs for constantly-running PWM.
Here is a sample program to get you started:
If you're using the PWM with an inductive load, such as a motor, you may want to switch to one of the odd-numbered PWM frequencies. The reason is that, at these frequencies, the PWM output maintains the correct phase, rather than aligning with the leading or trailing edge. This is supposed to help get smoother operation from the motors. To change to 18.8KHz (frequency 1) for example, add the following ahead of the DO...LOOP in the above code:
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 12/17/2008 10:53:34 PM GMT
The MoBoStamp-pe has three processors onboard: a BASIC Stamp 2pe and two AVR ATTiny13s that can be programmed to offload tasks from the Stamp.
-Phil
The program was just what I needed. It worked great. I wrote the following code to get four separate PWM signals from the A & B co-processors.
It also worked great. Now I'm going to try and sample an analog voltage on ports 0 & 1 of each AVR processor so I can control the four PWM signals using four pots.. I know I'm re-inventing the wheel sooo--- if you have the time and you know of a sample code that will help me with this task , I would really appreciate you posting it.
Thank you again
Dean
' {$STAMP BS2pe}
' {$PBASIC 2.5}
'This program will set up the two AVR co processors (A&B) so they will generate four separate unattended PWM signals.
OWOUT 10, 0, [noparse][[/noparse]$F1] 'Set co-processors A and B to18.8khz
OWOUT 6, 0, [noparse][[/noparse]$F1]
pwmAP2 VAR Byte
pwmAP3 VAR Byte
pwmBP2 VAR Byte
pwmBP3 VAR Byte
pwmAP2 = 50 ' 'Set the duty cycles so that each output will look different on the o-scope
pwmAP3 = 100
pwmBP2 = 150
pwmBP3 = 200
PAUSE 10 'Make sure AVR comes out of reset.
DO
OWOUT 6, 0, [noparse][[/noparse]$26, pwmAP2] 'Set A AVR port 2, to PWM positive
OWOUT 6, 0, [noparse][[/noparse]$36, pwmAP3] 'Set A AVR port 3, to PWM positive
OWOUT 10, 0, [noparse][[/noparse]$26, pwmBP2] 'Set B AVR port 2, to PWM positive
OWOUT 10, 0, [noparse][[/noparse]$36, pwmBP3] 'Set B AVR port 3, to PWM positive
PAUSE 700 'Test the effects of program RUN time. Note: I could see no interruption or any effect on the PWM signals due to this PAUSE 500 command.
LOOP
Post Edited (Deano1936) : 12/18/2008 10:12:35 PM GMT
The wiper resistor is there to ensure no damage to the AVR, should the wiper be at an extreme with the pin accidentally set to output.
Here's some sample code for reading the voltage at the pin:
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Oh, man, you've got to take a look. Very cool little board. One of those with the power input, 3-pin header I/O daughterboard is about $95, and it'll do 10-bit ADC, PWM, frequency counter input and all sorts of other stuff. The 2pe communicates with the AVRs through the one-wire protocol. It's easily my favorite Stamp module.