I'm working on a feeding pump that has some crude positioning needs. It does this by using a photo-interrupter, 30 slots per turn. I have done robust readings using interrupts and an A_Q_B encoder using the phasing transitions to prevent false counts.
Has anyone done decoding with a simple interrupter? I tried interrupt on CHANGE and storing the HIGH state, watching the transition to low, then doing the same on the transition to high. Doesn't seem to be error proof though.
// ************************ ReadFineEnc **********
void ReadFineEnc(void){
if(!digitalRead(FINE_ENCDR)) // if we got an interrupt
FineHiToLow=(!digitalRead(FINE_ENCDR)); // and we went low, store it
if(digitalRead(FINE_ENCDR)) // if we got an interrupt
FineLowToHi=(digitalRead(FINE_ENCDR)); // and we went high store it
if(FineLowToHi==FineHiToLow) FineCount ++; // bump counter only on match
}//------------------END ReadFineEnc ISR ----------------------------
Do you need to read direction and/or distance or only speed (tachometer)?
Also, what do you mean by "positioning" a pump?
This is an Enteral Feeding Pump for someone (my son) that can't accept normal foods. It feeds formula and then allows a "flush" cycle to administer water. It is the internal workings of a Kangaroo Joey Pump.
There is a Valve that has to shift positions to go between the two "bags", water and formula. It does this by reversing the drive motor a particular distance to align the ports in the valve. The positioning is fairly straightforward. You can see the two slotted wheels. The wheel with 2 slots is connected directly to the valve shaft, so to load and unload a bag "set", you have to stop with that encoder at "home". To index the valve to either FEED or FLUSH positions, you have to count out pulses on the 30 slot wheel from home. The gearing is such that it's 1,600 counts between "home" pulses. You can only go one direction due to the mechanics and the clutch. Empirical testing puts the FEED position at 1400 and the FLUSH at 2400. Due to PWM Control from my ESP32, I can run fairly slowly to the position and hit it within about 10 counts. I could probably hit it "dead on" if I just subtract 10 counts from desired destination.
I'm not confident that I'm not getting some bad counts though, thus the reason for my question.
Thanks.
Bob M.