Commit 6d6d7422 authored by Pavel Semerad's avatar Pavel Semerad
Browse files

show calibrate after poweron with steering/strottle not in dead zone

parent 8c7d049f
......@@ -4,6 +4,9 @@
PPM length shortened to "NUM_CHANNELS x 2ms + 5ms" to send new data
to receiver as soon as possible
ADC measuring every 1ms, averaging last 4 samples when used
after poweron, if steering or throttle are not in center dead zone,
show calibration screen, because recalibration will be probably
needed
*0.4.1 (17 Aug 2011)
......
......@@ -6,7 +6,6 @@ CALC - calc at end of SYNC signal
without PPM pulse, after that activate CALC
- maybe constant length servo pulse
warning when powering up and steering wheel + throttle not in center position
beep at startup - switchable at global config
check inactivity as compare to previous value and not center value
shut-off low-battery beeping
......
......@@ -44,7 +44,6 @@ static void calc_loop(void);
void calc_init(void) {
build(CALC);
activate(CALC, calc_loop);
sleep(CALC); // nothing to do yet
}
......
......@@ -367,16 +367,14 @@ static void check_inactivity(void) {
// input task, awaked every 5ms
_Bool input_initialized;
// read first ADC values
#define ADC_BUFINIT(id) \
adc_buffer ## id ## [1] = adc_buffer ## id ## [2] = \
adc_buffer ## id ## [3] = adc_buffer ## id ## [0];
static void input_loop(void) {
void input_read_first_values(void) {
// read initial ADC values
BSET(ADC_CR1, 0); // start conversion
while (!BCHK(ADC_CSR, 7)) pause(); // wait for end of conversion
while (!BCHK(ADC_CSR, 7)); // wait for end of conversion
read_ADC();
// put initial values to all buffers
......@@ -385,11 +383,13 @@ static void input_loop(void) {
ADC_BUFINIT(2);
adc_battery = adc_battery_last;
adc_battery_filt = (u32)adc_battery * ADC_BAT_FILT;
}
// task CALC must be awaked to compute values before PPM will take on
awake(CALC);
input_initialized = 1;
// input task, awaked every 5ms
static void input_loop(void) {
while (1) {
read_keys();
check_inactivity();
......
......@@ -139,7 +139,6 @@ extern u16 adc_buffer_pos; // step 2 (skip 16bit values)
// INPUT task
E_TASK(INPUT);
extern _Bool input_initialized;
#endif
......
......@@ -26,6 +26,7 @@
extern void ppm_init(void);
extern void lcd_init(void);
extern void input_init(void);
extern void input_read_first_values(void);
extern void buzzer_init(void);
extern void timer_init(void);
extern void task_init(void);
......@@ -67,13 +68,14 @@ void main(void) {
clock_init();
task_init();
input_init(); // here to have time to stabilize ADC
eeprom_init();
buzzer_init();
ppm_init();
timer_init();
lcd_init();
calc_init();
input_init();
input_read_first_values();
timer_init();
// enable interrupts
rim();
......
......@@ -81,7 +81,7 @@ void apply_model_config(void) {
if (channels != MAX_CHANNELS) {
ppm_set_channels(MAX_CHANNELS); // maybe sometime cm.channels
// task CALC must be awaked to do first PPM calculation
if (input_initialized) awake(CALC);
awake(CALC);
}
// set mixed channels to ignore them from menu_channel3_8
......@@ -797,10 +797,15 @@ void menu_init(void) {
// variables
menu_key_mapping_prepare();
// read global config from eeprom, if calibrate values changed,
// read global config from eeprom, if calibrate values was set to defaults,
// or if actual steering/throttle value is not in dead zone,
// call calibrate
if (config_global_read())
menu_calibrate();
if (config_global_read() ||
adc_steering_last < (cg.calib_steering_mid - cg.steering_dead_zone) ||
adc_steering_last > (cg.calib_steering_mid + cg.steering_dead_zone) ||
adc_throttle_last < (cg.calib_throttle_mid - cg.throttle_dead_zone) ||
adc_throttle_last > (cg.calib_throttle_mid + cg.throttle_dead_zone))
menu_calibrate();
apply_global_config();
// read model config from eeprom, but not awake CALC yet
......
......@@ -59,10 +59,8 @@ static u16 menu_delay; // timer for delay in MENU task
@interrupt void timer_interrupt(void) {
BRES(TIM2_SR1, 0); // erase interrupt flag
// read ADC only when EOC flag (only for first it will not be ready)
if (input_initialized && BCHK(ADC_CSR, 7)) {
READ_ADC();
}
// read ADC values every 1ms, it had enought time to end conversion
READ_ADC();
// increment 1ms steps
if (++time_1ms < 5) return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment