Shop OBEX P1 Docs P2 Docs Learn Events
Pulsout problem. — Parallax Forums

Pulsout problem.

cododd777cododd777 Posts: 8
edited 2010-10-01 18:08 in BASIC Stamp
I'm using a BASIC stamp BS2 to take PWM input from a 2-channel RC receiver, modify the signal values, and output the modified signals to a DC motor controller. The program is running perfectly, it takes in the values via PULSIN and transforms them to what they should be, (the output pulse widths are exactly what they need to be on the DEBUG window.) The problem is that there is no pulse at the pin. I have tried PULSOUT on all the pins, including the servo pins. No dice. The pin will output steady 5V fine, but not a pulse, (at least by my PULSOUT command.) I've used BASIC stamps before, but not for a few years now. Has PBASIC changed in functionality since I last used it? Or is the problem something obvious and I'm just rusty? Here is the program I'm using.

' {$STAMP BS2}
' {$PBASIC 2.5}

ch1 VAR Word
ch2 VAR Word
chA VAR Word
diffX VAR Word
diffY VAR Word
diffXA VAR Word
diffYA VAR Word

INPUT 0
INPUT 1
DO
PULSIN 0, 1, ch1
PULSIN 1, 1, ch2
ch1=770
diffX=770-ch2
diffY=770-ch1
diffXA=ABS(diffX)
diffYA=ABS(diffY)
IF diffXA >= (diffYA/2) THEN
IF ch2 > 770 THEN
chA = 770+(diffYA/4)
ELSEIF ch2 <= 770 THEN
chA = 770-(diffYA/4)
ENDIF
ELSE
chA=ch2
ENDIF
PULSOUT 5, ch1
PULSOUT 4, chA
DEBUG ? ch1
DEBUG ? chA
LOOP


