Author Topic: ENCODER PROGRAMMING HELP!  (Read 3079 times)

0 Members and 1 Guest are viewing this topic.

Offline bubbletea7Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
ENCODER PROGRAMMING HELP!
« on: February 24, 2011, 09:36:49 AM »
HELLO there,

i need a help regarding my programming..

i am doing my project of dc motor controller for positioning application..

the programming already done to my PIC..

can anyone help me to define the coding below for me..


  count=0;                 //count=0
   while(1)                 //check encoder signal
   {
    if(!signal_A && !signal_B)         //when signal 00
    {
     count=count+5;                    //count+5
     while(!signal_A && !signal_B);    //wait until signal changes
    }
    else if(!signal_A && signal_B)     //when 01
    {
     count=count+5;
     while(!signal_A && signal_B);
    }
    else if(signal_A && !signal_B)     //when 10
    {
     count=count+5;
     while(signal_A && !signal_B);
    }
    else if(signal_A && signal_B)     //when 11
    {
     count=count+5;
     while(signal_A && signal_B);
    }
    inttostr(count,txt);             //convert count value to string
    lcd_out(2,1,"Now=");             //display now value at lcd
    if(txt[2]==' ')
    txt[2]='0';
    if(txt[3]==' ')
    txt[3]='0';
    if(txt[4]==' ')
    txt[4]='0';
    if(txt[5]==' ')
    txt[5]='0';
    if(txt[6]==' ')
    txt[6]='0';
    lcd_chr_cp(txt[2]);
    lcd_chr_cp(txt[3]);
    lcd_chr_cp(txt[4]);
    lcd_chr_cp(txt[5]);
    if(count==degree)              //if degree equal count then stop motor & break from loop
    break;
   }




how my motor read signal from encoder? and how the encoder running and function in my dc geared motor with encoder until it give the output?



Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: ENCODER PROGRAMMING HELP!
« Reply #1 on: February 24, 2011, 10:55:15 AM »
Which PIC?
Which encoder? link to data sheet?
Which motor driver?

Quote
how my motor read signal from encoder?
The motor does not read the encode! The motor turns the encoder and the PIC reads the encoder.

Quote
can anyone help me to define the coding below for me..
No, you define what you want the code to do. Then we can help you get the code to do that.

Hint:
 Connect the encoder outputs to the IOC (Interrupt on Change) PIC inputs (see PIC data sheet). Then in the IOC ISR read the PIC encoder inputs and pass the input values to the code that check the encoder states.

Offline bubbletea7Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
Re: ENCODER PROGRAMMING HELP!
« Reply #2 on: February 24, 2011, 11:33:13 AM »
Actually i am doing my project of dc motor controller for positioning application..

my friend helping me to do the programing of my project. i am using microcontroller PIC 16F877A. and motor driver is L293D..

but i have certain part that i cannot understand of the coding of the programming..

that are :::


while(1)                 //check encoder signal

   {
    if(!signal_A && !signal_B)         //when signal 00
    {
     count=count+5;                    //count+5
     while(!signal_A && !signal_B);    //wait until signal changes
    }
    else if(!signal_A && signal_B)     //when 01
    {
     count=count+5;
     while(!signal_A && signal_B);
    }
    else if(signal_A && !signal_B)     //when 10
    {
     count=count+5;
     while(signal_A && !signal_B);
    }
    else if(signal_A && signal_B)     //when 11
    {
     count=count+5;
     while(signal_A && signal_B);


how the program reads the signal from the encoder?

he said to me, he follow the data sheet of my dc geared motor with encoder..
here is the link of the datasheet..

http://www.cytron.com.my/viewProduct.php?pid=ABAkNRIhAysEJQAfDA06JNHNifmJggYfKfF8xCBY4hM=

but i just cannot understand how it read.. sorry, i am really confusing about this encoder signal..

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: ENCODER PROGRAMMING HELP!
« Reply #3 on: February 24, 2011, 01:50:20 PM »
Quote
but i just cannot understand how it read.. sorry, i am really confusing about this encoder signal..
In the encoder manual there is a sample schematic, Figure 3.0.
The connector at the top right has the encoder on pins 5 & 6 with a note about 1k pull-ups. This implies that the encoder outputs are open-collector.
Part 1.1 shows the encode output logic and timing.

Quote
how the program reads the signal from the encoder?
This code:
Code: [Select]
signal_A && !signal_Breads the PIC port pins. There are #defines elsewhere in the code assigning the names 'signal_A' & 'signal_B' to port pins.

It seems you do not have any experience with PIC coding. So here is a link the a good tutorial on using and coding PICs:
http://www.gooligum.com.au/tutorials.html

Also read the PIC16F877 data sheet.

 

SMF spam blocked by CleanTalk