??? 02/27/05 20:29 Read: times |
#88584 - its easy in software Responding to: ???'s previous message |
Following my well proved example code:
#include <reg51.h> sbit PHASE_A = P1^0; sbit PHASE_B = P1^1; int enc_delta; // -32768 ... 32767 void t0_interrupt( void ) interrupt 1 { static char enc_last; char i; i = 0; if( PHASE_A ) i = 1; if( PHASE_B ) i ^= 3; // convert gray to binary i -= enc_last; // difference new - last if( i & 1 ){ // bit 0 = value (1) enc_last += i; // store new as next last if( i & 2 ) // bit 1 = direction (+/-) enc_delta--; else enc_delta++; } } // 45 cycle void main( void ) { TMOD = 0x02; // Mode 2: reload TH0 = -111; // 111 cylce (30kHz at XTAL = 20MHz) TR0 = 1; for(;;){ P2 = enc_delta; } } Signal oscillations only critical on using external interrupts, but not on this solution with the timer interrupt ! Since there is absolutely no way to trigger the interrupt faster as expected and thus no way for false counting. False counting can only occur, if the rotation speed was faster as the sample rate. E.g. with an AT89C51RD2 a timer interrupt of about 30kHz is possible very easy, which can count up to 15000 pulse per second. Thus only for very high speed external hardware was needed. Peter |
Topic | Author | Date |
Digital position encoder | 01/01/70 00:00 | |
Dont do this. | 01/01/70 00:00 | |
Signals are not connected directly | 01/01/70 00:00 | |
Is assembly ok? | 01/01/70 00:00 | |
For Mehdi | 01/01/70 00:00 | |
its easy in software | 01/01/70 00:00 | |
but | 01/01/70 00:00 | |
same resolution | 01/01/70 00:00 | |
But...what if ? | 01/01/70 00:00 | |
So what is the solution? | 01/01/70 00:00 | |
absolutely no problem | 01/01/70 00:00 | |
Thank you | 01/01/70 00:00 | |
PLEASE not again | 01/01/70 00:00 | |
Sorry | 01/01/70 00:00 | |
list.hw.cz | 01/01/70 00:00 | |
thank you | 01/01/70 00:00 | |
Re: PLEASE not again | 01/01/70 00:00 | |
Re frequency | 01/01/70 00:00 | |
So what frequency do we sample at? | 01/01/70 00:00 | |
I try to explain Peter's idea again | 01/01/70 00:00 | |
We know it ! | 01/01/70 00:00 | |
Nothing ??? | 01/01/70 00:00 | |
it takes time | 01/01/70 00:00 | |
Code doesn't function | 01/01/70 00:00 | |
reverse direction ! | 01/01/70 00:00 | |
This is not a problem | 01/01/70 00:00 | |
incorrect operation? | 01/01/70 00:00 | |
right connection ? | 01/01/70 00:00 | |
I dunno | 01/01/70 00:00 | |
Now... | 01/01/70 00:00 | |
check the sample condition ! | 01/01/70 00:00 | |
clarify | 01/01/70 00:00 | |
@Erik | 01/01/70 00:00 | |
@Peter | 01/01/70 00:00 | |
Grey code | 01/01/70 00:00 | |
Grey code more | 01/01/70 00:00 | |
Grey INCREMENTAL ? | 01/01/70 00:00 | |
I guess 98 | 01/01/70 00:00 | |
Gray code | 01/01/70 00:00 | |
Not a gray code | 01/01/70 00:00 | |
Grey | 01/01/70 00:00 | |
Yes of course its Grey code | 01/01/70 00:00 | |
Absolute Vs Incremental | 01/01/70 00:00 | |
So now... | 01/01/70 00:00 | |
Yes it can but only... | 01/01/70 00:00 | |
Peter is right! | 01/01/70 00:00 | |
Lover not a fighter :-) | 01/01/70 00:00 | |
Lover of software | 01/01/70 00:00 | |
steps lost or not | 01/01/70 00:00 | |
Determining direction | 01/01/70 00:00 | |
Its not Grey, its Gray !![]() | 01/01/70 00:00 |