(Keep in mind, the program is working fine, it takes the correct values in and the output pulse lengths are correct, there is just no pulse coming out. )

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2010-09-23 17:37
    cododd777 wrote: »
    I'm using a BASIC stamp BS2 to take PWM input from a 2-channel RC receiver, modify the signal values, and output the modified signals to a DC motor controller. The program is running perfectly, it takes in the values via PULSIN and transforms them to what they should be, (the output pulse widths are exactly what they need to be on the DEBUG window.) The problem is that there is no pulse at the pin. I have tried PULSOUT on all the pins, including the servo pins. No dice. The pin will output steady 5V fine, but not a pulse, (at least by my PULSOUT command.) I've used BASIC stamps before, but not for a few years now. Has PBASIC changed in functionality since I last used it? Or is the problem something obvious and I'm just rusty? Here is the program I'm using.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    ch1 VAR Word
    ch2 VAR Word
    chA VAR Word
    diffX VAR Word
    diffY VAR Word
    diffXA VAR Word
    diffYA VAR Word

    INPUT 0
    INPUT 1
    DO
    PULSIN 0, 1, ch1
    PULSIN 1, 1, ch2
    ch1=770
    diffX=770-ch2
    diffY=770-ch1
    diffXA=ABS(diffX)
    diffYA=ABS(diffY)
    IF diffXA >= (diffYA/2) THEN
    IF ch2 > 770 THEN
    chA = 770+(diffYA/4)
    ELSEIF ch2 <= 770 THEN
    chA = 770-(diffYA/4)
    ENDIF
    ELSE
    chA=ch2
    ENDIF
    PULSOUT 5, ch1
    PULSOUT 4, chA
    LOOP


    (Keep in mind, the program is working fine, it takes the correct values in and the output pulse lengths are correct, there is just no pulse coming out. )
    '
    Have you made sure that I/O pins 4 & 5 are working???(and not burnt-out)
    '
    I don't see any DEBUG commands for a DEBUG window?
    '
    Posting a fragment of the code you think is faulty doesn't help either!
    '
    Keep in mind that you know what the correct values are, But no one else on the forums knows what these values are because you didn't post them.
    '
    A little more info would help your post!
  • cododd777cododd777 Posts: 8
    edited 2010-09-23 19:21
    I posted this program after I had taken some of the DEBUG commands out, Ideally I wouldn't need them. ch1 is the input channel #1, ch2 is input #2, chA is a modified value for channel 2 that it should send to the speed controller. The PULSOUT commands send ch1 to the speed controller as the controller's input#1 and send chA to the controller as controller input #2.

    I tried every pin on the board (Making sure to switch the PULSOUT pin each time.) And each pin will output a steady 5V fine in testing, just no pulse.

    The pulse width values it is intended to output are between 500-900 for both channels. The is no one correct answer because it is taking a PWM signal from a remote control joystick channel. The input signals are also in the 500-900 range.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-09-23 20:06
    I made some changes to your code, saved you four bytes in the process. It should work just the same.

    Can you describe exactly how you are testing if the PULSOUT is working?

    Rich H
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    ch1 VAR WORD
    ch2 VAR WORD
    chA VAR WORD
    
    diffX VAR WORD
    diffY VAR WORD
    
    'diffXA VAR WORD
    'diffYA VAR WORD
    
    'INPUT 0  'not necessary - PULSIN sets the pins to input for you
    'INPUT 1
    
    DO
    '  PULSIN 0, 1, ch1  ' why do this when ch1 is set to 770 two lines later?
      PULSIN 1, 1, ch2  
    
      ch1=770  
    
      diffX = 770 - ch2 
      diffY = 770 - ch1 ' zero
    
      chA = ch2 + (diffY/4)
    
      PULSOUT 5, ch1 ' 770
      PULSOUT 4, chA
    
      DEBUG ? ch1
      DEBUG ? chA
    LOOP
    
  • cododd777cododd777 Posts: 8
    edited 2010-09-24 08:18
    The first sign it wasn't working was that the speed controller reported that there was no PWM pulse going in. So I checked it with another BASIC stamp, using PULSIN on the second one to measure the PULSOUT on the first. For all pins is showed a PULSIN of zero.

    Thanks for the edit! I'm still a little rusty with PBASIC 2.5!
  • ercoerco Posts: 20,256
    edited 2010-09-24 08:26
    Pulsouts are pretty straightforward, hard to believe you can't get one out of any of 16 pins. I suspect something bad in your controller or connection. Remove the controller connection and hook up a working servo to your BS2 and run a test program, something like below, to verify if your Stamp is outputting pulses. Hook the servo control wire directly to the Stamp output pin. Pin P0 as coded here.

    BTW, are you using a BoE or a HW board or a board you made?

    a:for b0=500 to 1000
    pulsout 0,b0' servo to pin P0
    pause 20
    next
    goto a
  • ercoerco Posts: 20,256
    edited 2010-09-24 09:30
    As long as your high & low commands are known working, you can also bit-bang a string of pulsouts:

    b:high 0' high pin P0
    pause 1' pause 1 ms
    low 0' low pin P0
    pause 20' typ servo delay between pulses
    goto b' repeat

    That will give you a stream of pulsouts 600-ish or so with processor overhead. That should let you test servos and your controller.
  • W9GFOW9GFO Posts: 4,010
    edited 2010-09-24 12:53
    cododd777 wrote: »
    So I checked it with another BASIC stamp, using PULSIN on the second one to measure the PULSOUT on the first. For all pins is showed a PULSIN of zero.

    Did you have the grounds of the two BS2s connected?

    Rich H
  • cododd777cododd777 Posts: 8
    edited 2010-09-24 17:06
    I'm using a BoE. I hooked up a Futaba servo which I know works to the regular servo outputs and also by sending in the pulse direct to the signal wire from the regular pins and tried PULSOUT, no luck. No motion, or any indication of response. I like the idea of sort of brute forcing a custom pulse generation routine, but I'm going to need pulse widths down to 500. I was skeptical that this would be a hardware problem given the behavior, and my rustiness with PBASIC, but if that is what people are thinking I can just go and buy another BoE. Kind of a strange problem though. Thanks for all the help so far!!
  • W9GFOW9GFO Posts: 4,010
    edited 2010-09-24 17:35
    Two things I can think of that would prevent a servo from operating on the Boe-board.

    1. The power switch has three positions, it must be slid all the way over to send power to the servo headers.

    2. There is a jumper for choosing where the servo power comes from. If it is missing then the servo would not get power.

    Rich H
  • cododd777cododd777 Posts: 8
    edited 2010-09-25 08:36
    I made sure the lever was on 2 and that the jumper was set correctly. I also tired it by plugging the servo into the breadboard and wiring the 5V, signal, and ground to the VDD, pin, and Vss terminals respectively. I was hoping that would get around any problem with the servo hookups.
  • ercoerco Posts: 20,256
    edited 2010-09-25 08:45
    This is real basic stuff, yet we're getting nowhere fast; something is clearly wrong. Please verify that your Stamp works and has at least one good pin which can flash an LED. Hook up an LED's long lead (+) to P0, LED short lead through a 330 ohm series resistor to ground.

    Now run this program:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a: toggle 0: pause 500:goto a

    Does it flash? Will it blend? Of course you can use any pin, as long as the code matches the pin.
  • cododd777cododd777 Posts: 8
    edited 2010-09-28 05:36
    Nothing, no flash on any pin. but it will work when I just set it to high and leave it. Weird, I know. I guess the thing to do know is just get another Stamp.
  • ercoerco Posts: 20,256
    edited 2010-09-28 08:56
    When you say "work", is it lighting an LED, or are you just measuring 5V with a multimeter?

    Is this a plain (green) BS2? Is it plugged into a BoE? How about post a photo of your hardware.
  • cododd777cododd777 Posts: 8
    edited 2010-09-28 16:55
    By "work" I mean lit the LED. And yes, it is a "plan green" BASIC stamp. I don't have a camera to take a picture, though. Never had any problems with the Basic stamps I've used previously...
  • ercoerco Posts: 20,256
    edited 2010-09-28 19:31
    It lights an LED, yet that toggle program doesn't work? Recheck, something's wrong. Try this with an LED on pin P0:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a: high 0: pause 1000:low 0: pause 1000:goto a
  • cododd777cododd777 Posts: 8
    edited 2010-10-01 16:22
    I rechecked, some problem. The new program works, though. It turns on and then off in 1sec intervals.
  • ercoerco Posts: 20,256
    edited 2010-10-01 18:08
    If that works, then my previous program should work, yet you said it didn't. Recheck:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    a: toggle 0: pause 500:goto a

    It sounds like your stamp is fine. If it puts out enough current to light an LED, it has enough output to drive a servo. I think you have a wiring error somewhere. Hook up a good servo in place of your speed controller, make sure all of your batteries have their negatives connected and retry. You need to post a photo or video for us to help you any further.
Sign In or Register to comment.