the coginit-command problem
hcchen
Posts: 14
Dear all
I want to use different cog to do two things.
one cog be used for the motor, and anther be used for encoder.
I use the "coginit" , but nothing is happening
Anyone interest in helping.
the code:
I want to use different cog to do two things.
one cog be used for the motor, and anther be used for encoder.
I use the "coginit" , but nothing is happening
Anyone interest in helping.
the code:
CON _clkmode = xtal1 + pll16x _clkfreq = 80_000_000 MOTOR_L_B = 19 MOTOR_L_PWM = 20 MOTOR_L_A = 21 MOTOR_R_B = 22 MOTOR_R_PWM = 23 MOTOR_R_A = 24 #1, HOME, GOTOXY ' PST Constants #8, BKSP, TAB, LF, CLREOL, CLRDN, CR #14, GOTOX, GOTOY, CLS Obj Motors : "Eddie Motor Driver" Encoders : "Quadrature_Encoder" PST : "Parallax Serial Terminal" term : "FullDuplexSerial" ping : "Ping" VAR long ID long JC long JD long Stack long Stack1 byte Cog byte Cog1 long Time, Counter1, Last1, Delta1, Counter2, Last2, Delta2, Total2 byte Success PUB main | perl,perr perl:=$FFF perr:=$FFF coginit(1,go(perl,perr),@stack1) coginit(2,encoder,@stack) 'Success := (Cog := cognew(encoder, @Stack) + 1) PUB go(perl,perr) Motors.start repeat Motors.left(perl) Motors.right(perr) PUB encoder | enc1,IC pst.Start(115200) ID := 0 repeat IC := enc1 enc1 := ina[2] if IC <> enc1 ID := ID + 1 else ID := ID + 0 pst.Str(String(pst#CE, pst#HM, "ID = ")) pst.Dec(ID) PUB Stop if Cog cogstop(Cog~ - 1)
Comments
It's also very dangerous to use coginit. cognew is generally the preferred way of starting a cog.
Another issue is you just let cog #0 die. Why not use it for one of your tasks instead of starting a new cog?
Instead of starting the method "encoder" in a new cog, your "main" method could just call "encoder" and have the method run in cog #0.
I'm confused how you're using the encoders. It doesn't look like the object "Encoders" is ever used.
I neglect the cog#0.:thumb:(carelessness)
I don't know how to use "Ecoders".(Forget to remove the object)
I try to write the encoder which can read pulse on pin2.
if my code can't be use, I will find the information about "Encoders".
I will try to understand the code how to work.
Sorry but I take exception to this statement every time I see it. Coginit isn't inherently dangerous but, like every other command in every other language, you have to have a certain amount of knowledge before you can use it effectively. It, like some other commands, may not be suitable for people with little programming experience.
Knowing how to use coginit properly will allow you to change the code a cog is running during program execution or run PASM in all 8 cogs.
Basically it comes down to managing an array of 8 variables.
Sandy
True: those are both legitimate uses of coginit, but only to the extent required for reloading the cog you're running in with new code. In virtually every other case, it's unnecessary to assign code to any particular cog. Especially for just starting a new cog, cognew is still the best way to go.
-Phil
A good mechanic will know the capabilities of every tool in his toolbox and know which is the appropriate tool for the job. That way you get to use all the tools.
Most infantrymen believe that a piece of high explosive will solve any problem. One tool for everything!
Sandy