Shop OBEX P1 Docs P2 Docs Learn Events
wrong readout Position controllers Parallax — Parallax Forums

wrong readout Position controllers Parallax

chatrougechatrouge Posts: 2
edited 2011-04-20 14:32 in Accessories
Hi there!

I am doing a project with a robot and i use the parallax positioning controllers. I am using a motorola microcontroller called mc9s12xdp512 ... and i am programming in C-language.

The problem i am facing is the readout of the information i am getting back. For example i am sending a command QPOS to ask the number of pulses the wheel has travelled.
command(encoder_right,QPOS);            // vraag aantal pulsen gereden
delay1();                                   // small delay between sending receiving                     
Nr = receive_message();                       // receive the data from encoder

void command(unsigned char encoder, unsigned char command)
{ 
case (QPOS):
      SCI0DRL = (QPOS|adres);  //QPOS
      break;
    case (QSPD):  
      SCI0DRL = (QSPD|adres);  //QSPD
      break;    
    case (CHFA): 
      SCI0DRL = (CHFA|adres);  //CHFA
      break;
    case (TRVL):
      SCI0DRL = (TRVL|adres);  //TRVL
      break;
}
int receive_message(void)
{
  SCI0SR2 = 0x00;                               // TXDIR = input 
  while((SCI0SR1 & SCISR1_RDRF_MASK) == 1) ;    // wait until data register is full
  return SCI0DRL;
}
the problem i am dealing with is the fact that my readout is an 8-bit value while the position controller has to send a 16-bit value.... i know that my dataregister is an 8-bit register so thats why i am reading only 8-bits.. but my question is how to get a 16-bit readout ? at the moment my readout works from the value 0-255... so the encoders DO send information back but only from 0 to 255 and then reset to 0.

somebody experience with this controller or comparible controllers and problems ?

many thanks,

Joep

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-19 07:40
  • kwinnkwinn Posts: 8,697
    edited 2011-04-19 18:25
    In most cases 16 bit values are read as 2 bytes over a serial link and then combined ( x + y*256 ) to make a 16 bit value.
  • chatrougechatrouge Posts: 2
    edited 2011-04-19 23:40
    Hi there, yeah thats the one i am using !

    @kwinn: i dont exactly understand what you are saying? what do you mean with (x+y*256) ?
    Is it just a matter of sending my command QPOS, and then just receive 2 times? a short delay is needed right ?

    thanks :)
  • kwinnkwinn Posts: 8,697
    edited 2011-04-20 14:32
    chatrouge wrote: »
    Hi there, yeah thats the one i am using !

    @kwinn: i dont exactly understand what you are saying? what do you mean with (x+y*256) ?
    Is it just a matter of sending my command QPOS, and then just receive 2 times? a short delay is needed right ?

    thanks :)

    Yes, you need to receive 2 bytes (times) and combine them to get a 16 bit value if they are sent that way. The documentation for the position controller should describe the format the data is sent in. Typically the first byte (least significant byte) is added to zero, then the second byte (most significant byte) is multiplied by 256 and added to the first byte. This is like receiving the number 12 as 2 characters. First you receive the 2 and save it, then you receive the 1, multiply it by 10, and add it to the 2 you saved.
Sign In or Register to comment.