PWM Command with BS2
geneshults
Posts: 22
I'm not for sure what I'm doing wrong here.
BS2 code wrote:
PWM 0,PWMD,255
PWMD = 191
PAUSE 50
At this setting of the PWMD (191) shouldn't I be getting an output voltage of 3.75 vdc?
and at 127 PWMD I should be getting a 2.5 volts.
I'm not, what I'm getting a totally different reading.
What I'm getting is at 191 is a 2.8 and at 127 is a .79 volts.
I did the calculations per manual Average Voltage = (Duty / 255) * 5 volts
AV=(127 / 255) * 5
AV=(.498) * 5
AV=2.49
Help Please
Thanks
Gene
BS2 code wrote:
PWM 0,PWMD,255
PWMD = 191
PAUSE 50
At this setting of the PWMD (191) shouldn't I be getting an output voltage of 3.75 vdc?
and at 127 PWMD I should be getting a 2.5 volts.
I'm not, what I'm getting a totally different reading.
What I'm getting is at 191 is a 2.8 and at 127 is a .79 volts.
I did the calculations per manual Average Voltage = (Duty / 255) * 5 volts
AV=(127 / 255) * 5
AV=(.498) * 5
AV=2.49
Help Please
Thanks
Gene
Comments
needs to be placed before the line with the PWM command
Is the code in a loop and are you using the filter described in the BASIC Stamp Manual?
Yes I am. The code is in a loop. And I am using the 1uf cap and a 10k resistor for the filter as per manual.
I had if buffered through a LM358 and have taken it out of the circuit to see if it was causing my issue. Still not getting what I would expect.
Here is the complete code I'm using.
I have tried different pins for the PWM output, but get the same result.
Hope you may see a mistake I made. LOL have looked at it tried different things so maybe new set of eyes on it may see some thing.
THanks
Gene
'
[ Title ]
' {$STAMP BS2}
' {$PBASIC 2.5}
' Range PWMD 0 - 255 For a 0 - 5 Volt Range Output
' PWM3.bs2
'
[ Declarations ]
PWMD VAR Word
'
[ Initialize ]
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB PWMD_1
GOSUB PWMDOUT
LOOP
'
[ PWM Subroutines ]
PWMD_1:
PWM 0,PWMD,255
PWMD = 255
PAUSE 50
RETURN
PWMDOUT:
DEBUG HOME
DEBUG CR, DEC PWMD,CR
RETURN
As PJ pointed out, and Chris confirmed, you must put the PWMD variable before the PWM command.
incorrect:
correct:
EDIT: OK, as Chris points out, if you are in a loop, your value will get updated after the first go around. I guess it's just not a good practice to put PWMD after PWM, in case you do not loop the sub routines.
I suspect there is something loading down the output circuit. Do you still have the LM358 buffer circuit?
What voltage do you measure at the output if you simply have
Is your "PWM" output measured solidly high at 5 volts?
How about this:
That should hover around 2.5 volts as it alternates high and low with a period of about 0.5 milliseconds.
Hello Tracy
Found my error. I had a bad row on my bread board that wasn't completing my filter circuit.
After doing every thing you asked and every thing coming out ok. I broke down my circuit and built it again on a different board and every thing worked great. Just letting you know what I found and what I did to correct it. thanks so much for your help and replys.
Found my error. I had a bad row on my bread board that wasn't completing my filter circuit.
After doing every thing you asked and every thing coming out ok. I broke down my circuit and built it again on a different board and every thing worked great. Just letting you know what I found and what I did to correct it. thanks so much for your help and replies.
Thanks for letting us know what the problem was. Too often people are too embarrassed to post the resolution.
This will help people in the future researching a similar problem.
Happy Stamping!
Jim