Steve,
Yup, restarted pc many times. LOL. I would really like to know what the problem is. I guess I will have to look into it further.
You said "Look at the code in the Interrupt Handler. Put this in your main loop"
Did you mean to compile just the code you listed or to add it to one of the others? If you meant by itself then it compiled just fine.
I tried it out and had some strange readings. It starts with Rot1:00 and Rot2:35. When I rotate the encoders nothing happens.
To test and see if it was the encoder or the program, I unpluged the a & b chanels from encoder 1 and alternately touched them to ground and the numbers changed. This makes me think something is wrong in the encoder circuit. I played arround with different values on the resistors to no avail. The encoders output a positive voltage between ~1.85 and 5 and I have 4.7K resistors pulled to ground on each channel.
I did notice if I was under a bright light and held the encoders at just the right angle the numbers changed but they were jumping arround and not going 1.2.3.4~.
You said "Look at the code in the Interrupt Handler. Put this in your main loop"
Did you mean to compile just the code you listed or to add it to one of the others? If you meant by itself then it compiled just fine.
Just use the "new code" in the last post by itself (I did the moving for you).
It starts with Rot1:00 and Rot2:35
Add something like this just below the variable declarations to give an initial starting value.
RotEnc1_val = 0
RotEnc2_val = 0
OK. Do you have the datasheet for the encoders? I assumed (always bad) that they where mechanical encoders, similar to the one shown here. Hook-up as per the nice diagram.
If they are not mechanical encoders, then they are optical. If so, they will have a Vcc, GND, ChA, and ChB. Also, no pull-ups (or downs) required.
At least it looks like the code is working. More info please.
Ok, I did just use the code by itself and I understand setting the variables to =0. Off to a good start
The encoders are optical with no data sheet since I pulled them out of a ball mouse. There is an emitter, wheel with 36 slots, and reciever for each encoder. They are in the same mounting positions as when the mouse was a mouse. I just chopped off the pc board behind them and attached my wires. The emitters only have 2 pins, +5v and ground. The recievers have 3 pins, A,B, & +5v. I know this because I traced them back on the mouse board before cutting. I also checked another mouse to be sure. (I bought 4 of them to play with).
With my original code (the really simple one a few posts back) nothing happened until I put in the resistors to ground. Thats the only reason they are in the circuit. The read out on the lcd also displayed channel A and B status and I could see 00 01 11 10 00 when rotated very slowly.
I did try your code without the resistors and it didnt make any difference.
I agree with you when you say we need to walk before we run. So I checked the outputs of the encoders with a logic probe. I am getting a high/low pulse out of each of the channels when they are rotated.
So I checked the outputs of the encoders with a logic probe. I am getting a high/low pulse out of each of the channels when they are rotated.
What voltage do they output on the channels? I haven't hacked any mouse encoders, so a google on that (or someone else on this forum who has could chime in) could help make sure the hardware portion is working properly.
I do know the code is working now. I scared up 2 mech encoders, and hooked them up to an 18F4620 I have. Using the internal pull-ups on port B, worked without a hitch. I see no reason it wouldn't work on the 16F628.
The encoders output a positive voltage between ~1.85 and 5 and I have 4.7K resistors pulled to ground on each channel.
So it's never 0V? @1.85 you're probably sometimes in-between Low and High logic Level. You may need to 'filter' it a little bit to avoid oddity.
1.Use the internal voltage comparator, set the threshold and use their interrupt to increment the counter.
OR
2.try something like...
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1067&stc=1&d=115794620 6">
maybe one diode could be enough... maybe not
HTH
Last edited by mister_e; - 11th September 2006 at 04:54.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
I got it working! Sort of. I played arround with different value resistors and some diodes as sugested by mister_e and ended up with 30K resistors. Also seams my pic16f628-20p dosnt have a very accurate osc in it. I hooked up an external resonator and it works at 20mhz using Steve's slightly modified code from post #12. Thanks Steve!
The only thing now is it sometimes skips or looses count. Either the pic running at 20mhz cant keep up or the infrared red rx cant keep up. These encoders came out of a PS2 computer mouse. The ones that turn off the ball.
I got it working! Sort of. I played arround with different value resistors and some diodes as sugested by mister_e and ended up with 30K resistors. Also seams my pic16f628-20p dosnt have a very accurate osc in it. I hooked up an external resonator and it works at 20mhz using Steve's slightly modified code from post #12. Thanks Steve!
The only thing now is it sometimes skips or looses count. Either the pic running at 20mhz cant keep up or the infrared red rx cant keep up. These encoders came out of a PS2 computer mouse. The ones that turn off the ball.
Any ideas guys?
Thanks!
Smitty
Now your walking, time to RUN!! Go back to post #6 and give the interrupts a try. With the optical encoders and interrupts, you should have not any switch bounce, and you should also not have any "skips". Well, if it turns faster than the interrupts can process the inputs, you can have some skips, but the nice thing about the interrupts is that the updates to the rotarty encoders count will not "wait" on the LCD output to finish.
Give it a shot,
Steve
Last edited by SteveB; - 17th September 2006 at 02:01.
I have tried microcode studio and microchips mpasm. I think I might have a problem with mpasm talking to pbp or I installed something wrong. I was going to unistall everything and try again but my pbp is on a floppy and I found out my floppy drive (havent used it in years! LOL) is bad. I ordered a new one and will have it by the end of the week. Its amazing how cheap a floppy drive is these days. I also ordered my first Oscilloscope! Its only a BK precision 2120b 30mhz dual channel but it should be able to handle everything I do.
Bookmarks