
Originally Posted by
lerameur
Jerson,
this is very simple encoder. I have light to voltage chip, reading the encoder, the encoder is divided into 4 sections, 2 white and two black, read black show ADC below 127 and white ADC above 127.
ken
Precisely. Depending on the way you've wired the sensor, you could see a logic 1 for black or a logic 0 for black. You can just read the digital input after configuring the pins tris register for input mode. Easier than reading the ADC and all its associated overhead. This overhead would eventually cause you to lose counts. I will still prod you into looking at the interrupt option.
What you've done will work, but at speeds relatively slower than the speed at which you read the ADC.
A simple routine could have an interrupt set up possibly on RB0. And the interrupt code would do something as simple as this
Code:
CounterISR:
dummyread = PortB ' clear the cause of the interrupt
Counter = Counter+1
return ' from interrupt
This code will ensure that you catch each and every pulse that comes its way irrespective of the Pauses in your mainline code.
This code is just a guide, please dont hold me to it.
JF
Bookmarks