help with a delay in a spin code
mnemonics
Posts: 23
Hello everyone I need help with a spin code. I am using the 2 button shift speed code and want to add a few usec 2 to 4 delay in between pulses to make sure that the LED are completely off before the next one is turned on. You can't see it with a naked eye but i saw it in a pic I took. I am running some motors and coils in a very unique way and have to make sure that in the spin code 2 ButtonShiftSpeedfinal.spin
LED from 16 to 23 are being turned on and off with 20 to 23 completely opposite of the 16 to 19 LEDs. I am running two banks Bank one 16 to 19 bank two 20 to 23 . Bank one the LED pulse train one at a time , in Bank two when the LED of bank one are off the ones on Bank two are on, so the LED on bank two turn off when the one on bank one turns on. I used the !outa[20..23] to make that bank opposite of bank one. The code I attached works like I want it too but i want to make sure that when the LEDs on bank one, pins 16 through 19 turn on that there is a delay in between pulses of a few microseconds before each LED is turned on so that Bank two does not stay on while bank one LED starts to turn on. I took a pic of the blinking LEDs and noticed that when one pin was being turned on, the opposite bank LED should be completely off .
VAR
Byte LEDS, PULSES
PUB ShiftLedsLeft
dira[16..23] ~~ 'Pin 16 to 23 output
PULSES := 5
repeat
if LEDS == 0
LEDS := %1000 ' pulse 1 pin at a time from 16 to 19
!outa[20..23] 'Pin 20 to 23 are the opposite of 16 to 20 High
'when pins are low and low when pins are high
if ina[4] == 1 'if input on pin 4 is high increment pulses
PULSES ++
PULSES <#= 254
elseif ina[1] == 1 'if input on pin 1 is high decrement pulses
PULSES --
PULSES #>= 1
waitcnt(clkfreq/PULSES + cnt) (((( Can I add the usec after the cnt to every pulse here))))))))
outa[16..19] := LEDS
outa[20..23] := LEDS
LEDS >>= 1
Just want to make sure that the LEDs turn completely off before the next one turns on. In one of my pics I can see one LED turning on and the other opposite of it was not completely off. In the transition from on to off I need to make sure with maybe a 2 usec delay between pulses if it is possible. . Thanks.. and happy holidays
LED from 16 to 23 are being turned on and off with 20 to 23 completely opposite of the 16 to 19 LEDs. I am running two banks Bank one 16 to 19 bank two 20 to 23 . Bank one the LED pulse train one at a time , in Bank two when the LED of bank one are off the ones on Bank two are on, so the LED on bank two turn off when the one on bank one turns on. I used the !outa[20..23] to make that bank opposite of bank one. The code I attached works like I want it too but i want to make sure that when the LEDs on bank one, pins 16 through 19 turn on that there is a delay in between pulses of a few microseconds before each LED is turned on so that Bank two does not stay on while bank one LED starts to turn on. I took a pic of the blinking LEDs and noticed that when one pin was being turned on, the opposite bank LED should be completely off .
VAR
Byte LEDS, PULSES
PUB ShiftLedsLeft
dira[16..23] ~~ 'Pin 16 to 23 output
PULSES := 5
repeat
if LEDS == 0
LEDS := %1000 ' pulse 1 pin at a time from 16 to 19
!outa[20..23] 'Pin 20 to 23 are the opposite of 16 to 20 High
'when pins are low and low when pins are high
if ina[4] == 1 'if input on pin 4 is high increment pulses
PULSES ++
PULSES <#= 254
elseif ina[1] == 1 'if input on pin 1 is high decrement pulses
PULSES --
PULSES #>= 1
waitcnt(clkfreq/PULSES + cnt) (((( Can I add the usec after the cnt to every pulse here))))))))
outa[16..19] := LEDS
outa[20..23] := LEDS
LEDS >>= 1
Just want to make sure that the LEDs turn completely off before the next one turns on. In one of my pics I can see one LED turning on and the other opposite of it was not completely off. In the transition from on to off I need to make sure with maybe a 2 usec delay between pulses if it is possible. . Thanks.. and happy holidays
Comments
Here is a simple example...
If you set pins 23..20 in the same instruction as pins 19..16 then they should change exatly at the same time: Andy
http://learn.parallax.com/propellerc
Thanks Brandan, Interesting to see the code in C I will try all the advise everyone gave me. I appreciate it my friends Happy Holidays to everyone
Andy