From 0b0fb6f88f6851842e89f19129b0dc535f41dcbc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 1 Apr 2011 08:45:34 +0000 Subject: ICU driver functional. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2857 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32/PWM/main.c | 23 +++++++++++++++++++++++ testhal/STM32/PWM/mcuconf.h | 4 ++-- testhal/STM32/PWM/readme.txt | 6 ++++-- 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'testhal/STM32') diff --git a/testhal/STM32/PWM/main.c b/testhal/STM32/PWM/main.c index ef08b792c..c89b71988 100644 --- a/testhal/STM32/PWM/main.c +++ b/testhal/STM32/PWM/main.c @@ -46,6 +46,25 @@ static PWMConfig pwmcfg = { 0 }; +icucnt_t last_width, last_period; + +static void icuwidthcb(ICUDriver *icup) { + + last_width = icuGetWidthI(icup); +} + +static void icuperiodcb(ICUDriver *icup) { + + last_period = icuGetPeriodI(icup); +} + +static ICUConfig icucfg = { + ICU_INPUT_ACTIVE_HIGH, + 10000, /* 10KHz ICU clock frequency. */ + icuwidthcb, + icuperiodcb +}; + /* * Application entry point. */ @@ -71,6 +90,8 @@ int main(void) { */ pwmStart(&PWMD1, &pwmcfg); palSetPadMode(IOPORT1, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL); + icuStart(&ICUD4, &icucfg); + icuEnable(&ICUD4); chThdSleepMilliseconds(2000); /* @@ -97,6 +118,8 @@ int main(void) { */ pwmDisableChannel(&PWMD1, 0); pwmStop(&PWMD1); + icuDisable(&ICUD4); + icuStop(&ICUD4); palSetPad(IOPORT3, GPIOC_LED); /* diff --git a/testhal/STM32/PWM/mcuconf.h b/testhal/STM32/PWM/mcuconf.h index 17929817f..bd96de17b 100644 --- a/testhal/STM32/PWM/mcuconf.h +++ b/testhal/STM32/PWM/mcuconf.h @@ -78,9 +78,9 @@ * ICU driver system settings. */ #define STM32_ICU_USE_TIM1 FALSE -#define STM32_ICU_USE_TIM2 TRUE +#define STM32_ICU_USE_TIM2 FALSE #define STM32_ICU_USE_TIM3 FALSE -#define STM32_ICU_USE_TIM4 FALSE +#define STM32_ICU_USE_TIM4 TRUE #define STM32_ICU_USE_TIM5 FALSE #define STM32_ICU_TIM1_IRQ_PRIORITY 7 #define STM32_ICU_TIM2_IRQ_PRIORITY 7 diff --git a/testhal/STM32/PWM/readme.txt b/testhal/STM32/PWM/readme.txt index 4c3fdf2fa..97476205d 100644 --- a/testhal/STM32/PWM/readme.txt +++ b/testhal/STM32/PWM/readme.txt @@ -1,5 +1,5 @@ ***************************************************************************** -** ChibiOS/RT HAL - PWM driver demo for STM32. ** +** ChibiOS/RT HAL - PWM/ICU driver demo for STM32. ** ***************************************************************************** ** TARGET ** @@ -8,7 +8,9 @@ The demo will on an Olimex STM32-P103 board. ** The Demo ** -The application demonstrates the use of the STM32 PWM driver. +The application demonstrates the use of the STM32 PWM and ICU drivers. Pins +PA8 and PB6 must be connected in order to trigger the ICU input with the +PWM output. The ICU unit will measure the generated PWM. ** Build Procedure ** -- cgit v1.2.3