Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: saliraza on April 30, 2009, 01:43:04 PM
-
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;
}
-
Before we continue lets work on the basics . . .
What version Axon software are you using?
What battery voltage and mAh do you have? Is it fully charged?
Are those four motors being run off the same battery?
-
Hello Admin, thanks for replying.
* I am using Axon software version v1.05.
* I have a Li-po of 11.1v 2100mAh (fully charged), as main power source for my 4 BLDC motors, and the Axon board. From Axon, I further power the IMU with 3.3v and 5v.
What I have tried:
* The 5v and 3.3v power from Axon to the IMU sensor have 10uF capacitors between the + and - terminals.
* The connections are all tested for shorts or any other fault.
* Run the Axon board alone, detaching the IMU and motors, with Li-po and a new 9v battery, both times i got the same resetting repeating several times with 2 second intervals and then stuck on repeating "System Warming Up".
Observations:
* If i set the ADC prescalar to higher value such as 128, the resetting occurs at fast rate. Lowering the value to 16 (which is undesired) reduce the resetting rate.
* Also increasing the delay in the very end of the code to higher value such as 1000ms fixes the issue, however I want to run the main loop at minimum 100Hz so I need 10ms delay.
I first suspected the use of same power source to the BLDC (very noisy) motors and Axon, but even running Axon alone on a new 9v battery with the same problem seems to point toward some kind of timing issue resulting in resetting. The resources I am using are just the usb UART1, timer3 & 4 for PWM (with prescale defined as TIMER_CLK_DIV64), and ADC channels 0-5 at 10bit.
I am thankful for your reply and am sure to get reliable help from you.
Regards,
Ali
-
your code path does not seem to be affected by any inputs, run the simulator for a while with a breakpoint at your first instruction, this may take a while but it can let you identify whether it's an electrical bug or a software bug. keep your eye on your stack while doing this, the compiler may have freaked out and allocated a variable into the stack or screwed up a pointer.
but from what you describe, i doubt it's software
-
Haven't seen this problem before . . .
Just to identify whether its a software or a hardware issue, do you have an oscilloscope?
Basically connect between ground and 5V and look for voltage drops below 5V at high speed.
I have a Li-po of 11.1v 2100mAh (fully charged), as main power source for my 4 BLDC motors
Also, there was a typo in my Axon documentation that I only corrected a few weeks ago. I said that the max voltage for the Axon was 20V, but actually its 10V. That big blue cap can be swapped out for a higher voltage rating if you need to. I'm not sure if this is causing the problem, but going above the capacitor rating could make the cap explode (won't result in damage to the Axon, you just need to replace the cap).