Help understanding PWM
Brian Carpenter
Posts: 728
I am trying to make a circuit that will allow for PWM from a rc reciver to pass through until channel 6 goes high. at that point i want the program in the BS2P to run.· It will need to monitor the channel 6 though. that is my (program on/off) switch.· the reciver talks in PWM to the servos.· i want to put the BS2P inbetween the two.· Thanks
Comments
I'm not sure if I get exactly what you want to do, but you might look at the 74HC132 Schmitt trigger NAND.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Do not know if my project will be of help, but to Forum "Projects" and look at my project. It is listed back in May as "Super BOT-BOE".
http://forums.parallax.com/forums/default.aspx?f=21&m=73883
I am controling the Boe-Bot by a Futaba RC transmitter, but if the Bot detects an object, the BOE on the Bot runs a program to avoid the object. Once the object has been avoided, control is returned to the RC. I have added a Lazer Pointer to the Bot since I posted the pictures under the "Projects" post. I am on vacation so I can not attach my codes. If you want them I can e-mail to you at the end of the week.
If you have any questions or if I can help you give me a e-mail
Joe Fishback
Ch6 is in essence a bypass for Ch1
What might be confusing is the term that you are using with Ch6. On your transmitter, you have a switch
that has two positions "HIGH" or "LOW". As far as the receiver is concerned, this is simply two fixed
servo positions. In other words if you plug a servo to the receiver on Ch6, the servo should "snap" to
one position or the other. Remember the signal on Ch6 is still a pulse that ranges from 1mS to 2mS, as
well as all of the other received channels. You need to do a little DEBUGing with the PULSIN function
available on the BS2. More than likely when Ch6 is switched you will see a value on one side of 1.5mS
or the other.
Since you have a BS2P, the PULSIN resolution is 0.8uS which means you should "see" a range of 1250 to 2500
for a 1mS pulse to 2mS pulse.
Your code might look something like this..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/25/2005 3:53:13 AM GMT
PULSIN·Ch1,1,ChData···'Get·Data
ChData·=·ChData·/·3···'Alter·the·incoming·data·(simple·divide·by·3)
ChData·=·ChData·MIN·1250··'Keep·the·Minimum·value·to·1250
... you can do what ever you want as long as the output pulse remains between 1mS and 2mS ..... 1250 to 2500
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
' {$STAMP BS2p}
' {$PBASIC 2.5}
Ch1···· VAR· IN0··· 'Input Pin 0 for Ch1
Ch6···· VAR· IN1··· 'Input Pin 1 for Ch6
ChOut·· VAR· OUT2·· 'Output Pin14 for ChOut
chlow·· VAR· Word
ChData· VAR· W1···· 'Data Variable for Pulse
DIRL = %11111100··· 'Set ALL pins as outputs except for IN0 and IN1
OUTL = %00000000··· 'Set ALL output pins to LOW state
'MainLoop:
DO
PULSIN Ch6,1,ChData
IF ChData > 1875 THEN chlow = 1
·· ' 1.5mS / 0.8uS resolution = 1875
DEBUG "high", CR
DEBUG ? ChData
DEBUG "············ ", ? chlow
PAUSE 1000
LOOP
i tested channel 6, which is a toggle from one extreme to another.· 1475 to 2526. So the first part of the code will let me know whether or not i am above 1875.· That part works.· The part i cant quite understand is the part where the ch1 is feed through to ChOut.· It is not working as writen.· If the range of Ch1 input on IN0 is between 1447 and 2526, what should the last part of this equation read.
'·{$STAMP·BS2p}
Ch1·····VAR··IN0····'Input·Pin·0·for·Ch1
Ch6·····VAR··IN1····'Input·Pin·1·for·Ch6
ChOut···VAR··OUT2···'Output·Pin2·for·ChOut
ChData··VAR··W1·····'Data·Variable·for·Pulse
DIRL·=·%11111100····'Set·ALL·pins·as·outputs·except·for·IN0·and·IN1
OUTL·=·%00000000····'Set·ALL·output·pins·to·LOW·state
MainLoop:
PULSIN·Ch6,1,ChData
IF·ChData·>·1875·THEN·Ch6IsHigh···'·1.5mS·/·0.8uS·resolution·=·1875
Ch6IsLow:·············'This·section·of·Code·allows·Ch1·to·enter·the·BS2
······················'and·exit·the·BS2·through·ChOut.
PULSIN·Ch1,1,ChData···'Get·Data
PULSOUT·ChOut,ChData··'Send·Data
GOTO·MainLoop
Ch6IsHigh:············'This·section·of·Code·allows·Ch1·to·enter·the·BS2
······················'and·exit·the·BS2·through·ChOut,·after·modifying
······················'the·incomming·data.
PULSIN·Ch1,1,ChData···'Get·Data
ChData·=·ChData·/·3···'Alter·the·incoming·data·(simple·divide·by·3)
ChData·=·ChData·MIN·1250··'Keep·the·Minimum·value·to·1250
PULSOUT·ChOut,ChData··'Send·Data
GOTO·MainLoop
1) In your section of code, I don't see a provision for the PULSOUT command.
··· basically PULSIN reads the signal from your receiver, while PULSOUT "reflects" the
··· signal out onto another pin (slightly delayed).
2) Since you appear to be·using· Pin14 for your output, you need to change...
··· Chout VAR OUT2· 'Output pin14 for ChOut
··· ...so that it reads...
··· Chout VAR OUT14· 'Output pin14 for ChOut
··· You should also add another I/O directive...
··· DIRH = %11111111· 'Set ALL pins as outputs
··· OUTH = %00000000· 'Set ALL output pins to LOW state
··· Note:
········ DIRH and OUTH correspond to pins 8-15 while DIRL and OUTL correspond to pins 0-7
Also,· not sure if this matters, this may be more of a personal programming style issue (old-school).
I would change the line...
chlow· VAR Word
..to read...
chlow VAR W2
...and specify the Word variable being used.
Not sure what you are asking here....· The values are within the accepted range of 1250 and 2500 for a BS2p.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.