COG "ownership" of I/O PINS
HI everyone,
I haven't posted for ages, but I can tell you I have been extremly busy for the whole year! ( and I do read this forum everyday to keep in touch)
I have a issue with accessing I/O pins and COGS that use them.
I have a main loop ( cog 0 )and that main loop needs to set ( Initialize) the direction & the state of a I/O pin, in this case an OUTPUT & LOW
During programm execution, this same pin need to be change to HIGH but within a NEW COG, then when the cog is finished , the main loop ( therefore the first COG ) will control this pin. ( I am pretty sure that never a cog wants to act upon the same pin at at the same rime, i.e they take turns)
For some reason my second cog seems to not make any differnece to the state of the PIN.
I thought I have solved this issue years ago! as I have done a similar thing before.
What I normally do I in my NEW COG routine is to "re-initialize" the direction using..
DIRA[MyPin] := Output ( so that this cog "owns" the pins direction) So I believe.
I then set the state ( hi or low ) as needed. but this does not apper to be working
Can any one shed some light on where I am going wrong?
Thanks
Dave M
I haven't posted for ages, but I can tell you I have been extremly busy for the whole year! ( and I do read this forum everyday to keep in touch)
I have a issue with accessing I/O pins and COGS that use them.
I have a main loop ( cog 0 )and that main loop needs to set ( Initialize) the direction & the state of a I/O pin, in this case an OUTPUT & LOW
During programm execution, this same pin need to be change to HIGH but within a NEW COG, then when the cog is finished , the main loop ( therefore the first COG ) will control this pin. ( I am pretty sure that never a cog wants to act upon the same pin at at the same rime, i.e they take turns)
For some reason my second cog seems to not make any differnece to the state of the PIN.
I thought I have solved this issue years ago! as I have done a similar thing before.
What I normally do I in my NEW COG routine is to "re-initialize" the direction using..
DIRA[MyPin] := Output ( so that this cog "owns" the pins direction) So I believe.
I then set the state ( hi or low ) as needed. but this does not apper to be working
Can any one shed some light on where I am going wrong?
Thanks
Dave M
Comments
Based on your description you shouldn't be having problems. And FWIW, here's a little demo
con _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' use 5MHz crystal CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq MS_001 = CLK_FREQ / 1_000 US_001 = CLK_FREQ / 1_000_000 con LED3 = 18 LED2 = 17 LED1 = 16 var long selection long stack1[32] long stack2[32] long stack3[32] pub main cognew(light(1, LED1), @stack1) cognew(light(2, LED2), @stack2) cognew(light(3, LED3), @stack3) repeat selection := ++selection & %11 pause(150) pub pause(ms) | t '' Delay program ms milliseconds t := cnt - 1088 ' sync with system counter repeat (ms #> 0) ' delay must be > 0 waitcnt(t += MS_001) pub high(pin) '' Makes pin output and high outa[pin] := 1 dira[pin] := 1 pub low(pin) '' Makes pin output and low outa[pin] := 0 dira[pin] := 1 pub toggle(pin) '' Toggles pin state !outa[pin] dira[pin] := 1 pub input(pin) '' Makes pin input and returns current state dira[pin] := 0 return ina[pin] con pri light(myflag, myled) repeat if (selection == myflag) high(myled) else low(myled)
Thanks for replying
So If COG 0 starts with..
DIRA[MyPin1] := Output and OUTA[MyPin1] := High,
Then COG 1 does..
DIRA[MyPin1] := Output and OUTA[MyPin1] := High,
Will the result of MyPin1 be HIGH?, AND Do I need to Declare "DIRA[MyPin1] := Output" again in the second cog??
OR
If COG 0 says..
DIRA[MyPin1] := Output and OUTA[MyPin1] := High,
Then COG 1 says..
DIRA[MyPin1] := Output and OUTA[MyPin1] := Low,
will the result of MyPin1 be Low ?? or do I have to get COG0 to make MyPin1 := LOW, before letting COG1 take control??
Thanks
Dave M
Yes, each COG has to set the output-pins in DIRA because each COG has it's own DIRA-register.
Thanks for the replies well explained!,
I can see know where i was going wrong, I have discovered that I don't actually need to control this particular pin from the second cog, I can set it just before the cog starts, and reset it back when the cog finishes.
But sometime this type of control of a pin need to be done,
Thanks
Dave M
Page 8 of the Data Sheet may make things clearer:
http://www.parallaxsemiconductor.com/sites/default/files/parallax/Propeller-P8X32A-Datasheet-v1.4.0_1.pdf