Can I do this complex multi-threaded task on propeller, without much hassle?
CuriousOne
Posts: 931
We have some chip, this chip should be able to do following tasks altogether, without one task causing problems to another one.
Drive and multiplex 4 digit, 7 segment display, pretty much like MAX7219 does, but without using any additional hardware, such as shift registers and so on.
Constantly monitor voltage on 4 inputs and calculate some dependencies from these values.
Work with 4x4 matrix keyboard.
Constantly measure pulse width and quantity on 2 pins.
generate PWM signal on 4 outputs, based on some internal data.
drive some logical level outputs
an additional "core" should interpret all the data received, and send data to display unit, outputs and pwm module, according to calculations.
Is this all possible with propeller?
Technically, I know I can do it all with PICbasic and some 18F high end chip, but interrupt management from picbasic is pain in the back.
Drive and multiplex 4 digit, 7 segment display, pretty much like MAX7219 does, but without using any additional hardware, such as shift registers and so on.
Constantly monitor voltage on 4 inputs and calculate some dependencies from these values.
Work with 4x4 matrix keyboard.
Constantly measure pulse width and quantity on 2 pins.
generate PWM signal on 4 outputs, based on some internal data.
drive some logical level outputs
an additional "core" should interpret all the data received, and send data to display unit, outputs and pwm module, according to calculations.
Is this all possible with propeller?
Technically, I know I can do it all with PICbasic and some 18F high end chip, but interrupt management from picbasic is pain in the back.
Comments
I think that practically almost all of that could be done even in a single core, but certainly depending upon the frequency of the pulse width measurement that might go on it's own cog and of course having an application cog simplifies things too.
As for the 7 segment display and keypad matrix that can be easily run from the one cog along with monitoring voltage etc as your scan time has to be fairly slow and so it may as well monitor voltage while it's sitting around. The multi-channel PWM can run from one cog and I can get up to 32-channels of 8-bit 7.6kHz PWM from the one cog.
cog #1 PWM
cog #2 keypad + display + monitor voltage
cog #3 measure pulse width
cog #4 application cog which also drives outputs
cog #5 free!
cog #6 free!
cog #7 free!
cog #8 free!
You still have the option to split cog #2 up but the scan loop for that is non-critical and very easy to implement.
btw, your requirements are not at all complex but certainly they are simple to implement on the Propeller.
But...
Do you have enough I/O pins?
What current do you require for the 7seg LEDs - the common anode/cathode may require a transistor driver depending on the total current.
You will need to do ADC for the voltage inputs, requiring an extra pin - see the ADC app note. I have decoded a touch screen using 5 pins.
From what you describe you should have enough cogs.
Here's one OBEX object (http://obex.parallax.com/object/715) for scanning a 4x4 keypad using a few passive components and only 1 I/O pin.
Not trying to sound like a fanboi, but Propeller is good stuff. I started on Motorola assembly and did a lot with that way back then, and I know a thing or two about the 8031 and the Z80s, and it continually blows my mind that the propeller is as versatile as it is.
Propeller is a fantastic concept that actually works- it is real nice when your project has a nice snappy keyboard, the display is nice and fluid, while it's running 4 serial ports, reading and averaging 8 analogs, outputting to the PC and sending it wirelessly all at the same time.
Arduino, phooey.
Drive and multiplex 4 digit, 7 segment display - 11 or 12 pins
Constantly monitor voltage on 4 inputs and calculate some dependencies from these values - 8 pins
Work with 4x4 matrix keyboard - 8 pins
Constantly measure pulse width and quantity on 2 pins - 2 pins
generate PWM signal on 4 outputs, based on some internal data - 4 pins
drive some logical level outputs - some more pins
Total 34 plus some more pins... and the Propeller has 28 of them free (these 28..31 pin has to be left for eeprom and uart)
Okay, but for a negligible bit of silicon he can have a very nice display and knock 10 pins off that count. Maybe not one chip, but as close as can be. Still a win.
I assume there will be other hardware mounted on this board, and I guess I'm confused as to why the aversion to shifting out the display data. Nice elegant solution for 50 cent's worth of silicon. Considering that none of this was possible 20 short years ago, I think that doing what he wants on a board not much bigger than a business card is a miracle. I used to lay out boards with technical pens and vellum.
And the digit select lines can double as 4 keyboard select lines, saving another 4 pins.
So that leaves 6 pins left over for other things, and no extra hardware used.
Cheers,
Peter (pjv)
The 4 digit LED display could be driven from a numberof chips but let's assume it's discrete drive and we have 8 segment drives and 4 column selects, so that's 12 I/O. But wait while we are scanning the display we can also be scanning the 4 columns of the keypad with the same I/O although we need 4 row inputs. So that makes the discrete keypad/display closer to 16 I/O. Also the reason I assigned these to the one cog and due to the slow scan time it can easily read the ADC.
So far 19 I/O total plus 4 for PWM out = 23.
Measure pulse width. How many? Let's say two so that's 25 I/O so far.
Drive some outputs but once again how many? If we give it 3 but once again more can be had over I2C. So that's 28 I/O + 2 for I2C + 2 for serial = 32.
The greatest hog is the display + keypad and there are many ways of reducing this, even dumb shift registers work well (4 74HCT595s + resnets drive 4 digits directly off 5V).
You are right, the emphasis WAS on the software, and that is easy with multiple cogs, but if there were insufficient I/O pins, then there was little point.
And, because the OP was asking for no additional chips -at least on the display- I presumed that there was a desire to keep all external hardware to a minimum, and hence I suggested single pin Sigma Delta analog conversion, requiring no extra chips.
ErNa;
The Sigma Delta can be done with a single pin per channel by using some twisted code, albeit not with great speed, nor great precision.... probably 8 bits, but can't recall just now.
Cheers,
Peter (pjv)
Ah, "no additional hardware such as shift registers", yes. Quite unrealistic really, I mean choosing to use a 4 digit 7-segment LED display indicates you need the visibility which at times means bright which means current and that cannot be realistically expected to be sourced from any micro. Even at 10ma/segment average that would still result in 320ma exceeding the absolute maximum ratings of the Prop chip. No, these need extra chips of some kind, so unless he is happy to have it not so bright or state why he needs LED displays so we can consider an alternative then he cannot do it without additional hardware.
Has anyone really used the sigma-delta for DC other than low precision stuff?
Right with your interpretation. I guess it all depends on what the OP's requirements are. A huge guess from this side.
Regarding Sigma Delta, I use them in quasi precision work.... thousands of units sensing temperature via thermistor with a few degrees of accuracy, and sensing wheatstone bridge pressure sensor to a few millivolts. Only a few of thos made, but hopefully a big bunch coming up.
Cheers,
Peter
Here's an object I wrote and have tested with ten digits - http://obex.parallax.com/object/753
The displays are quite readable even when driven directly by the Prop pins.
I had:
Cog 0 had the serial debug terminal if compiled, I used bst at the time
I made the user interface in LMM, not to brag but it was quite cool at the time. I should have used spin... knowledge comes (sometimes) with experience and as time slips away...
Edit: I look at the code and a tear forms in my eye. I used everything I developed and talked about here at the time: LMM, BCD math and FFT, and bst of course.
Not 100% sure that can be done with charlieplexing, but it might be possible.
Thanks everyone for detailed explanation!
Let me clear some things.
1st, I know how to do all above with additional hardware, maxim even has a chip which can do both led display driving and keyboard scan at same time. So all this is quite old stuff (for me) and I'm interested in alternative ways, because:
2. as it was remarked, since I need to fit all this in single chip, this might be because I have space constraints, and this also means that 7 segment leds being used are also quite small and need tiny amount of current. It also can be estimated, since I need smallest footprint, want to use led display, this means that I'm doing a rugged device, which should work on temperatures below zero, so, no LCD's welcomed.
The reason why I asked to split code across the cores, is for better readability and independency of program components.
Voltages does not need to be monitored with great accuracy - 8 bits will be enough. Pulses will be the sync signal from tv video, so no super speed or accuracy also here.
Didn't think you were coming back! Still don't know about the extra I/O, however what you want will fit into a Prop but unless you retask the serial and I2C lines there aren't any I/O left over, but it does do what you want.
COG I/O FUNCTION
0...4...PWM
1...16..8x4 LED + 4x4 KEYPAD (4 common)
2...2...MEASURE SYNCH
3...5...4 CHANNEL SIGMA-DELTA A/D with common feedback
3...5...APPLICATION inc SERIAL + I2C + 1 extra I/O
4
5
6
7
=...32 I/O
All variants of the Propeller have 32 I/O pins. It has been that way since day one.
http://www.parallax.com/sites/default/files/downloads/P8X32A-Propeller-Datasheet-v1.4.0_0.pdf
To add more I/O would require external hardware.
I am almost certain (99.44%) that you can reduce the number of pins for #1 from 16 to 12 pins by interleaving reading of the keypad with multiplexing the display.
At the beginning (or end) of each digit select set the 4 digit select pins and 4 of the segment/dp pins to inputs.
Set 1 of the 4 remaining segment pins that are still outputs (also connected to keypad columns) high.
Input data from the 4 segment pins that were set as inputs (also connected to keypad rows) and de-bounce/decode any keypress.
Repeat for each digit select so: col1/ds1, col2/ds2, col3/ds3, col4/ds4.
Done in pasm the keyboard scan portion of the code would be so fast that it would have very little effect on the brightness of the leds.
I wonder if you need to anyway since there are enough I/O already plus there's still the serial and I2C left over that can be repurposed easily enough. If only 28 I/O are needed and the Propeller has 32 then it is a good fit.
With 700+ posts, you're joshing us, right? Yanking the 'ole chain. Yes? No? (BTW, I do know that it would be possible to miss that by focusing on applications and so on.)
But that gets me to thinking: suppose (and I'm just speaking off-the-cuff, here) we had a version of the Propeller with, oh, I don't know, say double the number of I/O pins. And, while we're just dreaming, why not double the number of cogs (to 16), as well. Oh, and more memory would be nice, say on the order of 16X more (for a total of 512KB). Hmm, maybe we should create a webpage similar to the following to discuss such a beast: http://forums.parallax.com/showthread.php/155132-The-New-16-Cog-512KB-64-analog-I-O-Propeller-Chip
Speaking of which, over on the P2 forum, aren't we about due for an update? But be that as it may, the posters here are right about trying to get the most out of the available resources as possible. And to very loosely paraphrase Ken's "design with what we offer" advice, a Prop 1 in the hand is worth two Prop 2's in the fab.
What can I say Peter, I'm a firm believer in the "waste not, want not" philosophy, and on top of that I like to keep pins 28-31 free if possible. On top of that I can see that doing the two tasks together saves some duplication of code when compared to doing them separately. To add icing on top of that there might even be code space and time enough left to add a third task to the cog.
Yes, my IoT5500 module does all that it does with SD filesystem and network servers in basically one cog, although another one is used for serial console receive and another for background timing functions. So with the OPs requirements I don't see a problem with handling keypad and display in one cog since they are I/O linked and can just do what they do in sequence. But if the OP finds it's easier to use more cogs, well then, that must be easier.
BTW, I never like to repurpose my I2C and serial but some may never use serial normally and I guess the I2C could be used for column selects etc but in this situation there are sufficient I/O anyway. To me the I2C is a bus, something that some seem to forget and how many times do I see other I/O used for I2C when there are two there waiting to be used. As for the serial, it's my interactive console link for programming, debugging, reporting etc.
Currently, I have two main competitors - on one side there's Propeller with Spin, and on the other side, PIC18F45K22 with Picbasic pro. The later seems to be more easy to study, since 99.99% of basic stamp code can be directly used, but multitasking appears to be very tough task with picbasic pro, so this is why I'm looking into propeller.
Over the years I have worked with a lot of uC's, starting with ttl based systems built around the 74181 and on to 8008, 8080, Z80, 65xx, 68xx, 1802, and so on. On most of those projects whether the base high level programming language was some form of Basic or something else I ended up coding some part of it in the chip's assembly language. Getting the assembly code and hll code working together was always a hassle.
Combining spin and pasm is hassle free, and multitasking on the propeller is a breeze compared to an interrupt based system.
There is no competition. Use the Prop. Unless the PIC has some built in peripherals you really need that the Propeller lacks. Or it wins on speed or RAM space. I don't know the PIC but I doubt it. Or unless there are some other pressing needs like power consumption or physical size.
Spin is as easy to use as any BASIC. Except perhaps if you need floating point numbers.
Multi-tasking, at least up to 8 tasks, is of course a breeze on the Propeller. Depending on your tasks you can of course do many things in a single COG, much the same way as people manage to combine many functions into an Arduino or whatever single core device.
As a bonus you get to tap into the huge and willing support network here on the forum.
I do so hardware problems won't stop the Prop from booting.