still timer

This commit is contained in:
2021-02-06 18:01:43 +01:00
parent 5832a107c3
commit 18d0cbe4c8
5 changed files with 31 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include <main.h>
#include <usart.h>
#include <spi.h>
#include <tim.h>
#include <PontCoopScheduler.h>
@ -47,6 +48,10 @@ void my_setup_2() {
// cmdHandlerInit();
schAdd(second_tick, NULL, 0, 60*1000);
HAL_TIM_IC_Start_IT(&mainsCnt, TIM_CHANNEL_1);
logMsg("Application running");
}
@ -78,3 +83,22 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) {
}
}
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
static uint8_t state = 0;
static uint32_t savedV = 0;
if (htim == &mainsCnt) {
uint32_t v = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
if (state == 0) {
show(DEBUG_2, ON);
savedV = v;
state = 1;
} else if (state == 1) {
show(DEBUG_2, OFF);
uint32_t captured = (savedV < v) ? (v - savedV) : ((htim->Init.Period - savedV) + v);
logMsg("CCR: %ld", captured);
state = 0;
} else {
state = 0;
}
}
}