From e5df688262c23021b4caffe46db7565470b40ce9 Mon Sep 17 00:00:00 2001 From: key Date: Sun, 27 Mar 2022 17:21:46 +0200 Subject: [PATCH] Implementation of time output compare is suscessful --- bsl/csl/interfaces/timer.h | 4 ++-- bsl/csl/stm32f042/Src/timer.c | 8 ++++---- main.cpp | 17 ++++++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/bsl/csl/interfaces/timer.h b/bsl/csl/interfaces/timer.h index e6afa39..b37edba 100644 --- a/bsl/csl/interfaces/timer.h +++ b/bsl/csl/interfaces/timer.h @@ -153,14 +153,14 @@ void timerInitPwm( timerNo_t timer, * @param mode The desired output compare mode * @param timerIoChannel The internal Timer Capture compare channel to be used. * @param pinNo The desired Pin Number to be used as outpujt - * @param alternate The Alternate funtion No for the given Pin + * @param altFuntion The Alternate funtion No for the given Pin * @param polarity Sets the the given Pin */ void timerInitOutputCompare( timerNo_t timer, timerOutputCompareMode_t mode, uint8_t timerIoChannel, pinNo_t pinNo, - uint16_t alternate, + uint16_t altFunction, uint8_t polarity); /*! * @brief Set the outoreload value of the timer diff --git a/bsl/csl/stm32f042/Src/timer.c b/bsl/csl/stm32f042/Src/timer.c index 7bc9bfb..2646abd 100644 --- a/bsl/csl/stm32f042/Src/timer.c +++ b/bsl/csl/stm32f042/Src/timer.c @@ -101,17 +101,17 @@ void timerInitCounter ( timerNo_t timer, timerSetAutoReload(timer, autoReload); } -void timerConfigOutputCompare( timerNo_t timer, +void timerInitOutputCompare( timerNo_t timer, timerOutputCompareMode_t mode, uint8_t timerIoChannel, pinNo_t pinNo, - uint16_t alternate, + uint16_t altFunction, uint8_t polarity) { timerStop(timer); - pinSetAlternate(pinNo,alternate); + pinSetMode(pinNo,alternate); + pinSetAlternate(pinNo,altFunction); - switch(timerIoChannel) { case 1: diff --git a/main.cpp b/main.cpp index 84f3638..80a8821 100644 --- a/main.cpp +++ b/main.cpp @@ -20,6 +20,13 @@ void timer_test(timerNo_t timer, pinNo_t pin) pinWrite(pin,0); } +void timer_capture_compare_test(timerNo_t timer) +{ + timerInitCounter(timer, 4000, 999, downCounting); + // We use pin PA3 (Arduino header A2) + timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0); + timerSart(timer); +} int main(int argc, char *argv[]) @@ -58,16 +65,8 @@ int main(int argc, char *argv[]) pinWrite(pinB3,0); - for (i = 0 ; i < MAX_TIMER_CHANNEL_COUNT; i++ ) - { - print_Usart(usart2, const_cast("Testing Timer :")); - usartSendChar(usart2, i+48); - print_Usart(usart2, const_cast("\r\n")); - timer_test(timers[i], pinB3); - print_Usart(usart2, const_cast("Testing Completed \r\n\r\n")); - delayMs(100); - } + timer_capture_compare_test(timer_2); print_Usart(usart2, const_cast("All is working fine \r\n")); while(1)