This commit is contained in:
2021-02-07 19:13:09 +01:00
parent a2fe201fb2
commit 07a918d8c3

View File

@ -28,9 +28,25 @@ void my_errorHandler() {
show(LED_RED, ON); show(LED_RED, ON);
} }
uint32_t mainsCntSum = 0;
uint32_t mainsCntCnt = 0;
void second_tick(void *handle) { void second_tick(void *handle) {
uint32_t tmpSum = 0;
uint32_t tmpCnt = 0;
HAL_NVIC_DisableIRQ(TIM1_CC_IRQn);
tmpSum = mainsCntSum;
mainsCntSum = 0;
tmpCnt = mainsCntCnt;
mainsCntCnt = 0;
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
uint32_t cnt = tmpSum / tmpCnt;
double f = 1.0 / ((double)cnt) * 1.0e6;
t_seconds *seconds = wizGetSeconds(); t_seconds *seconds = wizGetSeconds();
coloredMsg(LOG_GREEN, "Tick %d %lu %lu", seconds->valid, seconds->missedUpdates, seconds->seconds); coloredMsg(LOG_GREEN, "Tick %f %d %lu %lu", f, seconds->valid, seconds->missedUpdates, seconds->seconds);
} }
@ -96,8 +112,10 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
} else if (state == 1) { } else if (state == 1) {
show(DEBUG_2, OFF); show(DEBUG_2, OFF);
uint32_t captured = (savedV < v) ? (v - savedV) : ((htim->Init.Period - savedV) + v); uint32_t captured = (savedV < v) ? (v - savedV) : ((htim->Init.Period - savedV) + v);
double f = 1.0 / ((double)captured) * 1.0e6; //double f = 1.0 / ((double)captured) * 1.0e6;
logMsg("CCR: %ld, %f", captured, f); //logMsg("CCR: %ld, %f", captured, f);
mainsCntSum += captured;
mainsCntCnt += 1;
state = 0; state = 0;
} else { } else {
state = 0; state = 0;