Shop OBEX P1 Docs P2 Docs Learn Events
Blinking LED's problem — Parallax Forums

Blinking LED's problem

w0ssw0ss Posts: 6
edited 2011-05-24 17:48 in Propeller 1
Just got the Dev board today and wanted to start with PASM from the beginning.

I am having an issue with getting LED's to blink correctly.

When I tell certain pins to blink the pin next to it blinks as well.

This started after I was trying to write some code in PASM but now it is happening even in SPIN. The Spin code I wrote to verify is below and on the first pass only I see some LED's double up. This even happens after a reboot or a reset. It is almost like it is remembering the PIN state. It is probably something I did in PASM but I am unsure what. I was trying to do the second piece of code attached.
_clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

var long Pin
PUB Go
repeat
  Pin := 16
  repeat while Pin <24
    dira[Pin]~~
    outa[Pin]~
    repeat 2
       waitcnt(clkfreq/8 + cnt)
       !outa[Pin]
    Pin := Pin + 1

CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  
VAR
  long PinM,PinM1
  
PUB go
  PinM:=21
  cognew(@Toggle, @PinM)
  PinM1:=17
  cognew(@Toggle, @PinM1)
DAT

ORG 0
Toggle
              rdlong Pin, PAR
              mov LED, #1
              shl LED, Pin
              or dira, LED
              mov Time, cnt
              add Time, #$f
:loop         waitcnt Time, Delay
              xor outa, LED
              jmp #:loop


Delay   long 20_000_000
Time    res 1
LED     res 1
Pin     res 1

