Which Microcontroller for Active Monitoring of Inputs
Kasmodean
Posts: 3
Hello,
I haven't used a stamp in a while, but I have a new task I think could make the use of a microcontroller. But I need some advise.
From what I remember the stamp instruction are serial. It does one thing then the next, but can't do two things at a time.
Example: Output high for 10 seconds when input is high.
While it is timing the 10 seconds if the input goes high again the timer won't reset because the stamp is timing not looking at the input.
This might be wrong, but is what I remember.
The task I have now has the following: 9 inputs and 4 output
I need the microcontroller to monitor the inputs and adjust the outputs as required.
But input timing is important.
Which microcontroller can simutaneous control outputs while monitoring and reacting to inputs and internal timers?
If the stamp or propeller can't do this, is there something that can (at hobbist level)?
Thanks.
I haven't used a stamp in a while, but I have a new task I think could make the use of a microcontroller. But I need some advise.
From what I remember the stamp instruction are serial. It does one thing then the next, but can't do two things at a time.
Example: Output high for 10 seconds when input is high.
While it is timing the 10 seconds if the input goes high again the timer won't reset because the stamp is timing not looking at the input.
This might be wrong, but is what I remember.
The task I have now has the following: 9 inputs and 4 output
I need the microcontroller to monitor the inputs and adjust the outputs as required.
But input timing is important.
Which microcontroller can simutaneous control outputs while monitoring and reacting to inputs and internal timers?
If the stamp or propeller can't do this, is there something that can (at hobbist level)?
Thanks.
Comments
Welcome to the forum.
Pretty much any processor can be made to do multiple things at the same time, or at least give the appearance that it does. Either by polling it's inputs or by using interrupts. As you said "timing is important" the illusion of parallel activity can only work if the processor is fast enough to keep up with the expected changes in it's inputs and the expected response time from input event to output.
So, to really answer your question we need to know what kind of signals you expect on your 9 inputs, what rate are they going to be changing, what maximum delay between and input change and a corresponding output is acceptable and what processing you want to do on the data. Clearly if the inputs only change one an hour and a one minute latency is OK then any mcu can do it. If we are toggling inputs at megahertz and expect nanosecond response times things get a bit harder.
Assuming your requirements are somewhere in between I would always advise to look into the Propeller, it is very capable, has real parallel processing capability and is dead easy to use.
3 mode switches (User Selected)
6 Limit Switches (Monitor status of system)
4 Outputs (Control Motors [through mosfets])
If two mode switches are selected do nothing.
If the mode buttons are switched fast cancel last action and start new action.
If limit switch is trigger immediate stop
Timing is in approximate tenths of seconds (human time, not machine time)
One thing I am worried is if a user button is pressed the code might be somewhere else in the code and not “see” the button press.
Proposed code for stamp (not in syntax):
Loop
If Input1=1 and input 2=0 and input3=0 then
......‘cancel last action
......output1=0
......output2=0
......output3=0
......output4=0
......‘start new action
.....Output1=1
.....Output2=1
End if
If Input2=1 and input 1=0 and input3=0 then
.....‘cancel last action
.....output1=0
.....output2=0
.....output3=0
.....output4=0
.....‘start new action
.....Output2=1
.....Output3=1
End if
If Input3=1 and input 1=0 and input2=0 then
......‘cancel last action
.....output1=0
.....output2=0
.....output3=0
.....output4=0
‘start new action
.....Output3=1
.....Output4=1
End if
If input4=0 or input5=0 or input6=0 or input7=0 or input8=0 or input9=0 then
......output1=0
.....output2=0
.....output3=0
.....output4=0
end if
Go To Loop
Checking a switch and making a simple decision based on its setting should take a couple of milliseconds at most. Even for 10 switches, that's well within your time limit. Rather than a series of complex IF statements, you should group the switch values so they form a number. 3 mode switches becomes a value from 0 to 7. 6 limit switches becomes a value from 0 to 63. You can use these values in a SWITCH/CASE statement or as an index into a table to decide on an action. For the limit switches, it's easy to test for "any limit switch activated", stop the motor(s), then figure out which switch or switches got triggered and do something about it. Remember that you need to debounce the switches. You can do that in hardware with a simple RC filter (see here). You can also do the debouncing in software as shown. Note that the BS2px can configure its input pins to be Schmitt triggers and to have built-in pullup resistors that can make it very simple to debounce switches using just a capacitor (see CONFIGPIN here).