Sevos not working

Here is the place for all your dsPic or autopilot questions.

Moderator: lukasz

Re: Sevos not working

Postby Tom » Sun May 30, 2010 2:05 pm

Hi Marc,

Everything you say is right :-) Your suggestions will be for a new version, especially the last one is not easy (and can be overcome if you follow the steps described in the wiki).

As for the resets, this is really strange. My module never resets. Some other users have had resets, but most of the time they were using heavy servos on the same 5V as the module.

I updated the microcontroller.c code:
Code: Select all
   
#include "microcontroller/microcontroller.h"
#include "uart1_queue/uart1_queue.h"

RCONBITS RCONbits_backup;


_FOSCSEL(FNOSC_PRIPLL);
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF  & POSCMD_XT); 

//_FWDT(FWDTEN_OFF);       // Watchdog Timer Enabled/disabled by user software   




void microcontroller_init()
{   
   INTCON2bits.ALTIVT = 0;    // Don't use alternate interrupt vector
   
   // Disable Watch Dog Timer
   RCONbits.SWDTEN=0;
   
   
   /*  Configure Oscillator to operate the device at 80Mhz (40MIPS)
       Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
       Fosc= 4M*80/(2*2)=80Mhz for 4MHz input clock */
   CLKDIVbits.PLLPRE = 0;    // N1=2 
   CLKDIVbits.PLLPOST = 0;   // N2=2
   PLLFBDbits.PLLDIV = 78;   // ->F_XT / 2 * (78 + 2) / 2
   
   RCONbits_backup = RCONbits;
   RCON = 0;  // we have to do this to make sure we can read RCON correctly on a (next) reset
}


/*!
 *  Delay function
 *  @param ms Number of milliseconds (0.001s) the function needs to wait.
 */
void microcontroller_delay_ms(unsigned long ms)
{
   //__delay32((long)FCY/1000L*ms);
   unsigned long i = FCY/1000/12*ms;
    for(;i > 0 ;i--)
        asm("clrwdt");
}


/*!
 *  Delay function
 *  @param us Number of microseconds (0.000001s) the function needs to wait.
 */
void microcontroller_delay_us(unsigned long us)
{
   long i = FCY/1000/1000/12*us;
    for(;i > 0 ;i--)
        asm("clrwdt");
}


void microcontroller_reset_type()
{
   if (RCONbits_backup.BOR)
   {
      uart1_puts("A Brown-out Reset has occurred\r\n");
   }
   if (RCONbits_backup.EXTR)
   {
      uart1_puts("A Master Clear (pin) Reset has occurred\r\n");
   }
   if (RCONbits_backup.IDLE)
   {
      uart1_puts("Device was in Idle mode\r\n");
   }
   if (RCONbits_backup.IOPUWR)
   {
      uart1_puts("An illegal opcode detection, an illegal address mode or uninitialized W register used as an Address Pointer caused a Reset\r\n");
   }   
   if (RCONbits_backup.POR)
   {
      uart1_puts("A Power-up Reset has occurred\r\n");
   }
   if (RCONbits_backup.SLEEP)
   {
      uart1_puts("Device has been in Sleep mode\r\n");
   }
   if (RCONbits_backup.SWDTEN)
   {
      uart1_puts("WDT is enabled\r\n");
   }
   if (RCONbits_backup.SWR)
   {
      uart1_puts("A RESET instruction has been executed\r\n");
   }
   if (RCONbits_backup.TRAPR)
   {
      uart1_puts("A Trap Conflict Reset has occurred\r\n");
   }
   /*if (RCONbits_backup.VREGS)
   {
      uart1_puts("Voltage regulator is active during Sleep\r\n");
   }*/
   if (RCONbits_backup.WDTO)
   {
      uart1_puts("WDT time-out has occurred\r\n");
   }                              
}
   

int microcontroller_after_reboot()
{
   return !(RCONbits_backup.EXTR || RCONbits_backup.POR); // We are in a reboot if there was no external reset
}


/* ****************************************************************
* Standard Exception Vector handlers if ALTIVT (INTCON2<15>) = 0  *
*                                                                 *
* Not required for labs but good to always include                *
******************************************************************/
#define _trapISR __attribute__((interrupt,no_auto_psv))

void _trapISR _OscillatorFail(void)
{
        INTCON1bits.OSCFAIL = 0;
        uart1_puts("Oscillator error!\n\r");
        //while(1);
}

void _trapISR _AddressError(void)
{
        INTCON1bits.ADDRERR = 0;
        uart1_puts("Address error!\n\r");
        //while(1);
        asm("reset");
}

