Hi.
I'm programming proffesionally for a couple of years now but every now and then I run in to the following issue of which I'm not sure I'm solving it correctly, or at least in the best way.
I have to trigger a vision camera once every machine cycle, the trigger position changes per production run and can be set within the whole machine cycle. To make adjustments easy for the machine operator I'm using an encoder.
The pulse counter counts up to 100 and is reset by the encoder's Z pulse.
The trigger is set when the pulse counter reaches a value that is set once per production run by the operator.
This way the vision system will take a photo at the required position within the machine cycle.
I use the following (simplified code)
This way there are 10 pulses to evaluate the trigger statement so it can not be missed falling in between scans. (scan time being about 8ms)
The problem with this method is that if the Trigger value is set at, for example, encoder_PV 98 (again, out of 100) then there are only 2 pulses left to evaluate the trigger statement before the pulse counter resets to zero. This can be a problem, since I want to make it as user friendly as possible.
Ofcourse I can put in a whole bunch of IF statements and use a different statement for when the trigger value is set >90 but I feel there must be a better way.
Thanks in advance for the input
Kind regards,
Andy
I'm programming proffesionally for a couple of years now but every now and then I run in to the following issue of which I'm not sure I'm solving it correctly, or at least in the best way.
I have to trigger a vision camera once every machine cycle, the trigger position changes per production run and can be set within the whole machine cycle. To make adjustments easy for the machine operator I'm using an encoder.
The pulse counter counts up to 100 and is reset by the encoder's Z pulse.
The trigger is set when the pulse counter reaches a value that is set once per production run by the operator.
This way the vision system will take a photo at the required position within the machine cycle.
I use the following (simplified code)
Code:
[COLOR="SeaGreen"](*Set current encoder value to selected trigger variable*)[/COLOR]
[COLOR="Blue"]IF[/COLOR] Set_mode [COLOR="blue"]AND[/COLOR] Set_pb_oneshot [COLOR="blue"]THEN[/COLOR]
Trigger_val:= HS_cntrPV;
Set_mode:= [COLOR="blue"]FALSE[/COLOR];
[COLOR="blue"]END_IF[/COLOR];
[COLOR="SeaGreen"](*Trigger out*)[/COLOR]
[COLOR="blue"]IF[/COLOR] HS_cntrPV >=Trigger_val [COLOR="blue"]AND[/COLOR] HS_cntrPV <(Trigger_val +10)THEN
Trigger:= [COLOR="blue"]TRUE[/COLOR];
[COLOR="blue"]ELSE[/COLOR] Trigger:=[COLOR="blue"]FALSE[/COLOR];
[COLOR="blue"]END_IF[/COLOR];
This way there are 10 pulses to evaluate the trigger statement so it can not be missed falling in between scans. (scan time being about 8ms)
The problem with this method is that if the Trigger value is set at, for example, encoder_PV 98 (again, out of 100) then there are only 2 pulses left to evaluate the trigger statement before the pulse counter resets to zero. This can be a problem, since I want to make it as user friendly as possible.
Ofcourse I can put in a whole bunch of IF statements and use a different statement for when the trigger value is set >90 but I feel there must be a better way.
Thanks in advance for the input
Kind regards,
Andy