ismbn
Full Member level 3
- Joined
- Feb 11, 2012
- Messages
- 160
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,308
- Location
- Mumbai. india
- Activity points
- 2,444
hello.
I working on a motor in which there is a rotary encoder is connected, with 2 output channels i.e. A & B. this output channels are giving the square wave with 90° Phase shift.
In my application i have to detect the direction of the motor and count the pulses done, & send to PC via UART.
The codding till now i have done is here. but the thing is its working fine in proteus. but when i am connecting the hardware... its not responding properly.
some time its giving "clock wise" and "anti clock " correctly, but most of the time it doesn't sending anything.
the UART communication header is working OK.. its tested...
What do you think where is the problem... I think there is some problem in the coding...
i think i am not nicely checking the direction on the motor...
Please guide me.
Thanks Regards
Ismail
I working on a motor in which there is a rotary encoder is connected, with 2 output channels i.e. A & B. this output channels are giving the square wave with 90° Phase shift.
In my application i have to detect the direction of the motor and count the pulses done, & send to PC via UART.
The codding till now i have done is here. but the thing is its working fine in proteus. but when i am connecting the hardware... its not responding properly.
some time its giving "clock wise" and "anti clock " correctly, but most of the time it doesn't sending anything.
the UART communication header is working OK.. its tested...
Code:
/*
/*
* Motor_incoder2_test.c
*
* Created: 11/29/2012 12:43:17 PM
* Author: Ismail
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <dbits/usart32.h>
#include <util/delay.h>
volatile unsigned long x=1000;
char z=0;
void go_intr()
{
MCUCR=1;
GICR |=(1<<INT0);//|(1<<INT0);
_delay_ms(10);
sei();
}
int main(void)
{
uart_init(103,0);
sbit (DDRD,7);
go_intr();
sei();
print('a');
while(1)
{
if (z==1)
{
x++;
print(x);
}
if(z==2)
{
x--;
print(x);
}
if(z==1)
{
print_str(" clock wise ");
}
if(z==2)
{
print_str(" anti clock wise ");
}
}
}
ISR(INT0_vect)
{
while(bit_is_clear(PIND,2) && bit_is_clear(PIND,3));;;
// if(bit_is_set(PINB,0) && bit_is_clear(PINB,1) && z==0)
if(bit_is_clear(PIND,2) && (z==0))
{
if (bit_is_set(PIND,3))
{
z=1;
}
}
if(bit_is_clear(PIND,3) && (z==0))
{
if (bit_is_set(PIND,2))
{
z=2;
}
}
}
What do you think where is the problem... I think there is some problem in the coding...
i think i am not nicely checking the direction on the motor...
Please guide me.
Thanks Regards
Ismail