Page 1 of 1

Question PIC30F4011 to control SC16A

PostPosted: Thu Apr 12, 2012 8:31 pm
by syting
Hi, I already get to move the servo motor by using SC16A controller. However I don know what command \i need to sent to get the position from SC16A. ( like the example show in cytron website, but it's write it in PIC16F and 18F) can U give me any of samplre code to get the position of servo motor from SC16A by using PIC30F ?


Here the function I try estimate from PIC16F


unsigned int request_position_cmd(unsigned char channel)
{
unsigned char first_byte=0, check_id, higher_position, low_position;

first_byte=0b10100000|channel;

U1TXREG = first_byte;

higher_position = UART_Rec();
low_position = UART_Rec();

position = higher_position<<6;
position = position|(low_position&0x3F);

return position;
}
unsigned char UART_Rec(void) //receive uart value
{
unsigned char rec_data;
while(U1STAbits.URXDA == 0); //wait for data
U1STAbits.OERR = 0;
rec_data = U1RXREG;
returnrec_data; //return the data received
}

Re: Question PIC30F4011 to control SC16A

PostPosted: Thu Apr 12, 2012 10:26 pm
by shahrul
Why not just use PIC16F or PIC18F?

Re: Question PIC30F4011 to control SC16A

PostPosted: Thu Apr 12, 2012 10:33 pm
by robosang
I am sure Cytron staff will be super busy providing example code for every model of PIC, another one will ask for dsPIC33, PIC24, then it come to PIC32. And some one will start asking for Arduino code 8-)

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 8:50 am
by Idris
The concept is same, just using UART and follow SC16A protocol. You need to study about UART in dsPIC30F.

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 9:36 am
by hyng
Have you try to write out the code? What are the errors you got?
You can post some codes here if you have any doubt. Then we can verify from there..

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 12:45 pm
by syting
ok .. here the function .... I already try run.. no error but no function.


unsignedintrequest_position_cmd(unsigned char channel)
{
unsigned char first_byte=0, check_id, higher_position, low_position;

first_byte=0b10100000|channel;

U1TXREG = first_byte;

higher_position = UART_Rec();
low_position = UART_Rec();

position = higher_position<<6;
position = position|(low_position&0x3F);

return position;
}
unsigned char UART_Rec(void) //receive uart value
{
unsigned char rec_data;
while(U1STAbits.URXDA == 0); //wait for data
U1STAbits.OERR = 0;
rec_data = U1RXREG;
returnrec_data; //return the data received
}

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 12:46 pm
by syting
And thanks for everyone reply my message .. I hope u guys can help me with that .. I will very appreciate :)

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 3:09 pm
by Idris
Do you have set the appropriate baudrate?

Re: Question PIC30F4011 to control SC16A

PostPosted: Fri Apr 13, 2012 3:48 pm
by hyng
Have you follow the command in correct way?
If not mistaken, the position report command will need to send two bytes to SC16A before getting the 3 bytes of data.
In the function given by you, you only send a byte (servo channel) to SC16A, what about another byte? Other than that, you only receive two bytes from SC16A but in fact it will send back 3 bytes if the two bytes you send to SC16A is valid.