Sorry for my lack of detail, this is going to be a fairly long winded 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 how to do it myself 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 (ie, they need to be tripped at precisely the right time - almost impossible manually).
I hope that I explain what I’m trying to achieve well, however I’m unfamiliar with the workings, and programming of micro controllers/electronics, therefore 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.
'Code' version:
- 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 as detailed below. Also the state of ‘ready’ means that it is not receiving 4.5v – this is the initial state, ie this is what should happen when the machine/microcontroller turns on initially. ‘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 – let me know if you need anymore details,
Many thanks - I am genuinely really grateful for all the help,
Harry.