I am making a coiling machine and will be passing the wiring into a small pulley. The pulley will have four sections, two white and two black. The sensor will be reading the encoder , there will be small led lighting the encoder from behind.
Therefore the speed I do not know, and it is not important, it will be going in one direction. I will be counting four changes for one revolution.
Here is a program I just wrote, have not tried it yet,
'Get initil value
ADCON0.2 = 1 'Start Conversion
ADCIN 1, OldOutput_Pot 'analog pin 1 (RA1) get the 8 bit result
pause 50
if OldOutput_Pot > 127 then
OldOutput_Pot =1
endif
if OldOutput_Pot < 128 then
OldOutput_Pot =0
endif
Mainloop:
ADCON0.2 = 1 'Start Conversion
ADCIN 1, Output_Pot 'analog pin 1 (RA1) get the 8 bit result
pause 50
'Calculate the distance
if Output_Pot > 127 then
Output_Pot =1
endif
if Output_Pot < 128 then
Output_Pot =0
endif
if OldOutput_Pot == Output_Pot then
goto Mainloop
endif
if OldOutput_Pot != Output_Pot then
counter = counter +1 'If oldOutput_pot is different then Output_pot
OldOutput_Pot = Output_Pot
if counter =4 then
Revolution = Revolution + 1
counter =0
endif
endif
lcdout $FE,1, "Counter:",dec counter
lcdout $FE,$C0, "Revolution:",dec Revolution
pause 150
GOTO Mainloop
end







Bookmarks