Comments

  • RaymanRayman Posts: 14,877
    edited 2011-05-24 10:12
    Code looks good to me. I do not see how the two adjacent pins are lighting up...

    Try posting your complete code for a case that exhibits this behaviour. Is what you posted above just a snippet?

    Are you doing this on a breadboard? Make sure have the required capacitors between Vdd and GND and the all the VDD and GND pins on the Prop are connected.

    Actually, maybe you should double check your crystal connection to make sure you have good contacts there.
    Maybe try with RCFast instead of the crystal...
  • PublisonPublison Posts: 12,366
    edited 2011-05-24 10:23
    If you are using the Propeller Demo Board, the outputs to the LED's are shared with the VGA DAC circuit. As you can see, some lines get tied together through the resistors.
    628 x 528 - 57K
  • w0ssw0ss Posts: 6
    edited 2011-05-24 10:25
    This is on the propeller demo board just received it yesterday. The code posted is the only code on it as I am just trying to learn PASM

    The first section of code has the double LED's on the first iteration only.

    The second section has the double LED blinking constantly. The "extra" adjacent Pin blinking is a lower intensity than if I set the pin to high so it makes me think something is bridged somewhere but the board looks good and not sure how it would bridge only in certain instances.

    I made a change to the code of the first program that fixes the blinking LED but I don't see why my original code does not work.
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000 var
    
    long Pin
    
    PUB Go
    
    dira[16..23] := %11111111
    repeat
        Pin := 16
        repeat while Pin <24
        outa[Pin]~
        repeat 2
            waitcnt(clkfreq/8 + cnt)
            !outa[Pin]
        Pin := Pin + 1
    
  • w0ssw0ss Posts: 6
    edited 2011-05-24 10:29
    I am using the Demo Board Publison. I would expect the double LED to be the case all the time not just in certain code examples. Perhaps I am missing something basic on this.
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-05-24 10:40
    Hi w0ss and welcome to the propellerforum

    I tried both codes on my PPDB and they worked as expectected.
    No doubling of LEDs

    I only changed the pin numbers to from 21 / 17 to 0-8

    What is the exact name of your board? Did you check carefully for shortcuts on your board?
    best regards

    Stefan
  • RaymanRayman Posts: 14,877
    edited 2011-05-24 10:40
    w0ss,

    I just tried your code on my demo board and it works as expected.
    But, I had to modify you indents...
    With SPIN, the indenting is very important...
    Here's what I did. Do you see how the indenting is a little different?
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    var
    long Pin
    PUB Go
    dira[16..23] := %11111111
    repeat
        Pin := 16
        repeat while Pin <24
          outa[Pin]~
          repeat 2
              waitcnt(clkfreq/8 + cnt)
              !outa[Pin]
          Pin := Pin + 1
    
  • RaymanRayman Posts: 14,877
    edited 2011-05-24 10:43
    BTW: If indents turn out to be the issue, you can see them more clearly by selecting in the Prop Tool menu "Edit"->"Preferences"->"Show Block Group Indicators".
  • w0ssw0ss Posts: 6
    edited 2011-05-24 11:48
    Rayman wrote: »
    w0ss,

    I just tried your code on my demo board and it works as expected.
    But, I had to modify you indents...
    With SPIN, the indenting is very important...
    Here's what I did. Do you see how the indenting is a little different?
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    var
    long Pin
    PUB Go
    dira[16..23] := %11111111
    repeat
        Pin := 16
        repeat while Pin <24
          outa[Pin]~
          repeat 2
              waitcnt(clkfreq/8 + cnt)
              !outa[Pin]
          Pin := Pin + 1
    

    That is the code that works on my device as well. Yes the indenting is as you show in the IDE. The cut and paste seems to fool with it here.

    The code that doesn't work is in the first post it has the
    dira[Pin]~~ within the inside repeat.
  • w0ssw0ss Posts: 6
    edited 2011-05-24 11:51
    StefanL38 wrote: »
    Hi w0ss and welcome to the propellerforum

    I tried both codes on my PPDB and they worked as expectected.
    No doubling of LEDs

    I only changed the pin numbers to from 21 / 17 to 0-8

    What is the exact name of your board? Did you check carefully for shortcuts on your board?
    best regards

    Stefan
    Thanks for the Welcome!

    My board is the Propeller Demo Board Rev G from Parallax.

    http://www.parallax.com/tabid/768/ProductID/340/Default.aspx
  • RaymanRayman Posts: 14,877
    edited 2011-05-24 12:18
    Ok, I see the problem.

    Publison had it right...

    You're seeing the result of the LED circuit being also connected to the VGA circuit...

    One the first loop, dira starts out all cleared.
    But on subsequent loops, dira is set on all pins.

    On the first loop, when you get to P18, current can go through the 470 ohm resistor to the VGA output pin, then come back in through the 240 ohm resistor and power the LED on P19...

    On the second loop, P19 is already enforcing 0 volt output when the loop starts.
  • w0ssw0ss Posts: 6
    edited 2011-05-24 12:34
    Rayman wrote: »
    Ok, I see the problem.

    Publison had it right...

    You're seeing the result of the LED circuit being also connected to the VGA circuit...

    One the first loop, dira starts out all cleared.
    But on subsequent loops, dira is set on all pins.

    On the first loop, when you get to P18, current can go through the 470 ohm resistor to the VGA output pin, then come back in through the 240 ohm resistor and power the LED on P19...

    On the second loop, P19 is already enforcing 0 volt output when the loop starts.


    Thanks for the explanation. I understand what is happening now. I assumed because the LED was not lit that it was the same as pulling it to 0 volt but that is not true.
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2011-05-24 13:02
    The LEDs in the same pins as the VGA can be stopped from back feeding themselves by putting two ordinary silicon diodes, in series from each of the R, G and B pins of the VGA socket down to ground. The two diodes form a 1.4 Volt forward conduction, this is high enough not to affect the 1 Volt signal that goes to the VGA (if used) but is too low to allow the LEDs to start conducting (usually about 1.8 Volts ish).
  • PublisonPublison Posts: 12,366
    edited 2011-05-24 17:48
    I have also found on the Demo Board, if you set 16..23 to outputs first, it does not display the adjacent LED.

    Examples:

    Ray's code sets 16..23 to outputs before running the LED code. This works correctley off the bat:
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    var
    long Pin
    PUB Go
    dira[16..23] := %11111111
    repeat
        Pin := 16
        repeat while Pin <24
          outa[Pin]~
          repeat 2
              waitcnt(clkfreq/1 + cnt)
              !outa[Pin]
          Pin := Pin + 1
    

    Your first code will run with adjacent LED's lighted through the first repeat, then correctly in subsequent loops, because all the pins are now tagged as outputs. (All pins are inputs upon power up as default):
    _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    var long Pin
    PUB Go
    repeat
      Pin := 16
      repeat while Pin <24
        dira[Pin]~~
        outa[Pin]~
        repeat 2
           waitcnt(clkfreq/1 + cnt)
           !outa[Pin]
        Pin := Pin + 1
    

    Just to prove that, I added line 8 which changes 16..23 back to inputs before the loop was run. I displays the adjacent pin phenomenon each time:
    _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    var long Pin
    PUB Go
    repeat
      Pin := 16
      dira[16..23]~
      repeat while Pin <24
        dira[Pin]~~
        outa[Pin]~
        repeat 2
           waitcnt(clkfreq/1 + cnt)
           !outa[Pin]
        Pin := Pin + 1
    

    PS: Also forgot "Welcome to the Forums" :smile:

    EDIT: Should have read Ray's post all the way through! He said what I just posted!!
Sign In or Register to comment.