PDA

View Full Version : Slow Opto Encoder With Interrupts



crhomberg
- 22nd October 2007, 21:35
Hi all,

I am making a trolly which is moved along a track with a belt. I made an opto encoder with a metal disk and the components from a ball mouse.
I read the other thread on opto encoders and have it working great when using it alone in itīs own little loop. The problem is I need to do many other things in the mean time.
The encoder is only 10 pulses per revolution and my motor at max goes at 10 RPM (it has a gearbox)

I am trying to use Darrel Taylors great instant interrupts with my 16F877A. I have used them successfully many times but I am definately doing something wrong this time.
It works only at very low speed (ie 10Hz) at 50Hz it just show A and B being permanently on.

Can anyone guide me to what my error is. I have attached both my codes in txt format, the working one without INTs and the INT one that does funny things?

Regards

Chris

Darrel Taylor
- 23rd October 2007, 04:03
Hi Chris,

It'll probably work better without the serout2 in the interrupt handler.

In the first version (without interrupts), there was an attempt to limit the number of times that SEROUT2 was executed. (IF NUMBER<>COUNTER)

But in the interrupt version, that disappeared, and it sends the result after every interrupt.
Using up way too much time. (even at 38400 baud)

Any time consuming Serial outputs should be done in the Main Loop, instead of the handler.
<br>

crhomberg
- 24th October 2007, 15:04
Thanks Darrel, all works fine now, really your interrupts make hardware interrupts so much easer for those of us who are not good with assembler.

Regards

Chris R.