Shop OBEX P1 Docs P2 Docs Learn Events
Help understanding PWM — Parallax Forums

Help understanding PWM

Brian CarpenterBrian Carpenter Posts: 728
edited 2005-07-27 03:17 in BASIC Stamp
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

  • JonathanJonathan Posts: 1,023
    edited 2005-07-24 07:36
    Alt,

    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
  • Joe FishbackJoe Fishback Posts: 99
    edited 2005-07-24 15:18
    Alt,

    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
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-07-25 00:29
    ok here is what i am trying to do.· i have an r/c reciever that i want to feed the signal from ch1 through the BS2 and control the servo based on the input recieced by the reciever.· But when i switch ch6 high, i want the input from ch1 to be avoided and have the BS2 start its's program.· Is this possible
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-25 03:44
    I think I know what you are trying to do...

    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..

    ' {$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
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 7/25/2005 3:53:13 AM GMT
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-07-25 05:54
    could you please explain why we are dividing this value by 3.




    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
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-25 14:11
    Since I have no idea of what you actually want to do, dividing by 3 is only an example of manipulating the signal based on the status of Ch6.
    ... 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.
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-07-25 17:41
    ok got you. sorry for the ignorance. i should be able to use debug to see what my values are.
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-07-26 04:28
    Well,· thanks for the help. here is where i am stuck.· i used this code to determine my range of PWM coming from ny R/C reciever.

    ' {$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
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-07-26 15:46
    altitudeap,
    You said...
    The part i cant quite understand is the part where the ch1 is feed through to ChOut.
    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.
    You said...
    If the range of Ch1 input on IN0 is between 1447 and 2526, what should the last part of this equation read.
    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.
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2005-07-27 03:17
    Beau, You guys are incredibe. i dont think that i have ever dealt with a company that has provided so much support and training for the product they see. i think you and your fellow workers are incredible. About the project. I decided that because i have so many servos that i want to drive. i purchased the PSC today. this will definately change the way the code is written. thanks again.
Sign In or Register to comment.