Shop OBEX P1 Docs P2 Docs Learn Events
Propeller output pin voltage variation — Parallax Forums

Propeller output pin voltage variation

dbergquistdbergquist Posts: 6
edited 2011-04-15 07:58 in Propeller 1
I'm a hobbyist working with the propeller proto board for the first time. I've connected a propeller pin directly to an input of a ULN2003A in order to drive a relay. I wrote some simple test code that switches the relay on and off on 2 second intervals. It appears to be working except that randomly the voltage of the propeller output pin (when the pin is high) drops to 1.64v rather than the normal 3.3v. This in turn prevents the relay from engaging. I've tried this with different pins on the same board and get the same result. Do I need components between the prop pin and the input to the ULN2003A or could I just have a bad proto board?

Comments

  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-04-14 13:11
    Welcome to the forums!

    If the relay uses the same power source as the protoboard, there's a strong chance that the power surge from the relay switching is pulling the source voltage below what's required to drive the regulators (which I think is 6v). Putting the relay on its own power supply, or putting a large-ish capacitor across the power leads of the supply to the relay may help to buffer the initial surge.

    That said, I'm surprised it didn't brown out and reset if that's what's actually happening. To test it, try measuring the voltage going into the prop.

    You may get better answers if you can take a picture of your setup and post code. There are a lot of smart people on here.
  • LeonLeon Posts: 7,620
    edited 2011-04-14 13:19
    The ULN2003A doesn't appear to be suitable for 3.3V inputs.
  • dbergquistdbergquist Posts: 6
    edited 2011-04-14 13:45
    A heavy-duty 12v battery is the source for a 6.5v power supply that powers the proto board, but the power for the ULN2003A and the relay come directly from the battery. The relay engages successfully about 10 times for every one failure. I just disconnected the relay coil from the circuit and observed the same voltage drop on the prop pin.
  • dbergquistdbergquist Posts: 6
    edited 2011-04-14 13:51
    Leon wrote: »
    The ULN2003A doesn't appear to be suitable for 3.3V inputs.

    When I can get 3.3v out of the prop pin it appears to work, but what would you recommend instead?
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2011-04-14 13:57
    How are you measuring to voltage on the pin? Do you have a scope on it?

    Someone already asked about posting the code. It would help to see if there is something in the software that is causing it. What are you using for the clock soruce? Is it the standard 5Mhz crystal on the board or something else?

    Robert
  • LeonLeon Posts: 7,620
    edited 2011-04-14 14:17
    dbergquist wrote: »
    When I can get 3.3v out of the prop pin it appears to work, but what would you recommend instead?

    It probably won't drive it reliably. Check the data sheet!
  • dbergquistdbergquist Posts: 6
    edited 2011-04-14 14:42
    I'm measuring it with a voltmeter. The clock source is the standard 5 Mhz crystal. I'm having trouble uploading the code as an attachment, so I'm pasting the object that's engaging the relay.

    CON
    _xinfreq = 5_000_000
    _clkmode = xtal1 + pll16x
    _pinOn = 1
    _pinOff = 0
    _input = 0
    _output = 1
    _buttonUp = 0
    _buttonDn = 1

    VAR long SmokeStack[128] ' Stack for smoke sequencer
    byte LocalCog

    PUB Start(pinNo)
    Stop
    LocalCog := cognew(SmokeSequence(pinNo), @SmokeStack) + 1

    PUB Stop
    if LocalCog
    cogstop(LocalCog~ - 1)

    PRI SmokeSequence(pinNo) | mycount
    ' Initialize two second counter
    mycount := clkfreq*2 + cnt
    dira[pinNo] := _output
    outa[pinNo] := _pinOn

    ' Toggle relay on/off every two seconds
    repeat
    if cnt => mycount
    outa[pinNo] := !outa[pinNo]
    mycount := clkfreq*2 + cnt
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-04-14 14:46
    If you wrap your code with [ c o d e] and [/ c o d e] (without the spaces) it'll keep the proper formatting.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-04-14 14:49
    I'm not exactly sure what the behavior is going to be when the clock sign flips around (which will happen about every 25 seconds, which is roughly 2 seconds x 10 counts...)

    The clock is a number from 0 to (1<<32 - 1), so in PASM the clock wraps every 52 seconds, but Spin treats all longs as signed, so the sign changes every 26 seconds.

    You may want to use waitcnt( clkfreq * 2 + cnt ) instead of the repeat loop. It's also a little more power friendly, as the chip will go into a lower power wait state. If you're seeing the pin toggling from 0 to 1.6v instead of 0 to 3.3v it may not be your issue.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-04-14 14:52
    Leon,

    Here are the relevant sections of the ULN2003A and Propeller datasheets, and I don't see a problem driving the '2003A with the Prop, so long as the load current requirements aren't too high.

    attachment.php?attachmentid=80218&d=1302817785

    Even with a 17V input, the '2003A draws a maximum of 1.35 mA. And even with a 10 mA load, the Prop pin will be at least 2.85V above Vss.

    Where's the problem? I don't see it.

    -Phil
    600 x 600 - 39K
  • dbergquistdbergquist Posts: 6
    edited 2011-04-14 15:04
    JasonDorie wrote: »
    I'm not exactly sure what the behavior is going to be when the clock sign flips around (which will happen about every 25 seconds, which is roughly 2 seconds x 10 counts...)

    The clock is a number from 0 to (1<<32 - 1), so in PASM the clock wraps every 52 seconds, but Spin treats all longs as signed, so the sign changes every 26 seconds.

    You may want to use waitcnt( clkfreq * 2 + cnt ) instead of the repeat loop. It's also a little more power friendly, as the chip will go into a lower power wait state. If you're seeing the pin toggling from 0 to 1.6v instead of 0 to 3.3v it may not be your issue.

    I used waitcnt instead and the problem has gone away. I would not have suspected is was a software problem. Thanks so much for your help.
  • LeonLeon Posts: 7,620
    edited 2011-04-14 15:20
    Phil:

    It is marginal at higher currents. This is on the first page:
    The ULN2001A is a general-purpose array and can be used with TTL and CMOS technologies. The ULN2002A
    is designed specifically for use with 14-V to 25-V PMOS devices. Each input of this device has a Zener diode
    and resistor in series to control the input current to a safe limit. The ULN2003A and ULQ2003A have a 2.7-kΩ
    series base resistor for each Darlington pair for operation directly with TTL or 5-V CMOS devices. The
    ULN2004A and ULQ2004A have a 10.5-kΩ series base resistor to allow operation directly from CMOS devices
    that use supply voltages of 6 V to 15 V. The required input current of the ULN/ULQ2004A is below that of the
    ULN/ULQ2003A, and the required voltage is less than that required by the ULN2002A.

    I don't think it is intended for 3.3V inputs.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-04-14 15:41
    Leon,

    I still don't see the problem. Even the first page includes TTL devices which may not even reach 3.3V on their outputs. Granted, it does say "5V CMOS devices", but this datasheet was probably written back when most CMOS devices couldn't source much current. Times have changed -- especially given the Prop's output current capabilities. I stand by my observation based on the DC specs, not the front-page boilerplate.

    -Phil
  • JasonDorieJasonDorie Posts: 1,930
    edited 2011-04-14 15:42
    The problem is this bit:
    ' Toggle relay on/off every two seconds
    repeat
      if cnt => mycount
        outa[pinNo] := !outa[pinNo]
        mycount := clkfreq*2 + cnt
    

    If the clock starts at zero, after 13 iterations of your loop, your myCount will be slightly above $7BFA4800 (13 x 160million). Say it's $7C00_0000 for the sake of argument. When that IF statement succeeds, you add 160 mil to it, and it becomes $8589_6800, which Spin treats as -2,054,592,512.

    So now you have the system counter at $7C00_0000 (still a positive number), and your myCount value at $8589_6800 (a negative number). The next iteration of your loop succeeds again, because cnt >= myCount, toggling the pin. It adds 160 mil to myCount again, making it $8F12_D000... and so on. This will continue until myCount catches up to cnt, or cnt becomes negative, whichever happens first, all the while toggling your output pin.

    On a digital scope you'd see the toggle, but on a voltmeter it'll look like 1.6v instead of 3.3v because it's just reading the average.

    Make sense?
  • kwinnkwinn Posts: 8,697
    edited 2011-04-14 19:54
    dbergquist wrote: »
    A heavy-duty 12v battery is the source for a 6.5v power supply that powers the proto board, but the power for the ULN2003A and the relay come directly from the battery. The relay engages successfully about 10 times for every one failure. I just disconnected the relay coil from the circuit and observed the same voltage drop on the prop pin.

    I would suggest checking that 6.5V regulator output voltage. It may be a simple overheating/shutdown issue.
  • dbergquistdbergquist Posts: 6
    edited 2011-04-15 07:58
    JasonDorie wrote: »
    The problem is this bit:
    ' Toggle relay on/off every two seconds
    repeat
      if cnt => mycount
        outa[pinNo] := !outa[pinNo]
        mycount := clkfreq*2 + cnt
    

    If the clock starts at zero, after 13 iterations of your loop, your myCount will be slightly above $7BFA4800 (13 x 160million). Say it's $7C00_0000 for the sake of argument. When that IF statement succeeds, you add 160 mil to it, and it becomes $8589_6800, which Spin treats as -2,054,592,512.

    So now you have the system counter at $7C00_0000 (still a positive number), and your myCount value at $8589_6800 (a negative number). The next iteration of your loop succeeds again, because cnt >= myCount, toggling the pin. It adds 160 mil to myCount again, making it $8F12_D000... and so on. This will continue until myCount catches up to cnt, or cnt becomes negative, whichever happens first, all the while toggling your output pin.

    On a digital scope you'd see the toggle, but on a voltmeter it'll look like 1.6v instead of 3.3v because it's just reading the average.

    Make sense?

    This appears to be exactly what is happening. The first failure occurs >= 13 iterations, but subsequent failures occur at exactly 13 iterations. Thanks again.
Sign In or Register to comment.