Microcontroller to trip sensors with precise timings.
Moderator: Benj
Microcontroller to trip sensors with precise timings.
Hi,
I’m new here and a beginner to programming microcontrollers. I’ve been told that Flowcode is perfect for what I’m trying to achieve, and I fully intend on purchasing it, but for now I want to see if what I want to achieve is possible, this is going to be a fairly longwinded first-post, so bear with me haha! Also, I realise that I should probably pay to have this work done – however at the moment I can’t afford it, and I’d really like to learn to use Flowcode as well
I am trying to trip a couple of transmissive photo-interrupter sensors in a printer, to prevent the need for temperamental, mechanical components which need careful timing setups.
I hope that I explain what I’m trying to achieve well, however I’m unfamiliar with the workings, and programing of micro controllers – I have written two versions of what I’m trying to achieve, one ‘code’ version, and one in plain English.
Firstly though, in the original machine, a motor would usually spin a cog which would ‘interrupt’ the photo interrupter, whilst at the same time pushing a piece of paper through the machine, to trip another photointerrupter. I would like to programmatically replicate this process, thus removing the motors, and photointerrupters.
- Let ‘Port A’ be an input port on the microcontroller, which would have the 4.5 voltage motor wires connected to it.
- Let ‘Port B’ be an output port, which would replicate the voltage that the first photointerrupter would ‘give off’ to the motherboard of the printer.
- Let ‘Port C’ be an output port on the microcontroller, which replicates the second photointerrupter, and the voltage it gives to the motherboard of the printer.
- Let ‘process’ be a variable, which has two states, ‘initiated’ which means that the ‘Port A’ is receiving 4.5 volts, and as a result, the photointerrupters are tripped in order. Also the state of ‘ready’ means that it is not receiving 4.5v – this is the initial state. ‘Process’ is to be changed from ‘initiated’, to ‘ready’ when a hall sensor is tripped.
So, here is how I would like the microcontroller to work:
if (Port A voltage = 4.5v){
AND
if ('process' = 'initiated'){
do nothing (because its already happening).
}
else if ('process' = 'ready'){
Wait 1.25 seconds
then
set Port B voltage = >2.4v
then
wait 1.25 seconds
then
set Port C voltage = >2.4v
then
'process' = 'initiated'
}
}
else{
set Port B voltage = <0.4v (this is the ‘default voltage’ which the printer registers as ‘there is no paper’)
set Port C voltage = <0.4v
}
if (hall sensor passes magnet){
'process' = 'ready' (the ‘process’ should only be set to ‘ready’ when this happens – not just when ‘Port A’ stops receiving 4.5v)
set Port B voltage = <0.4v
set Port C voltage = <0.4v
}
So:
If 'port A', is sent a signal of 4.5 volts (which it will keep on receiving because its a motor signal), then check if its already been received, and if it has, then do nothing because the whole process is already taking place, but if it hasn't then, wait 1.25 seconds, and set the voltage of port B to 2.4 volts then wait another 1.25 seconds and set the voltage of Port C to 2.4 volts, and also set the variable 'process' to 'initiated', because the process is happening. If NONE of this is happening, ie there was no initiation from port A, then keep ports B and C at 0.4v – this should also be the ‘initial’ voltage of the two ports. Then ONLY set the variable ‘process’ to ‘ready’ (from ‘initiated’) when a hall sensor passes a magnet – upon doing this the microcontroller should also set ports B and C to 0.4v.
I hope that makes sense,
Id be really grateful if anyone could tell me what type of microcontroller I would need, and how would I how would I go about doing it?
Many thanks
Harry.
I’m new here and a beginner to programming microcontrollers. I’ve been told that Flowcode is perfect for what I’m trying to achieve, and I fully intend on purchasing it, but for now I want to see if what I want to achieve is possible, this is going to be a fairly longwinded first-post, so bear with me haha! Also, I realise that I should probably pay to have this work done – however at the moment I can’t afford it, and I’d really like to learn to use Flowcode as well
I am trying to trip a couple of transmissive photo-interrupter sensors in a printer, to prevent the need for temperamental, mechanical components which need careful timing setups.
I hope that I explain what I’m trying to achieve well, however I’m unfamiliar with the workings, and programing of micro controllers – I have written two versions of what I’m trying to achieve, one ‘code’ version, and one in plain English.
Firstly though, in the original machine, a motor would usually spin a cog which would ‘interrupt’ the photo interrupter, whilst at the same time pushing a piece of paper through the machine, to trip another photointerrupter. I would like to programmatically replicate this process, thus removing the motors, and photointerrupters.
- Let ‘Port A’ be an input port on the microcontroller, which would have the 4.5 voltage motor wires connected to it.
- Let ‘Port B’ be an output port, which would replicate the voltage that the first photointerrupter would ‘give off’ to the motherboard of the printer.
- Let ‘Port C’ be an output port on the microcontroller, which replicates the second photointerrupter, and the voltage it gives to the motherboard of the printer.
- Let ‘process’ be a variable, which has two states, ‘initiated’ which means that the ‘Port A’ is receiving 4.5 volts, and as a result, the photointerrupters are tripped in order. Also the state of ‘ready’ means that it is not receiving 4.5v – this is the initial state. ‘Process’ is to be changed from ‘initiated’, to ‘ready’ when a hall sensor is tripped.
So, here is how I would like the microcontroller to work:
if (Port A voltage = 4.5v){
AND
if ('process' = 'initiated'){
do nothing (because its already happening).
}
else if ('process' = 'ready'){
Wait 1.25 seconds
then
set Port B voltage = >2.4v
then
wait 1.25 seconds
then
set Port C voltage = >2.4v
then
'process' = 'initiated'
}
}
else{
set Port B voltage = <0.4v (this is the ‘default voltage’ which the printer registers as ‘there is no paper’)
set Port C voltage = <0.4v
}
if (hall sensor passes magnet){
'process' = 'ready' (the ‘process’ should only be set to ‘ready’ when this happens – not just when ‘Port A’ stops receiving 4.5v)
set Port B voltage = <0.4v
set Port C voltage = <0.4v
}
So:
If 'port A', is sent a signal of 4.5 volts (which it will keep on receiving because its a motor signal), then check if its already been received, and if it has, then do nothing because the whole process is already taking place, but if it hasn't then, wait 1.25 seconds, and set the voltage of port B to 2.4 volts then wait another 1.25 seconds and set the voltage of Port C to 2.4 volts, and also set the variable 'process' to 'initiated', because the process is happening. If NONE of this is happening, ie there was no initiation from port A, then keep ports B and C at 0.4v – this should also be the ‘initial’ voltage of the two ports. Then ONLY set the variable ‘process’ to ‘ready’ (from ‘initiated’) when a hall sensor passes a magnet – upon doing this the microcontroller should also set ports B and C to 0.4v.
I hope that makes sense,
Id be really grateful if anyone could tell me what type of microcontroller I would need, and how would I how would I go about doing it?
Many thanks
Harry.
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
- Contact:
Re: Microcontroller to trip sensors with precise timings.
This might get you started in your project. Press play to see if the logic is right. You can click on the switch and watch what happens. Adjust to suit your needs. The circuit design is up to you to get the exact voltages.
There is a very nice "Learning Center" on the website.
There is a very nice "Learning Center" on the website.
- Attachments
-
- trip_sensors.fcf
- trip sensors
- (11.5 KiB) Downloaded 271 times
Re: Microcontroller to trip sensors with precise timings.
Wow Many thanks for doing this! I have a few questions:Kenrix2 wrote:This might get you started in your project. Press play to see if the logic is right. You can click on the switch and watch what happens. Adjust to suit your needs. The circuit design is up to you to get the exact voltages.
There is a very nice "Learning Center" on the website.
- Where can I see/alter the voltage outputs of the microcontroller?
- Would I need a special microcontroller to actually be able to output voltage?
Also, I think that part of it is wrong in the sense that it will immediately switch back to outputting 0.4v at ports B and C regardless of the state of port D. Please see the attached image in which I have tried to further explain what I would like to happen.
Again, thank you so much for helping me out with this,
Best regards
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Microcontroller to trip sensors with precise timings.
Hi Harry,
The normal output from a microcontroller is at ttl logic level. i.e with 5V microcontroller its either 0V(logic 0) or 5V (logic 1)
If microcontroller has an ADC converter, then i/p can vary from 0V to 5V which loads a value from 0 to 255 (if ReadAsByte)
or 0 to 1023 if ReadAsInt and you have an int variable.
On way of producing a variable voltage output is to feed PWM (Pulse Width Modulation) into a low pass RC filter (Resistor and cap) using PWM component but the accuracy will not be that good.
Or a more accurate method is to use a separate D to A (Digital to Analogue) converter.
As for the waiting a timer interrupt can be used.
I could put something together for you, if I get a chance tonight?
Martin
The normal output from a microcontroller is at ttl logic level. i.e with 5V microcontroller its either 0V(logic 0) or 5V (logic 1)
If microcontroller has an ADC converter, then i/p can vary from 0V to 5V which loads a value from 0 to 255 (if ReadAsByte)
or 0 to 1023 if ReadAsInt and you have an int variable.
On way of producing a variable voltage output is to feed PWM (Pulse Width Modulation) into a low pass RC filter (Resistor and cap) using PWM component but the accuracy will not be that good.
Or a more accurate method is to use a separate D to A (Digital to Analogue) converter.
As for the waiting a timer interrupt can be used.
I could put something together for you, if I get a chance tonight?
Martin
Martin
Re: Microcontroller to trip sensors with precise timings.
Martin, thanks for the reply,medelec35 wrote:Hi Harry,
The normal output from a microcontroller is at logic level. i.e with 5V microcontroller its either 0V(logic 0) or 5V (logic 1)
If microcontroller has an ADC converter, then i/p can vary from 0V to 5V which loads a value from 0 to 255 (if ReadAsByte)
or 0 to 1023 if ReadAsInt and you have an int variable.
On way of producing a variable voltage output is to feed PWM (Pulse Width Modulation) into a low pass RC filter (Resistor and cap) using PWM component but the accuracy will not be that good.
Or a more accurate method is to use a separate D to A (Digital to Analogue) converter.
As for the waiting a timer interrupt can be used.
I could put something together for you, if I get a chance tonight?
Martin
Regarding the accuracy of the analogue (i think) signal that was originally sent - it was read as 'Greater than 2.4v' or 'less than 0.4v' - so as long as the voltage output is >2.4v or <0.4v (depending on the situation), it should be alright - extreme precision is not really necessary.
However, if its easier to implement a digital to analogue converter, then I think that would be the better path
Could you also recommend a microcontroller to suit my needs?
Many thanks - I really appreciate your help,
Harry
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Microcontroller to trip sensors with precise timings.
haza100 wrote:Regarding the accuracy of the analogue (i think) signal that was originally sent - it was read as 'Greater than 2.4v' or 'less than 0.4v' - so as long as the voltage output is >2.4v or <0.4v (depending on the situation), it should be alright - extreme precision is not really necessary.
No its not easier. Much more simple to implement RC filterhaza100 wrote:if its easier to implement a digital to analogue converter, then I think that would be the better path
it's a just a resistor connected to a PWM output.
An electrolytic capacitor connected across the other end of resistor and ground will be more than adequate.
For determining value of components take a look here:
http://sim.okawa-denshi.jp/en/CRlowkeisan.htm
.haza100 wrote:Could you also recommend a microcontroller to suit my needs?
That would depend on a few factors.
1) needs to have a least 1 CCP PWM (Capture/Compare/Pulse Width Modulation)
2) What other Inputs and outputs are required, e,g if LCD is connected for a dispaly or not.
3) Maximum speed of operation ie how many MIP (million instructions per second) = clock frequency/4
4) What other functions are required. E.g can, spi etc.
5) How complex or how much Room program is going to take up.
I would recommend going to:
http://www.microchip.com/ParamChartSear ... nchID=1005
Or
http://www.microchip.com/maps/microcontroller.aspx
For the PIC micro controllers you will need to select 8 bit.
Prefix will be PIC16F or PIC18F.
Before ordering any microcontrollers, it would be best to create a rough flowchart first then compile to hex just to make sure there are nor compiling issues with selected component.
If your after a microcontroller with a few pins as possible (8 pin device) then 12F1840 is ideal
Another way on cutting down on pins and component count is to use the microcontroller's internal oscillator (e.g taking 12F1840 as an example you can select speeds from 31KHz to 32MHz) instead on external crystal and two matching caps or resonator.
Martin
Re: Microcontroller to trip sensors with precise timings.
Ok, I'm a little bit lostmedelec35 wrote:haza100 wrote:Regarding the accuracy of the analogue (i think) signal that was originally sent - it was read as 'Greater than 2.4v' or 'less than 0.4v' - so as long as the voltage output is >2.4v or <0.4v (depending on the situation), it should be alright - extreme precision is not really necessary.No its not easier. Much more simple to implement RC filterhaza100 wrote:if its easier to implement a digital to analogue converter, then I think that would be the better path
it's a just a resistor connected to a PWM output.
An electrolytic capacitor connected across the other end of resistor and ground will be more than adequate.
For determining value of components take a look here:
http://sim.okawa-denshi.jp/en/CRlowkeisan.htm
.haza100 wrote:Could you also recommend a microcontroller to suit my needs?
That would depend on a few factors.
1) needs to have a least 1 CCP PWM (Capture/Compare/Pulse Width Modulation)
2) What other Inputs and outputs are required, e,g if LCD is connected for a dispaly or not.
3) Maximum speed of operation ie how many MIP (million instructions per second) = clock frequency/4
4) What other functions are required. E.g can, spi etc.
5) How complex or how much Room program is going to take up.
I would recommend going to:
http://www.microchip.com/ParamChartSear ... nchID=1005
Or
http://www.microchip.com/maps/microcontroller.aspx
For the PIC micro controllers you will need to select 8 bit.
Prefix will be PIC16F or PIC18F.
Before ordering any microcontrollers, it would be best to create a rough flowchart first then compile to hex just to make sure there are nor compiling issues with selected component.
If your after a microcontroller with a few pins as possible (8 pin device) then 12F1840 is ideal
Another way on cutting down on pins and component count is to use the microcontroller's internal oscillator (e.g taking 12F1840 as an example you can select speeds from 31KHz to 32MHz) instead on external crystal and two matching caps or resonator.
Correct me if I'm wrong - I should use 2 RC filters which will consist of capacitors, connected to the two the two PWM output ports at B and C. This will allow me to alter the voltage fairly accurately - ie, from <0.4v to >2.4v.
Also, will port D need to be pule width modulation 'enabled'?
As far as the microcontroller goes, I do not require an LCD or anything like the - just the set up in the above diagram for now. However I would like to have a few spare pins in order to set up a stepper motor 'backwards and forward' circuit as well (but this can be done much later on).
I'm unsure how much memory the program will take up, I need to actually learn how to create the flowcharts in Flowcode first - I think that the program 'Kenrix2' kindly make for me will help a lot, but isn't entirely correct. I shall try to learn how to use Flowcode beginning next week.
To clarify, I will need:
1. A microcontroller (with 3 PWM ports?)
2. A programmer chip to program the microcontroller
3. The actual program
4. Electrolytic capacitors (of what 'transfer function' value I do not know )
5. Resistors to go with the capacitors
Many thanks & kind regards,
Harry
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: Microcontroller to trip sensors with precise timings.
If the output voltages required are < 0.4V and > 2.4V I would just use the output of the controller buffered in some way to make sure the low signal stays below 0.4 V (PIC specify output low voltage < 0.6 V, not 0.4 V) The operating voltage defines the output high. It is at least operating voltage - 0.6 V (so for operating voltage of 3.3 volt that would be 2.7 V and for 5 volt it would be 4.4 V)Regarding the accuracy of the analogue (i think) signal that was originally sent - it was read as 'Greater than 2.4v' or 'less than 0.4v' - so as long as the voltage output is >2.4v or <0.4v (depending on the situation), it should be alright - extreme precision is not really necessary.
Using digital signals would be a lot easier.However, if its easier to implement a digital to analogue converter, then I think that would be the better path
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Microcontroller to trip sensors with precise timings.
Hi Harry,
Sorry for losing you a bit.
I have had a bit more thinking time on this.
I was taking a literal value of 2.4V, but if you stated >2.4 and <0.4 then just using a normal digital output ( 0V or 5V) will suffice which is what kersing was saying so I do agree with him.
So you won't need any PWM channels or resistors or caps for that. I was making it more complex than it needs to be.
As for servo:
Using servo component will only be available with the professional version of Flowcode and will require a microcontroller with 2 PPM outputs (Two ccp PWM channels are used to generate PWM Signal).
Alternatively you can generate PWM using a timer interrupt instead of 2 PWM channels. Plus professional version for that method is not required.
See:
http://www.matrixmultimedia.com/mmforum ... 13&#p30748
Sorry for losing you a bit.
I have had a bit more thinking time on this.
I was taking a literal value of 2.4V, but if you stated >2.4 and <0.4 then just using a normal digital output ( 0V or 5V) will suffice which is what kersing was saying so I do agree with him.
So you won't need any PWM channels or resistors or caps for that. I was making it more complex than it needs to be.
As for servo:
Using servo component will only be available with the professional version of Flowcode and will require a microcontroller with 2 PPM outputs (Two ccp PWM channels are used to generate PWM Signal).
Alternatively you can generate PWM using a timer interrupt instead of 2 PWM channels. Plus professional version for that method is not required.
See:
http://www.matrixmultimedia.com/mmforum ... 13&#p30748
Martin
Re: Microcontroller to trip sensors with precise timings.
OK, great - I shall forget about the PWM and use digital output for now?
I have had a go at writing the program - I have no idea how to actually output either 0v or 5v, nor do I know how to record the input. I hope you can see what I'm trying to achieve though, to assist in making it clear I have also attached a text document which is more understandable to me
Many thanks!
Harry
I have had a go at writing the program - I have no idea how to actually output either 0v or 5v, nor do I know how to record the input. I hope you can see what I'm trying to achieve though, to assist in making it clear I have also attached a text document which is more understandable to me
Many thanks!
Harry
- Attachments
-
- Microcontroller_basic.txt
- (703 Bytes) Downloaded 218 times
-
- Program Attempt 1.fcf_avr
- (12 KiB) Downloaded 254 times