Need more cogs!
DiverBob
Posts: 1,110
For the first time I've come into the situation that I need more than 8 cogs. Since that is a fixed limitation, I'm looking at different objects that can perform the same or similar functions with either no additional cogs or reduce the cogs being called. The application uses 3 cogs, one each for motors that need to be able to run independently of each other. Another cog is used to continuously update global variables from 4 ADC channels using a MCP3208. The remaining cogs are using the following objects
Parallax serial Terminal - 1 cog, used for troubleshooting software, will not be needed later but critical at this stage
Servo32_9 - 2 cogs, great servo controller but I think this could be replaced by a 1 cog option.
Float32full - 2 cogs, I think Float32 can perform the same basic functions with 1 cog
I think I need to really replace servo32-9. It looks like either jm_servo8_adv or pwm_32 would be a good choice and both only use one cog.
Another option would be to take the ADC off its own cog and let the routines call the ADC routine when they need the value.
I'll be doing some experimenting with the above but wanted to see if others had some different approaches. Any opinions out there or are there other options I'm not seeing?
As always, thanks for the help!
Bob
Parallax serial Terminal - 1 cog, used for troubleshooting software, will not be needed later but critical at this stage
Servo32_9 - 2 cogs, great servo controller but I think this could be replaced by a 1 cog option.
Float32full - 2 cogs, I think Float32 can perform the same basic functions with 1 cog
I think I need to really replace servo32-9. It looks like either jm_servo8_adv or pwm_32 would be a good choice and both only use one cog.
Another option would be to take the ADC off its own cog and let the routines call the ADC routine when they need the value.
I'll be doing some experimenting with the above but wanted to see if others had some different approaches. Any opinions out there or are there other options I'm not seeing?
As always, thanks for the help!
Bob
Comments
I've attached my latest version. At the moment, I'm working on an update to allow up to 16 servos and improve the ramping resolution by switching from microseconds to system ticks (internal values only -- user interface won't change).
http://obex.parallax.com/object/229
Servo32 (I looked at version 7) only uses one cog if you don't sue the ramp function.
John Abshier
I tried out Float32 and it seems to work OK, what's the difference between it and F32?
I moved my ADC routine out of a cog but managed to break the code, troubleshooting that mess now. I may just move it back into its own cog again if I don't figure this out before my frustration level gets much higher... I hate it when a supposedly simple change just has much larger impact than ever expected!
In both cases, we structured the main loop something like this:
Total loop timing needs to be adjusted for channels, averaging, other processes.
John Abshier
What sort of resolution and what frequency do you need?
I'm pretty sure I've posted my four motor PWM object (though not in the OBEX) .
BTW, pwm_32 isn't a good choice for motors. the "frequency" is much too fast for some controllers.
Edit: I think my four channel PWM object also monitors four quadrature encoders. I'm sure I could be persuaded to clean out the encoder section if you just want to use the PWM section.
I've attached the project files from my July 2011 N&V column.
- add more cogs by adding physical prop chips, (MCS)
- control 8 servos with one cnt on one cog (I forget exactly how many can be controled, but you run out of pins before you run out of counters)
- use the float extension if you don't mind slow or use double and do it integer if you want fast.
But you have to start with the forth so that would be cheating
<snark>Yes, suggesting he start from scratch with a new language he may not know is always very helpful...</snark>
Johnny, I tried your servo object, the Set command works pretty well. The move command works but as it accelerates there are some hesitations like a counter is rolling over/overflowing or something like that. I'm not planning on using the move command but thought you might like to know. Since I'm actually controlling DC motors in a linear actuator via an HB25 using 10K pots for position feedback the movement time is considerably greater than you would have experienced with a standard servo.
Anyway, it works on a test program, now I'll shoehorn it into my ramping routine and se how it behaves.
Bob
Thanks for the quick help, this is definitely the place to go to get it. I want to play with your dual motor code once I get a break.
way to go. I follow your thread for a while now and am impressed with your work.
You are talking about getting rid of PST later, but how do your Leg controllers will talk to each other / some master controller?
I guess you still need that PST cog fore some form of communication between them, or not?
Anyways - one cog for LED strips is cool. Even animations possible. What a beast.
Enjoy!
Mike
I've never seen that myself, but I'll look into it. As said, I'm working on a version that [internally] uses system ticks instead of microseconds -- at 80MHz this result in an 80x improvement in granularity (at 80MHz system clock). I believe it will help, especially in ramping.