Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
unnamed
PostPosted: Jul 22, 2012 - 06:46 PM
Rookie


Joined: May 10, 2011
Posts: 27


Hi, can someone explain to me why my servo is 'laggy' when i'am controlling it over serial port ?
Serial is working at 115200bps. Here you can see difference between buttons and serial control.

http://www.youtube.com/watch?v=II8tb7Of ... e=youtu.be

any ideas what can be wrong ?
 
 View user's profile Send private message  
Reply with quote Back to top
DocJC
PostPosted: Jul 22, 2012 - 07:21 PM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6980
Location: Cleveland, OH

Quote:
why my servo is 'laggy'


It did not appear to lag at all, at the start of the video you pushed the buttons and it responded appropriately.

THEN, without you pushing any buttons, it started moving again. That would appear to be the problem.

That, also, would appear to be a software problem.

The video says Rasperry Pi Xmega Servo, so what is the real system configuration?

It looks like you have an Xmega Xplain PCB, and you are pushing buttons on it, and the servo moves. Is there a Rasberry Pi in the system at this time, or not?

The point is, you need to determine if the Xmega code or the Pi code has a bug. If the Pi is NOT part of the setup, then one can obviously eliminate that as the source of the current problem.

Assuming the servo is being driven by the Xmega PCB, then it appears to me your program is sending more instructions after your initial inputs.

Perhaps your Main Loop isn't looping? Add a couple of LED flashes to the start up sequence to see if the Xmega is looping around and restarting the entire program. Any interrupts taking over controlof the output,and trashing it? Any Command Buffer not being cleared? Any volatiles not being declared volatile? (Hey, that one is added as that is what the C guys alwyas look at first...)

JC
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
unnamed
PostPosted: Jul 22, 2012 - 08:42 PM
Rookie


Joined: May 10, 2011
Posts: 27


hmm i didn't explain myself right.

i have 2 options in my xmega programm, controling servo with buttons or serial commands, in video i was first pushing buttons to show how servo moves (and its ok), and next i'am using serial command from raspberry using minicom. with serial commands u can see how laggy it is.

main looks like this:
Code:

int main (void)
{
   Config32MHzClock();
   timersInit();
   usartInit();
   stdout = &mystdout;
   SWITCHPORT.DIR = 0x00;
   SWITCHPORT.PIN0CTRL = PORT_OPC_PULLUP_gc;
   SWITCHPORT.PIN4CTRL = PORT_OPC_PULLUP_gc;
   SWITCHPORT.PIN1CTRL = PORT_OPC_PULLUP_gc;
   SWITCHPORT.PIN5CTRL = PORT_OPC_PULLUP_gc;
   LEDPORT.DIRSET = 0x03;
   LEDPORT.DIRSET = 0xB0;   
   LEDPORT.OUTSET = 0x80;


   while(1) {
      if(ioport_pin_is_high(GPIO_PUSH_BUTTON_0)){
         LEDPORT.OUTSET = 0x01;
         if(compareValue < 1140){
         compareValue += 20;
         }         
      }else{
         LEDPORT.OUTCLR = 0x01;
      }
      if(ioport_pin_is_high(GPIO_PUSH_BUTTON_4)){
         LEDPORT.OUTSET = 0x10;
         if(compareValue > 200){
         compareValue -= 20;
         }         
      }else{
         LEDPORT.OUTCLR = 0x10;
      }
      if(ioport_pin_is_high(GPIO_PUSH_BUTTON_1)){
         LEDPORT.OUTSET = 0x02;
         if(compareValueSec < 1140){
         compareValueSec += 20;
         }         
      }else{
         LEDPORT.OUTCLR = 0x02;
      }
      if(ioport_pin_is_high(GPIO_PUSH_BUTTON_5)){
         LEDPORT.OUTSET = 0x20;
         if(compareValueSec > 200){
         compareValueSec -= 20;
         }         
      }else{
         LEDPORT.OUTCLR = 0x20;
      }
      
      if(receivedData == 97){
         if(compareValue > 200){
            compareValue -= 20;
         }   
         receivedData = "\0";         
      }else if(receivedData == 115){
         if(compareValue < 1140){
            compareValue += 20;
         }   
         receivedData = "\0";      
      }   
      _delay_ms(300);

      LEDPORT.OUTSET = 0x80;
   }
}


