From 06b016b87936bd2afe8831b82e09088244ddb206 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Tue, 30 Aug 2011 18:15:28 +0200 Subject: [PATCH] Moved to new value format on model.stick. Used to be float 0..1, is not float -100 to 100, plus a series of other fixes: Updated process_inputs() to the new values Added dual-rate math to process_inputs() Updated the ISR_Timer to reflect the new value format, and added an extra sanity check Added raw values to model datastruct for debugging Added dumping of raw value to serial-dumping. Tested tuning of PPM timing const's, may still be glitchy.. Moved the calibrate-trigger during startup, it did not get triggered after the change to active low logic Removed a for-loop-limit-bug causing incorrect/invalid values for input_cal.max[0] and model.stick[0] Changed the calibrate routine to use one int less, less code space and cycles. --- source/RCTXDuino/RCTXDuino.pde | 102 ++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/source/RCTXDuino/RCTXDuino.pde b/source/RCTXDuino/RCTXDuino.pde index b6c8d26..5d81bc1 100644 --- a/source/RCTXDuino/RCTXDuino.pde +++ b/source/RCTXDuino/RCTXDuino.pde @@ -17,6 +17,7 @@ struct model_t { int channels; // How many channels should PPM generate for this model ... float stick[8]; // The (potentially recalc'ed) value of stick/input channel. + int raw[8]; boolean rev[8]; int dr[8]; // The Dual-rate array uses magic numbers :P /* dr[0] = Input channel #1 of 2 for D/R switch #1. 0 means off, 1-4 valid values. @@ -52,10 +53,10 @@ volatile bool do_channel = true; // Is next operation a channel or a sepa // The timing here (and/or in the ISR) needs to be tweaked to provide valid // RC PPM signals accepted by standard RC RX'es and the Microcopter... -#define framelength 21500 // Max length of frame -#define seplength 400 // Lenght of a channel separator -#define chmax 1700 // Max lenght of channel pulse -#define chmin 600 // Min length of channel +#define framelength 21000 // Max length of frame +#define seplength 300 // Lenght of a channel separator +#define chmax 1550 // Max lenght of channel pulse +#define chmin 620 // Min length of channel #define chwidht (chmax - chmin)// Useable time of channel pulse // ----------------- Menu/IU related stuffs -------------------- @@ -137,9 +138,6 @@ void setup(){ Serial.println("Starting...."); delay(500); read_settings(); - scan_keys(); - if ( keys[KEY_UP]) - calibrate(); pinMode(A5, OUTPUT); // PPM output pin do_channel = false; @@ -154,6 +152,9 @@ void setup(){ // Unfortunately the interrupt mode is unusable in this scenario, but digital I/O works :P pinMode(A2, INPUT); digitalWrite(A2, HIGH); + scan_keys(); + if ( !keys[KEY_UP]) + calibrate(); // Debugging: how long does the main loop take on avg... t = micros(); @@ -165,7 +166,7 @@ void setup(){ // and this "default model values" should probably be moved // out to a section of read_settings when handling "new model", or // to a separate model_defaults function... - model.channels = 8; + model.channels = 6; model.rev[0] = model.rev[1] = model.rev[2] = model.rev[3] = model.rev[4] = model.rev[5] = model.rev[6] = model.rev[7] = false; model.dr[0] = model.dr[1] = model.dr[2] = model.dr[3] = 0; @@ -251,7 +252,6 @@ void mplx_select(int pin) void calibrate() { int i, r0, r1, r2, adc_in; - int calcount = 0; int num_calibrations = 200; lcd.clear(); @@ -260,13 +260,13 @@ void calibrate() lcd.print("their extremes.."); Serial.print("Calibration. Move all controls to their extremes."); - for (i=0; i< MAX_INPUTS; i++) { + for (i=0; i