From fc566096de923e683805dcf45bfbd3910f795c7d Mon Sep 17 00:00:00 2001 From: John Arne Birkeland Date: Fri, 1 Mar 2013 11:24:36 +0100 Subject: [PATCH] AVR HAL: RCJitterTest example Used to test jitter on the PPM R/C input system. --- .../AP_HAL_AVR/examples/RCJitterTest/Makefile | 1 + .../examples/RCJitterTest/RCJitterTest.pde | 110 ++++++++++++++++++ .../examples/RCJitterTest/nocore.inoflag | 0 3 files changed, 111 insertions(+) create mode 100644 libraries/AP_HAL_AVR/examples/RCJitterTest/Makefile create mode 100644 libraries/AP_HAL_AVR/examples/RCJitterTest/RCJitterTest.pde create mode 100644 libraries/AP_HAL_AVR/examples/RCJitterTest/nocore.inoflag diff --git a/libraries/AP_HAL_AVR/examples/RCJitterTest/Makefile b/libraries/AP_HAL_AVR/examples/RCJitterTest/Makefile new file mode 100644 index 0000000000..f5daf25151 --- /dev/null +++ b/libraries/AP_HAL_AVR/examples/RCJitterTest/Makefile @@ -0,0 +1 @@ +include ../../../../mk/apm.mk diff --git a/libraries/AP_HAL_AVR/examples/RCJitterTest/RCJitterTest.pde b/libraries/AP_HAL_AVR/examples/RCJitterTest/RCJitterTest.pde new file mode 100644 index 0000000000..ce11513605 --- /dev/null +++ b/libraries/AP_HAL_AVR/examples/RCJitterTest/RCJitterTest.pde @@ -0,0 +1,110 @@ +#include +#include +#include +#include + +#include +#include + +#if CONFIG_HAL_BOARD == HAL_BOARD_APM2 +const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; +#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1 +const AP_HAL::HAL& hal = AP_HAL_AVR_APM1; +#endif + +uint16_t ppm_center[ 8 ]; +uint16_t ppm_min[ 8 ]; +uint16_t ppm_max[ 8 ]; +uint16_t ppm_delta[ 8 ]; +uint16_t ppm_mark[ 8 ]; + + +void setup (void) { + hal.console->printf_P(PSTR("\fRC input jitter test - Do not move sticks: \r\n")); + + hal.scheduler->delay(2000); + + for( uint8_t rep = 0; rep < 10; rep++ ) + { + for( uint8_t i = 0; i < 8; i++ ) + { + uint16_t ppm_tmp = hal.rcin->read( i ); + ppm_center[ i ] += ppm_tmp; + } + hal.scheduler->delay( 100 ); + } + + for( uint8_t i = 0; i < 8; i++ ) + { + uint16_t ppm_tmp = ppm_center[ i ] / 10; + ppm_center[ i ] = ppm_tmp; + ppm_min[ i ] = ppm_tmp; + ppm_max[ i ] = ppm_tmp; + ppm_delta[ i ] = 0; + } + +} + +void loop (void) { + + + static bool update = true; + static uint32_t time_trigger; + + for( uint8_t i = 0; i < 8; i++ ) + { + uint16_t ppm_tmp = hal.rcin->read( i ); + + // min? + if( ppm_tmp < ppm_min[ i ] ) + { + uint16_t delta_tmp = ppm_center[ i ] - ppm_tmp; + if( delta_tmp > ppm_delta[ i ] ) ppm_delta[ i ] = delta_tmp; + + ppm_min[ i ] = ppm_tmp; + ppm_mark[ i ] = ppm_tmp; + + update = true; + } + + // max? + if( ppm_tmp > ppm_max[ i ] ) + { + uint16_t delta_tmp = ppm_tmp - ppm_center[ i ]; + if( delta_tmp > ppm_delta[ i ] ) ppm_delta[ i ] = delta_tmp; + + ppm_max[ i ] = ppm_tmp; + ppm_mark[ i ] = ppm_tmp; + + update = true; + } + + } + + if( update && hal.scheduler->millis() > time_trigger ) + { + update = false; + time_trigger = hal.scheduler->millis() + 5000; + + //hal.console->printf_P( PSTR("%c%c%c\r\n"), 0x1B, 0x5B, 0x48 ); // Terminal home position + hal.console->printf_P( PSTR("--------------------------------------------\r\n") ); + for( uint8_t i = 0; i < 8; i++ ) + { + hal.console->printf_P( PSTR("ch%d: center:%d min:%d max:%d delta:%d"), + i + 1, ppm_center[ i ], ppm_min[ i ],ppm_max[ i ], ppm_delta[ i ] ); + + if( ppm_mark[ i ] > 0 ) + { + hal.console->printf_P( PSTR(" [%d]"), ppm_mark[ i ] ); + ppm_mark[ i ] = 0; + } + + hal.console->printf_P( PSTR(" \r\n") ); + } + } + + hal.scheduler->delay( 10 ); +} + +AP_HAL_MAIN(); + diff --git a/libraries/AP_HAL_AVR/examples/RCJitterTest/nocore.inoflag b/libraries/AP_HAL_AVR/examples/RCJitterTest/nocore.inoflag new file mode 100644 index 0000000000..e69de29bb2