wrong readout Position controllers Parallax
chatrouge
Posts: 2
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.
somebody experience with this controller or comparible controllers and problems ?
many thanks,
Joep
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
Are you talking about this position controller?
http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/position/List/0/SortField/4/ProductID/665/Default.aspx
@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.