void _trapISR _StackError(void)
{
        INTCON1bits.STKERR = 0;
        uart1_puts("Stack error!\n\r");
        //while(1);
        asm("reset");
}

void _trapISR _MathError(void)
{
        INTCON1bits.MATHERR = 0;
        uart1_puts("Math error!\n\r");
        //while(1);
        asm("reset");
}




void __attribute__((interrupt, no_auto_psv)) _AltOscillatorFail(void)
{
        INTCON1bits.OSCFAIL = 0;
        uart1_puts("Oscillator error!\n\r");
        //while(1);
}

void __attribute__((interrupt, no_auto_psv)) _AltAddressError(void)
{
        INTCON1bits.ADDRERR = 0;
        uart1_puts("Address error!\n\r");
        //while(1);
        asm("reset");
}

void __attribute__((interrupt, no_auto_psv)) _AltStackError(void)
{
        INTCON1bits.STKERR = 0;
        uart1_puts("Stack error!\n\r");
        //while(1);
        asm("reset");
}

void __attribute__((interrupt, no_auto_psv)) _AltMathError(void)
{
        INTCON1bits.MATHERR = 0;
        uart1_puts("Math error!\n\r");
        //while(1);
        asm("reset");
}




The traps are printed to screen (so keep your terminal or config tool open).
On boot-up, the module prints the reason for reset. On a normal reset I get:
Code: Select all
A Brown-out Reset has occurred
A Power-up Reset has occurred


I don't know where the Brown-out reset comes from at a normal start-up...

Attached this latest firmware.

Can this help you?
Attachments
rtos_pilot.zip
(63.08 KiB) Downloaded 474 times
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Sevos not working

Postby Tom » Sun May 30, 2010 4:58 pm

Mistery solves!

On some occasions, the very first value of pitch and roll are "NaN". This is kept in the PID for the integrate-term.

So the value towards the servos was 1500 + (-1) because (int)NaN = -1

Here the fixed firmware:
Marc, Can you check if it works?

Thanks for pointing it out!

How about the reboots?
rtos_pilot.zip
(63.16 KiB) Downloaded 489 times
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Sevos not working

Postby marc » Sun May 30, 2010 5:06 pm

Hi Tom,

I flashed the new firmware... at least now I have an direction for searching for the crashes... it ssems to be linked with the power supply (and I use 3 grams servos...) ;-)
Look below:
[06:31:03.45] Sensors task initializing...Gluonpilot v0.2DVLP [May 30 2010 15:49:37, config: 220 bytes, logline: 62 bytes, double: 4 bytes]
[06:31:03.45] A Brown-out Reset has occurred
[06:31:03.46] Loading configuration...done
[06:31:03.89] Opening ppm...channels: 8 done
[06:31:08.81] Opening GPS...timeout...done
[06:31:08.81] Control task initializing...done
[06:31:09.34] Sensors task initializing...Gluonpilot v0.2DVLP [May 30 2010 15:49:37, config: 220 bytes, logline: 62 bytes, double: 4 bytes]
[06:31:09.34] A Brown-out Reset has occurred
[06:31:09.35] Loading configuration...done


My point was also to save the Traps in EEPROM since the terminal will not always be connected and in case of crash it could explain/discard assumptions...


With the new firmware I have problems with the roll... which doesn't work even in manual mode while perfectly visible on the RC input... it's seems to be a repetitive issue for me... I suspect a bug in the flash burn process since it always finish to work after several retries... (my config is different from yours : autopilot SW in ch6, roll on ch1, pitch on ch2 and ailerons)

CU

Marc
marc
 
Posts: 21
Joined: Wed Nov 25, 2009 3:28 pm

Re: Sevos not working

Postby Tom » Sun May 30, 2010 8:25 pm

If the flash burn doesn't work, it's easy to verify: if the "Read" command returns the correct values then it must be OK in memory. If "Read" is OK after a reboot it also must be OK.

Do you also get resets without the servo attached? Sometimes these small servos have a lot of peak-current.
And if you also disconnect the receiver?

Do you also have these kind of resets with, for example, the servo_test example?

Maybe you can monitor the 5V with a scope? It's really strange because I can easily control 3 servos using the FTDI 5V cable. It never ever reboots.
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Re: Sevos not working

Postby Tom » Sun May 30, 2010 8:41 pm

(I guess you're not connecting the ESC and the FTDI 5V at the same times?)
User avatar
Tom
Site Admin
 
Posts: 1016
Joined: Fri Nov 13, 2009 6:27 pm
Location: Belgium

Previous

Return to Firmware

Who is online

Users browsing this forum: No registered users and 4 guests

cron