Shop OBEX P1 Docs P2 Docs Learn Events
SLED-C4 converting BASIC to SPIN — Parallax Forums

SLED-C4 converting BASIC to SPIN

pgbpsupgbpsu Posts: 460
edited 2008-09-13 19:49 in Propeller 1
I'm trying to use an SLED-C4 from Reynolds Electronics to display temperature. I've got my temp code working, but I can't get the display to respond. This 4 digit, 7-segment display is very simple. It only has 5 pins and I'm only using 4 of those. It takes serial data as input. Despite my best efforts I'm not getting the display to do anything. It turns on and all the segments are lit: 8888. I can't change any of them.

I'm giving it +5V power from the demo board. I'm running my serial line into an ST M74HCT04B1 (www.st.com/stonline/books/pdf/docs/2099.pdf) which I'm simply using to lift my serial data from 3.3 to 5V. This is an inverter chip but by running my serial line into this chip, feeding that output back into the inverter, I end up with my serial data stretched to 5V. I'm pretty sure my trouble isn't with this part of the circuit. When I scope the serial line coming from the Prop and the serial line just before going into the SLED they are identical save the voltage.

So I'm left to believe that the trouble is with my code. Since this is a serial device it can't be that difficult. The datasheet for the display (www.rentron.com/SLED/SLED-C4.pdf) has example code for BASIC. Sure doesn't look that difficult, but I was hoping someone who knows BASIC and SPIN could tell me what the differences are between the example code:

Below is a BASIC example. 
CountIt: 
    ' 4-digit counter from 0 to 1000 using "D"ecimal mode  
    FOR Counter = 0 TO 1000 
    '                     left digit                                                          right digit 
    DEBUG "D", Counter DIG 3, Counter DIG 2, Counter DIG 1, Counter DIG 0 
    PAUSE 20 
    NEXT Counter 
    PAUSE 500 
    DEBUG "C","~" ' Clear display 
D mode offers the least amount of flexibility, but simplifies host side firmware for simple counter applications as 
shown above, where custom characters or animations are not necessary. 
Note that D mode expects to receive decimal digits 0 through 9. Any value greater than 9 decimal will clear the 
display digit position it is in. In the above example, D mode will not provide automatic leading zero blanking. The 
display will show a count of 0000 through to 1000. 





And my code:

{
                                ********************************************
                                            Test of SLED-4 Display
                                ********************************************

Simple test of the SLED-4 7-segment display from Reynolds Electronics www.rentron.com
 PGB 28 Aug 2008
 
}
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

'***************************************
'  Pin Assignments
'***************************************
  SLED          = 2                                 ' Serial line to SLED


OBJ
  term    : "PC_Interface"
  debug   : "FullDuplexSerial"                          'Send data to serial display

VAR
  long   cx, cy, ch
  long   mx,my,mxo,myo

PUB Main  

    term.start(31,30)                                   'start the PropTerminal interface
    
    debug.Start(1,SLED,%0000,19200)                     '(rx,tx,mode,baud) Add SLED port

    pauseMsec(3000)                                     ' wait 

    repeat 1000
      debug.hex($44,2)
      debug.dec(1)
      debug.dec(2)
      debug.dec(3)
      debug.dec(4)
      term.hex($44,2)
      term.dec(1)
      term.dec(2)
      term.dec(3)
      term.dec(4)
      pauseMsec(300)                                  ' wait 1 second before next reading

PRI pauseMSec(DelayMS)
'' Pause execution in milliseconds.
'' Duration = number of milliseconds to delay
  
    waitcnt(clkfreq / 1000 * DelayMS + cnt)  '  Wait for DelayMS cycles    





I realize that I'm not displaying an increasing number like the BASIC code does. I'll be happy to get 1234 out of this thing! I'm also not clearing the display when done. As a check of what I'm outputting from the Prop I've setup PropTerminal. I've attached a picture of that output.

I've setup the SLED with PIN 3 (BAUD) tied to GND which should set the baud rate to 19,200. I'm not monitoring the AUX pin but I don't see how that can be required by this simple test of the display. When powering up the unit I get "8888" and it never changes. I should add that the datasheet specifies:
SLED said...
Display Operation
A single I/O-pin on the host controller is all that’s required to control the SLED-C4 display. Serial data should be
sent from the host controller to the SLED-C4 display in standard non-inverted N, 8, 1 format, LSB first. During
idle or non-transmit periods, the host controller serial output pin should idle at Vcc or logic 1.

According to my scope I'm idling high. Any suggestions.

Thanks in advance,
pgb

