Blinking LED's problem
w0ss
Posts: 6
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.
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
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...
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.
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
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?
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.
My board is the Propeller Demo Board Rev G from Parallax.
http://www.parallax.com/tabid/768/ProductID/340/Default.aspx
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.
Examples:
Ray's code sets 16..23 to outputs before running the LED code. This works correctley off the bat:
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):
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:
PS: Also forgot "Welcome to the Forums"
EDIT: Should have read Ray's post all the way through! He said what I just posted!!