Hi folks, Im having great trouble in pic programming and hope someone can help me.Im designing a motor controller circuit using pic 16f877a. Iv got a single ended quadrature encoder (It has 5 outputs - a channel, b channel, z channel, 5v, ground). Iv finished the coding for the motor controller part in mikroc. NowI dont know how to do the programming for this encoder. Have to get the feedback(Pulses) from this encoder compare it with the expected pulses and make adjestments. Can someone show me a sample coding for this in mikroc. Iv googled this for last several days and read so many articles but I still couldnt do the coding.
This is the coding in mikroc iv written so far. This works. If possible can someone integrate the encoder components in this
void m1(int forward) { if(forward) { PORTC.F4=1; PORTC.F5=0; } else { PORTC.F4=0; PORTC.F5=1; } }
void m2(int forward) { if(forward) { PORTC.F6=1; PORTC.F7=0; } else { PORTC.F6=0; PORTC.F7=1; } }
void setup_timer0() //for encoder 1 { //should be called after configuring the ports(coresponding tris) TRISA.F4=1; //encoder signal input bit OPTION_REG=0x80; OPTION_REG.T0CS=1; //timer0 counter mode }
void setup_timer1() { TRISC.F0=1;//encorder signal input bit T1CON=0;//configure prescale of timer1 T1CON.TMR1CS=1;//To set RC0 as input source for timer1 T1CON.T1OSCEN=0;//internal oscillator disabled T1CON.T1SYNC=1;//disable synchronization T1CON.TMR1ON=1;//start timer1 } void main() {
PORTC=0; TRISC=0; setup_timer0(); setup_timer1(); PWM1_INIT(5000);//Both pwm generators share one pulse width value. So one
//initializing is enough PWM1_change_duty(80); pwm2_change_duty(200); pwm1_start(); pwm2_start(); m1(1); //m1 forward m2(0); //m2 backward
while(1) { delay_ms(1000); PORTB=TMR0; //Encorder1 value PORTD=TMR1L; //Encorder2 value } }
--------------------------------------- This message was sent using the comp.arch.embedded web interface on