Comments

  • KIHKIH Posts: 13
    edited 2008-09-12 14:52
    brightness on max?
  • pgbpsupgbpsu Posts: 460
    edited 2008-09-12 15:43
    @KIH -

    That's not something I'd considered. I added this just before I start looping over the write "1234" loop:

        debug.tx("B")                               ' enter brightness mode
        debug.dec(50)                              ' set brightness to about 1/2 max
        debug.tx("~")                               ' Serial packet termination character.  Force display out of input loop, causing immediate execution of last valid command.
    
    
    



    But it hasn't made any difference. Still "8888" at what appears to be max brightness. Any other suggestions....

    Thanks,
    pgb
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-12 16:20
    You say you scoped the signal at the prop and the sled and they were the same except for voltage but the 7404 is an invertor - so I would expect the signal to be inverted. I would guess you need the serial port inverted. Try setting
    debug.Start(1,SLED,%0000,19200)
    to
    debug.Start(1,SLED,%0011,19200)
    which will invert the tx and rx
  • pgbpsupgbpsu Posts: 460
    edited 2008-09-12 16:38
    Hi Timmoore-

    The 7404 is an inverter but I'm putting the output from the prop into the inverter, taking that output and putting it back into the inverter, taking that output and sending
    that into the SLED. I tried what you suggested and it didn't work. Although this makes sense. Because of the way my circuit is laid out- going through the inverter 2x- the idle
    state is now low, which is not what the SLED wants. I could remove one stage of the inverting process and use the change you suggested.

    I'm pretty sure the form of the serial input to the SLED (+5V, idle high) is correct. I'm not sure what bits precede and follow a debug.tx($AA) so I'm not sure I'm getting the
    correct bit pattern out of the prop. It looks like the FullDuplexSerial object shifts things to the right

                            shr     txdata,#1       wc
    
    



    which would be LSBit first correct?

    Thanks,
    pgb
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-12 16:50
    ok, if you have 2 invertors then the serial port should be correct. The serial port outputs 1 start bit, 8 bits of data and 1 or 2 stop bits (dont remember which).
    Looking at the Sled spec it seems to say you need to send "~" to have the device execute the last command. I can see you do that in the basic code but not in the spin code.
    You could try adding debug.tx("~" after output the 1,2,3,4.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-09-12 19:54
    Okay, I have used this display many times. You're sending the "D" followed by a binary 2...what does this do? It's not being sent in the BASIC Stamp example. Plus, each digit is being sent as raw binary, but your SPIN example is converting it to an ASCII value. The D puts the display into decimal mode and in that mode it wants raw values, not printable representations. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • AribaAriba Posts: 2,687
    edited 2008-09-12 20:40
    Instead of this code part:
    repeat 1000
          debug.hex($44,2)
          debug.dec(1)
          debug.dec(2)
          debug.dec(3)
          debug.dec(4)
          term.hex($44,2)
          term.dec(1)
          term.dec(2)
          term.dec(3)
          term.dec(4)
          pauseMsec(300)                                  ' wait 1 second before next reading
    
    


    try this:
    repeat counter from 0 to 1000
          debug.tx("D")
          debug.tx(counter/1000)
          debug.tx(counter/100//10)
          debug.tx(counter/10//10)
          debug.tx(counter//10)
          term.out("D")
          term.out(counter/1000+$30)
          term.out(counter/100//10+$30)
          term.out(counter/10//10+$30)
          term.out(counter//10+$30)
          pauseMsec(300)                                  ' wait 1 second before next reading
    
    


    and define the counter variable in the var section.
    the hex and dec methods of PC_Interface and FulDuplexSerial sends a String representation of the number,
    but you need single characters for the 4 digits of the counter value.
    I interpret the description so, that the display needs the values 0..9 ("decimal digits 0 through 9"), but it can also be that
    it needs the ASCII values 0..9, then add $30 to it, like in the term code above.

    Andy
  • pgbpsupgbpsu Posts: 460
    edited 2008-09-12 20:50
    Hi Chris and Ariba-

    Thanks for your posts. I won't be able to try this out until I get back to the lab on Monday, but I'm quite sure that the code I posted doesn't do anything to the display. It simply displays 8888 as it has done since turning it on. I'll try what you and Ariba have described.

    I hope my problem is that I'm not sending the correct representation of the numbers I want. That will be the easiest to solve. hop.gif I should have thought of this, but when I read decimal "0...9" I assumed ascii but sending %0000_0001 - %0000_1001 is well worth a try.

    Thank you both very much.
    Peter
  • pgbpsupgbpsu Posts: 460
    edited 2008-09-13 19:49
    Ariba-

    Your code worked perfectly. Thanks! I now know how to deal with the rest of the commands. It was a problem of using debug.hex. I should have thought of this,
    but for some reason it didn't occur to me.

    Thanks to everyone who posted.
    Peter
Sign In or Register to comment.