Cog Share Same Resource (LED1)
Humanoido
Posts: 5,770
Scenario: There are 8 cogs running the same little SPIN program to blink the same LED on pin 1. Obviously all programs accessing the same LED at the same time will crash. What is the solution? Thank you in advance.
Humanoido
Humanoido
Comments
Not true.
All those 8 COGS will run, set PIN 1 to output and proceed to toggle it up and down. They are all totally oblivious of each other.
Now, all outputs from all COGS are OR'ed together to give the final output on the PIN. So whenever any one of those COGs sets the pin high then the actual output will be high. No matter if other COGs have set it low.
This, of course, is probably not what you want. The LED might just end up on (or off) all the time depending on the phases and frequencies of the toggling in each COG.
Why do they all need to drive the same LED anyway, can't they have one each?
Let's say the LED blinking rate is different on the output from the program in each cog. There are actually 16 LEDs, each blinking at their own rate from one cog and every cog. So a way is needed to switch from one cog, and observe the output, and switch to the next cog, and observe the output, etc.
(this switching could take place automatically after some delay, enough to observe each cog's 16 LEDs blinking, maybe 5 or 10 seconds..)
Well, if each cog had its own 16 LEDs and didn't share, that would be a total of 128 LEDs and too much, especially when the project is upscaled.
Humanoido
It's still not clear just what you want to do. There is no way to "switch from one cog to another and observe the output" because the cogs and their outputs are inside the Propeller chip and there is circuitry (the OR network) between the cogs' outputs and the I/O pins that hides the individual cog's outputs. You can include code in each cog's program that makes a copy in hub memory of the OUTA register whenever it's changed and you can assign one cog to transmit the 7 long words to somewhere else where they can be displayed, but that's a function of your program, not the hardware, and it requires that one cog be dedicated to this monitoring.
I want the threads in each cog to continue to do their calculations and output to the LEDs one at a time (take turns). I plan to do this with software.
1) Using software, make sure no cogs try to blink LEDs at the same time (idea 1)
2) Using software, one cog blinks the LEDs for 10 seconds, stops blinking output to LEDs, but continues the work to do the blinking, and tells the next cog to start blinking
3) the process continues as all cogs will take turns blinking the LEDs until the cycle repeats
The idea is to have all props running at the same time doing some work and then take turns to report that work to output. Here, the work is code timing to do LED blinking and the output is in the form of 16 LEDs.
Each cog will have 16 threads running at the same time. Each thread drives one LED to its own blinking rate. Together, one cog will blink 16 LEDs, each at different rates.
I want to show that all threads in all cogs are indeed working. My idea was to have one cog output to pins while the other cogs, still running, simply do not output.
It would be nice if all cogs could send output, and that output could be selectively shown, one by one (one at a time).
You can include code in each cog's program that makes a copy in hub memory of the OUTA register whenever it's changed and you can assign one cog to transmit the 7 long words to somewhere else where they can be displayed.
Idea 2: What if all the cogs are doing work and all continue reporting to the register. Is there a software way to suppress/mask the register from getting that data from a specific cog? So the LED blinking will not be combined with the other cogs output...
Idea 3: Is there a round robin software way of cogs outputting to the same pins, taking turns?
In the simplest form, each cog blinks an LED and does not stop its blinking program. But there is some software way to view the output from each cog.
If this still does not make sense, I will need to go back to the books for a while.
Humanoido