what did i do wrong new cog in spin
Anubisbot
Posts: 112
Hi, i want to start the the pwm.spin from pwm_update.spin in a new cog, and want to be able to later change the values of the lang array in the main cog. so the second cog with the pwm generator kann keep runnig continusly.
for debug i wanted to use the pc_text.spin
When i compile and run it i get only the text string not the cog value
and i cand find if its bposible to write to a lang arry from a nother cog
Thanx
AnubisBOT
Post Edited (Anubisbot) : 5/22/2007 10:59:20 AM GMT
for debug i wanted to use the pc_text.spin
When i compile and run it i get only the text string not the cog value
and i cand find if its bposible to write to a lang arry from a nother cog
Thanx
AnubisBOT
Post Edited (Anubisbot) : 5/22/2007 10:59:20 AM GMT
Comments
It's also impossible (deliberately) to read or write to any variable in another object. This is always done with a "helper" method in the object with the variables. Since your SetPWM routine only sets the values of pwm_state and your REPEAT loop only reads them, you don't need to use semaphores (locks). Replace your start routine with:
Then just use "id := pwm.start" instead of the statement with the cognew in your main program.
You also have to use pwm.SetPWM instead of the one in your main program.
now the tv out works and it starts something, but the pwm funktion seem to only drive them high all the time,
pwm.spin
CON
TableSize = 500
VAR
' Holds the value the output should take at each instant in time.
long pwm_state[noparse][[/noparse]TableSize]
long cogStack[noparse][[/noparse]20]
PUB Start
SetPWM(9,1) ' initialize the table
SetPWM(10,1)
SetPWM(16,1)
return cognew(pwm_loop,cogStack)
PRI pwm_loop | t
' start the time value at zero
' PWM Loop
dira[noparse][[/noparse]9] := 1 ' Make pin 0, pin 1, and pin 2 all outputs
dira[noparse][[/noparse]10] := 1
dira[noparse][[/noparse]16] := 1
t := 0
repeat
outa := pwm_state[noparse][[/noparse]t] ' Set states of all 3 pwm pins simultaneously
t += 1 ' Change to the next state
if t := TableSize ' If t goes off the edge of the table NOTE change
t := 0 ' start over at beginning
PUB SetPWM(pin, percent) | i, count
' Determine how many pixels to turn on for any table size
count := (percent * TableSize) / 500
repeat i from 0 to TableSize - 1
if i < count
pwm_state |= (1 << pin)
else
pwm_state &= !(1 << pin)
pwm_update.spin
{{ PWM_Update.spin }}
_clkmode = XTAL1 + pll16x
_xinfreq = 5_000_000
VAR
OBJ
pwm : "pwm"
TV : "PC_Text" 'You can also use TV_Text or VGA_Text objects
PUB Start |id
TV.start(0)
TV.str(string("debug...",13))
id:= pwm.start
TV.dec(id)
repeat 20
waitcnt(50_000_000 + cnt)
pwm.setpwm(16,1)
waitcnt(50_000_000 + cnt)
pwm.setpwm(16,500)
Thanks
Anubisbot
[noparse][[/noparse]code]
Post Edited (Anubisbot) : 5/21/2007 9:45:05 PM GMT
Thanks mike...
Anubisbot
You should also put a check in SetPWM to make sure that percent is between 0 and 100.
here is my code..
i dont see why it dosent work,
Anubisbot
Maybe you need the·'repeat' as shown. It the same as·for(;[noparse];)[/noparse];·in c. It makes sure your prgram keeps running after starting the extra cog.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's not all that hard to count the number of grains of sand on the beach. The hardest part is making a start - after that it just takes time.·· Mirror - 15 May 2007
when i change it to this it runs but it changes my pin 15 to out i think
Anubisbot
Why are you doing the ">> 5"? pwm_state is already set up as a bitstring for all the I/O pins.
Why are you doing the "outa[noparse][[/noparse]11..4]"? You can set all the output pins ("outa := pwm_state[noparse][[/noparse] t ]") because each cog has its
own private copy of OUTA. If a bit in DIRA is set to zero, the corresponding OUTA bit isn't really used. You do need the initialization
statement that sets bits 11 through 4 of DIRA, but you don't need to do that for OUTA.
I think in your code that the ">> 5" would have to be a ">> 4" to work properly.
Attached are the files i use.
when i start ir remorte test.spin it starts the debug PC_Text.spin
Thats ok, then it reads the ir signal comming in on pin 15, i see the velue on the screen .
but when i press 1 on my remote it starts the pwm.spin the lights go on and my remote stops working.
I dont get i tried all things back and forth all night..
Somebody out there how has an idea
Anubisbot
Thats strange, or di i miss a littele like the a . or something...
Anubisbot
no i dont think so, because there is a stop routine what i call every time i call ir.start
and the hole setup works until i press the 1 on the remote (start the pwm.spin)
When i press 2 or 3 or anny other button on the remote it works just fine. and the remote is every time in cog2, cog1 is PC_Text.spin for debuging, and main cog is IR_Remote_Test.spin
What i can see is as soon i call pwm.start , so it goes to pwm.spin and does the start routine sets the pwm values in a table and starts running, but i think it does it in the main cog, because my main loop stops totaly.. thats wierd..
Anubisbot
I still don't understand why you have to stop and restart the remote code receive routine for every code.
I see one problem: In the COGNEW call in PWM.start, you need to pass the address of the stack array like: @cogStack
i thought that when there is no endless loop it would atomatick return to here i called it...
Does you now why.. maybe a new trap..
Anubisbot
But i thinck we can close this treat now ,
And again a big thanx to Mike..
Anubisbot