Question PIC30F4011 to control SC16A

Autonomous Robot, Manual Robot, DC Motor Driver, Stepper Motor Driver, Servo, Multi PWM chip.....

Question PIC30F4011 to control SC16A

Postby syting » Thu Apr 12, 2012 8:31 pm

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
}
syting
Greenhorn
 
Posts: 3
Joined: Thu Apr 12, 2012 8:15 pm

Re: Question PIC30F4011 to control SC16A

Postby shahrul » Thu Apr 12, 2012 10:26 pm

Why not just use PIC16F or PIC18F?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: Question PIC30F4011 to control SC16A

Postby robosang » Thu Apr 12, 2012 10:33 pm

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-)
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: Question PIC30F4011 to control SC16A

Postby Idris » Fri Apr 13, 2012 8:50 am

The concept is same, just using UART and follow SC16A protocol. You need to study about UART in dsPIC30F.
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Question PIC30F4011 to control SC16A

Postby hyng » Fri Apr 13, 2012 9:36 am

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..
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: Question PIC30F4011 to control SC16A

Postby syting » Fri Apr 13, 2012 12:45 pm

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
}
syting
Greenhorn
 
Posts: 3
Joined: Thu Apr 12, 2012 8:15 pm

Re: Question PIC30F4011 to control SC16A

Postby syting » Fri Apr 13, 2012 12:46 pm

And thanks for everyone reply my message .. I hope u guys can help me with that .. I will very appreciate :)
syting
Greenhorn
 
Posts: 3
Joined: Thu Apr 12, 2012 8:15 pm

Re: Question PIC30F4011 to control SC16A

Postby Idris » Fri Apr 13, 2012 3:09 pm

Do you have set the appropriate baudrate?
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Question PIC30F4011 to control SC16A

Postby hyng » Fri Apr 13, 2012 3:48 pm

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.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am


Return to Robot Controller

Who is online

Users browsing this forum: No registered users and 11 guests

cron