simple programming hurdle
shmow
Posts: 109
·Here's the lowdown:
-I'm trying to control a cog (and see it's status too) but I'm not sure if I've done it correctly programming-wise
-when the cog is running a piezo is energized (I've fiddled with the times: piezo and waitcnt command)
and the piezo "fumbles" its sound when the cog stops before piezo is finished
-a LED is supposed to energize when the cog is running but alas it doesn't
Would appreciate any insights or advice.
-I'm trying to control a cog (and see it's status too) but I'm not sure if I've done it correctly programming-wise
-when the cog is running a piezo is energized (I've fiddled with the times: piezo and waitcnt command)
and the piezo "fumbles" its sound when the cog stops before piezo is finished
-a LED is supposed to energize when the cog is running but alas it doesn't
Would appreciate any insights or advice.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long stack[noparse][[/noparse]200] byte Cog_Seven byte Value_One OBJ BS2 : "BS2_Functions" ' Create BS2 Object PUB Main BS2.start (31,30) coginit(7, Lamp_Test, @stack[noparse][[/noparse]100]) 'initiate separate cog to operate LED on pin16 repeat 'repeat endlessly if Value_One == 0 Cog_Seven := cognew(ChimePulse, @stack[noparse][[/noparse]50])+1 'start method in new cog Value_One := Cog_Seven 'assign true value to conditional variable waitcnt(clkfreq+cnt) 'wait 3 seconds if Value_One 'stop cog with variable cogstop(Cog_Seven~ - 1) Value_One := 0 'reset variable PUB ChimePulse BS2.FREQOUT(14, 1000, 3000) 'send tone on pin 14 for 1 second PUB Lamp_Test dira[noparse][[/noparse]16]~~ 'set pin 16 to output repeat 'repeat endlessly outa[noparse][[/noparse]16] := Value_One 'set LED output to true
Comments
If you are just trying to learn about cogs and multiprocessing, how about getting the program to work using just the initial cog, then gradually moving functionality to other cogs one step at a time?
the sample of code in my previous message was part of a larger program I had written earlier.
the original·program would run as I had planned, but when I added this piezo sequence the program had trouble managing all of the memory or I/O (that's my·guess anyway).
I dedicated a cog to this piezo sequence and everything ran better.
I wrote the code in my previous message so I could understand cogs a little better.
The problem would arise, in my example, when the waitcnt command time was shorter than the time for the piezo to buzz.· If the piezo time equals the waitcnt command time then no problem but any difference would cause the piezo to sound intermittently.
I'm just looking for a more efficient way to manage cogs.
could you post a detailed description of what happened "had trouble managing all the memory or IO"
If you use SPIN everything is done in HUB-RAM. The HUB-RAM is ONE block of 32kB of RAM.
So i don't understand what you mean by "trouble managing memory" ?
I'm really want to understand your problem. But with the information given yet i do not understand it.
please post a REALLY DETAILED descritpion what you want to do and ask a CONCRETE question.
The more CONCRETE the question is the faster you will get a satisfying answer.
regards
Stefan