BlocklyProp Cogs
bluejay
Posts: 131
I understand that the P8X32A microcontroller chip has 8 cogs (cpu).
Can somebody please tell me how I can control 8 leds flashing at different rates using all 8 cogs by coding in BlocklyProp?
Thanks in advance.
Can somebody please tell me how I can control 8 leds flashing at different rates using all 8 cogs by coding in BlocklyProp?
Thanks in advance.
Comments
You'll make seven new processor blocks and put an LED function in each of them. The functions will have loops inside of them to toggle the LEDs.
Link these seven new processor blocks together - one on top of the other.
At the bottom, make another loop in the main processor (your eighth one) to control the eighth LED. You need to be a bit careful when doing this because some of the BlocklyProp blocks also start processors. Those are listed here https://learn.parallax.com/support/reference/propeller-blocklyprop-block-reference/about-multicore
Hopefully you'll be surprised at the possibilities after getting this to work. Let me know if you need an example.
Ken Gracey
Your first step would be to create a project and make seven new processor blocks, stacked on top of eachother. Inside each of those blocks, put a function with a unique name.
From this point, the rest is easy.
Ken Gracey
His Blinkenlights example code blinks 4 LEDs at different frequencies. You would just need to add 3 more functions to enable 7 blinking LEDs, then as Ken stated, add the code to blink an 8th LED within the main program.
I think you would end up with something like (untested, but should work):
dgately
How do I attach a file/s? Anybody could please help with answer?
@bluejay What platform are you using? FLIP, Activity Board, custom?
I have included a file that I made with an Activity Board with LEDs on the breadboard at Pins 10 and 11 with a 220 ohm resistor in series.
Download the file, rename and remove the .txt. You should have a .svg file to load in Blockly. You may just be able to double click on the file to open in Blockly.
There's a "CONNECT" button that needs clicking, and then you should see some log data appear below the button, to confirm the connection is working.
Have you covered that step ?
Even when running Solo, you must open the client and connect.
What pins are connected to the FLIP. Are you using 220 ohm resistors in series with the LED's?
Having never before used the cogs on a FLIP module, this article raised these questions. I would like to be able to do the following using BlocklyProp:
A. Wanting the LEDs to blink much longer, I changed the duration for milliseconds from 100000 to 4 billion (almost max in a 32 bit variable) which gives maybe 46 days if I did the math right.
BUT, is there some way to not have a time limit at all using these frequency functions?
B. Setting up 4 LEDs to blink in a fibonacci sequence (3, 5, 8, and 13 Hz), I noticed with a Saleae logic probe that each cog starts at a different offset from the previous on. Is there some way to have each cog start at the same, or very close to the same time (still using BlocklyProp)?
I'm curious if you could build your code using the pulsout BlocklyProp blocks. The libraries for these functions do not start new processors, so you could use them in a similar way. You'd need to put each one in a loop, and put the loop in a function. Remember to include an appropriate pause, too.
You could also try this with the servo angle block. This block runs in a processor and doesn't need a new processor block. Simply set the angle and move on to your next block.
Put the logic analyzer on them and let's see if there's a difference.
Somebody in Parallax would know the exact answer. It's a matter of how the underlying libraries have been constructed. Considering there are at least three ways to achieve this goal it would be a good idea to see if the other approaches above yield the same results.
Ken Gracey
I am using the frequency function but just in a trivial way, following along with the cited article to blink some LEDs at rates other than powers of 2 (no servos involved).
Since I knew nothing about cogs (and still know so very little), those 2 questions I posted did occur to me. There is nothing really important about getting all four LEDs to start off at the same time (as much as possible), just a curiosity. I guess the real question would be, how close is it possible using cogs to have four processes start at the same time?
I will be reading about cogs and studying some successful programs others have written.
Thank you for your reply.
Yes, it opens fine.
Are you using Windows or something else?
I think you have a problem with the code, too. You're trying to drive a servo with the frequency command. I'm not certain this will generate the signals needed by a servo (1-2K us high pulses followed with 20-40 ms low pauses in a loop).
Ken Gracey
I've attached a screen shot and the blocks code as an SVG. I have also made the project public:
-- https://blockly.parallax.com/blockly/projectlink?id=117532&key=862a32e1-958f-467a-ac95-00b0bbb385ee
The current project only has two LEDs because those exist on the Activity Board and the FLiP module. You can add more by duplicating the process_ledx() function and adjusting output and timing values for it.
For additional information, you may want to read my article on background timing using BlocklyProp:
-- https://learn.parallax.com/tutorials/language/blocklyprop/precision-timing-propeller
He also wrote this for us https://learn.parallax.com/support/reference/propeller-blocklyprop-block-reference/system and I put the system counter to use in my own project here https://learn.parallax.com/tutorials/language/blocklyprop/visual-metronome-project
Lots of ways to go about this. Keep reading, learning and trying.
Ken Gracey
SOLUTION: Removing the folder com.ParallaxInc.BlockyPropClient.savedState from /Users/rralston/Library/Saved Application State
REASON for problem: unknown (especially since problem was on 2 different computers and the second computer would presumably have had a fresh Saved Application State file since the BlocklyProp Client was just installed for this test).
What did not help:
Trying different saved project
Different USB cable
Different USB port
Different FLIP board
Using direct USB port rather than from USB hub
Reboot iMac (running Mojave 10.14.6 <— latest; connection to router is ethernet cable)
Download and reinstall BlocklyProp client (v0.7.5)
Reset Chrome (78.0.3904.97. <— updated since previous version(s) had a zero day exploit
Try Opera (64.0.3417.92. <—latest)
Try different computer, AirBook (running Catalina 10.15.1 <— latest); installed BlocklyProp client, used latest Chrome; connection to router is wireless
Reboot house router
If I had to put money on when this problem occurred, I'd say it was sometime between last night and today at noon Pacific time. I think the issue was on our servers and had nothing to do with your computer. Yesterday, Jim updated the BlocklyProp site and somehow got his containers a bit mixed up. The Educator Hotline, personal phones and e-mail were lighting up and subject to blitzkrieg response from Parallax in response. It seems that we mixed some of the solo.parallax.com files with the blockly.parallax.com files. Many people were unable to compile and download.
Was your problem in this timeframe?
Also, use Chrome with BlocklyProp.
And, have you seen solo.parallax.com? It saves locally and only goes to the cloud for compiling. Turns out it's a lot more reliable and in a year we'll be switching exclusively to this version.
Sorry you got all wrapped up in this problem. We owe you some time back!
Ken Gracey
Yes, I am convinced the problem was external from me. Today I tried my laptop expecting it to not find the FLIP and that I would have to remove the SavedState folder.
But, not true, the laptop worked as expected. So my solution above is wrong.
I will try the solo version.
Robert
BUT, the file length seems to be about 22 characters (excluding the project number) so many of my project titles are too short in the download. I will now alter the titles on the non-solo site and download again to retain the descriptiveness I need.
Anyway, we aim to make BlocklyProp as reliable as possible. So far the track record is really good and will improve with Solo.parallax.com.
Ken Gracey