Hi Everyone,
I got this issue with the Axon when I try to ADC data from the ADXLS330 3.x accelerometer, IDG300 2.x gyro, and ADXRS300 1.x gyro. I am also trying to run 4 BLDC motors by using the PWM code provided on the tutorials. I have made couple of postings before and have received good help from the society ... thanks a bunch.
Now, I got this resetting issue. I have used the help from some postings on the forum and the FAQ entry on the subject and placed 10uF caps between the GND and the 5v, 3.3v power supply from Axon. This reduced the resetting rate, however its still happening and sfter few hickups system stalls to the "system warming up" repeating on the H-terminal, not even to any further prompts that i placed to monitor the code flow. Also i noticed that the resetting issue reduces if i make the ADC prescaler fast. I am attaching the code im running so that you can see if im making some basic mistake.
Regards,
Ali
p.s here is the code im running:
int main(void)
{
//declare variables here
int i=0;//useless variable
int j=0;//useless variable
//ADC Variables
int a3=0,a4=0,a5=0;
int a0=0,a1=0,a2=0,a6=0;
//Accelerometer Variables and Constants
float ax=0.0,ay=0.0,az=0.0;
float p=0.0,r=0.0,t=0.0;
//Gyro Variables and Constants
int tm;
float gx=0.0,gy=0.0,gz=0.0;
float g_p=0.0,g_r=0.0,g_y=0.0;
/****************INITIALIZATIONS*******************/
//other stuff Im experimenting with for SoR
uartInit(); // initialize the UART (serial port)
uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection
uartSetBaudRate(2, 38400); // set UARTH speed
uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
//G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)
rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf
configure_ports(); // configure which ports are analog, digital, etc.
LED_on();
rprintf("\r\nSystem Warming Up");
// initialize the timer system (comment out ones you don't want)
timer0Init();
timer1Init();
timer2Init();
timer3Init();
timer4Init();
//timer5Init();
a2dInit(); // initialize analog to digital converter (ADC)
//select speed/accuracy of data conversion
a2dSetPrescaler(ADC_PRESCALE_DIV16); // configure ADC scaling
// A2D clock prescaler select
// *selects how much the CPU clock frequency (16MHz) is divided
// to create the A2D clock frequency
// *lower division ratios make conversion go faster
// *higher division ratios make conversions more accurate
// ADC_PRESCALE_DIV2 -> CPU clk/2
// ADC_PRESCALE_DIV4 -> CPU clk/4
// ADC_PRESCALE_DIV8 -> CPU clk/8
// ADC_PRESCALE_DIV16 -> CPU clk/16 = 1MHz
// ADC_PRESCALE_DIV32 -> CPU clk/32 = 500KHz
// ADC_PRESCALE_DIV64 -> CPU clk/64 = 250KHz
// ADC_PRESCALE_DIV128 -> CPU clk/128= 125KHz
//a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
a2dSetReference(ADC_REFERENCE_256V);
//let system stabelize for X time
for(i=0;i<16;i++)
{
j=a2dConvert10bit(i);//read each ADC once to get it working accurately
delay_cycles(5000); //keep LED on long enough to see Axon reseting
rprintf(".");
}
LED_off();
/*********ADD YOUR CODE BELOW THIS LINE **********/
rprintf("Initialization Complete \r\n");
//wait until user pushes button
//while(!button_pressed());
//rprintf("Robot Started \r\n");
//reset all timers to zero
reset_timer_0();
reset_timer_1();
reset_timer_2();
reset_timer_3();
reset_timer_4();
//reset_timer_5();
// Initialize Motors
if(button_pressed())
{
rprintf("Arming Motors \r\n");
PWM_Init_timer3_E3(10);
delay_ms(100);
PWM_Init_timer3_E4(10);
delay_ms(100);
PWM_Init_timer4_H3(10);
delay_ms(100);
PWM_Init_timer4_H4(10);
delay_ms(100);
PWM_timer3_On_E3();
PWM_timer3_On_E4();
PWM_timer4_On_H3();
PWM_timer4_On_H4();
delay_ms(3000);
PWM_timer3_Set_E3(127);
PWM_timer3_Set_E4(127);
PWM_timer4_Set_H3(127);
PWM_timer4_Set_H4(127);
delay_ms(3000);
PWM_timer3_Set_E3(254);
PWM_timer3_Set_E4(254);
PWM_timer4_Set_H3(254);
PWM_timer4_Set_H4(254);
delay_ms(3000);
PWM_timer3_Set_E3(127);
PWM_timer3_Set_E4(127);
PWM_timer4_Set_H3(127);
PWM_timer4_Set_H4(127);
delay_ms(3000);
//PWM_timer3_Off_E3();
//PWM_timer3_Off_E4();
//PWM_timer4_Off_H3();
//PWM_timer4_Off_H4();
rprintf("Motors Armed \r\n");
}
while(1)
{
//clear timer
//reset_timer_2();
//if you don't require high speed data collection,
//add a delay here to slow it down
//be careful that clock doesn't overflow!
//delay_ms(100); //Sampling Rate 100Hz (Sensors bandwidth is 10Hz)
//configure ADC to 2.56V
//a2dSetReference(ADC_REFERENCE_256V);
//delay_us(200);//wait for change
//a1=a2dConvert10bit(1);//refresh ADC
//gather data
a0=a2dConvert10bit(0);//GyroZ
a1=a2dConvert10bit(1);//GyroX
a2=a2dConvert10bit(2);//GyroY
a3=a2dConvert10bit(3);//AccelX
a4=a2dConvert10bit(4);//AccelY
a5=a2dConvert10bit(5);//AccelZ
a6=a2dConvert10bit(6);//Temp
//configure ADC to 5V
//a2dSetReference(ADC_REFERENCE_AVCC);
//delay_us(200);//wait for change
//a0=a2dConvert10bit(0);//refresh ADC
//Accelerometer Measurements Zero Calibration
ax=(a3-354.5); //(accel_ADC-accel_OFFSET)*accel_SCALE
ay=(a4-353.5);
az=(a5-335);
//Gravity Aiding Roll, Pitch, and Theta Angles
p=60*atan2(ax,sqrt(square(ay)+square(az)));
r=60*atan2(ay,sqrt(square(ax)+square(az)));
t=60*atan2(sqrt(square(ax)+square(ay)),az);
//Gyro Measurement offset Calibration
gy=(a2-319)*3.75; //(gyro_ADC-gyro_OFFSET)*gyro_SCALE
gx=(a1-327)*3.75;
gz=(a0*1.13)-561;
tm=(a6*0.67)-273;
g_p=0.98*(g_p+gx*0.011)+0.02*(p);
g_r=0.98*(g_r+gy*0.011)+0.02*(r);
g_y=g_y+gz*0.011;
//report angle estimates
//rprintf("Pitch=%d Roll=%d Theta=%d\r\n",(int)p,(int)r,(int)t);
//rprintf("GyroX=%d GyroY=%d GyroZ=%d Temp=%d\r\n",(int)g_p,(int)g_r,(int)g_y,tm);
j=127+(int)g_p;
PWM_timer3_Set_E3(j);
// Fuzzy Flight Controller
// Inputs are X,Y,Z coordinates, Roll,Pitch,Yaw angle estimates
// Sonar Data
// Outputs are PWM motor speeds
//control();
delay_ms(10);//an optional small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/
return 0;
}