usart init like this:

Code:

void usartInit(void)
{
   PORTD.DIRSET = PIN3_bm;   // PD3 (TXD0) as output
   PORTD.DIRCLR = PIN2_bm;   // PD2 (RXD0) as input

   USART_InterruptDriver_Initialize(&USART_data, &USART, USART_DREINTLVL_MED_gc);

   USART_Format_Set(&USART, USART_CHSIZE_8BIT_gc, USART_PMODE_DISABLED_gc, false);
   
   USART_RxdInterruptLevel_Set(USART_data.usart, USART_RXCINTLVL_MED_gc);

   USART_Baudrate_Set(&USART, 1047 , -6 );

   USART_Rx_Enable(&USART);
   USART_Tx_Enable(&USART);
   
   PMIC.CTRL |= PMIC_MEDLVLEN_bm;
   sei();
}


for my noob brain its like serial commands are to slow Smile but i'am just starting with avr so i dont really get how it all works Smile
 
 View user's profile Send private message  
Reply with quote Back to top
DocJC
PostPosted: Jul 22, 2012 - 10:23 PM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6980
Location: Cleveland, OH

I don't use C, I'll let others comment on the code.

Is the 300 mSec delay active for both push button and USART commands?

Are you using a USB to serial cable? If so is your Pi transmission routine sending 1 character at a time, or one packet at a time. The typical USB ISR would occur at 1 / mSec, and you want the entire packet sent on the next USB interrupt, and sent as one packet. Still, the stuttering of your servo seems that this alnoe is not the issue.

You might flash an LED with every new command received. See if the LED flashes slower when getting the Pi commands. Any delays in your PI software that are preventing it from sending commands quickly?

JC
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
unnamed
PostPosted: Jul 22, 2012 - 10:32 PM
Rookie


Joined: May 10, 2011
Posts: 27


300ms delay is active fro both buttons and commands

i'am not using usb, pins are connected directly to each other.

i'am gonna try with led tomorrow Smile
 
 View user's profile Send private message  
Reply with quote Back to top
DocJC
PostPosted: Jul 22, 2012 - 11:03 PM
Raving lunatic


Joined: Dec 11, 2007
Posts: 6980
Location: Cleveland, OH

Quote:
i'am not using usb, pins are connected directly to each other.


HOW?

I did not see you moving any switches or wires in the video?

Please upload a schematic of your project's wiring, showing what the servo is connected to, and wht the Pia nd Xmega are connected to.

You can draw a picture on paper, on any drawing or schematic program, and generate a jpg image of the schematic. If you draw it on paper just take a picture of it with your cell phone.

Click the Preview button instead of the Submit button and you will get to a box that allows you to attach the JPG image.

JC
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
unnamed
PostPosted: Jul 23, 2012 - 09:06 AM
Rookie


Joined: May 10, 2011
Posts: 27


Pi rx/tx pins are connected directly to xmega rx/tx pins, u can see it on the movie from my first post, wires are going through breadboard but theres nothing between them.

so its simple as raspi -(seril commands)- xmega - servo
 
 View user's profile Send private message  
Reply with quote Back to top
Who-me
PostPosted: Jul 26, 2012 - 11:39 PM
Hangaround


Joined: Mar 25, 2007
Posts: 106


unnamed wrote:
Pi rx/tx pins are connected directly to xmega rx/tx pins..


When you have two blocks like this, and are unsure who causes the delay, an obvious test step is to include bright LEDs on the interface TX/RX pins.

If you have a scope, you can time Button-Fall to PiTXD out, and AVR_RXD to Servo action.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits