Hi everyone,
I’m trying to measure a couple of low frequency signals (0-10000Hz) using input capture timers on F401RE. Currently I’m trying to port over the PWMInput example from STM32CubeF4 to work with Mbed, but haven’t any luck. Feeding a 2KHz signal to TIM4 Ch2 pin (PB_7), I don’t see my interrupt handler function getting triggered at all.
#include "mbed.h"
#define TIM_USR TIM4
#define TIM_USR_IRQ TIM4_IRQn
#define tim_irq TIM4_IRQHandler
DigitalOut myled(LED2);
Serial pc(SERIAL_TX, SERIAL_RX);
PwmOut pwm(PB_9);
TIM_HandleTypeDef mTimUserHandle;
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_IC_InitTypeDef sConfigIC;
TIM_MasterConfigTypeDef sMasterConfig;
__IO uint32_t period;
__IO uint32_t pulse;
void tim_init()
{
mTimUserHandle.Instance = TIM_USR;
mTimUserHandle.Init.Prescaler = 0;
mTimUserHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
mTimUserHandle.Init.Period = 65535;
mTimUserHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
mTimUserHandle.Init.RepetitionCounter = 0;
HAL_TIM_IC_Init(&mTimUserHandle);
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
sSlaveConfig.InputTrigger = TIM_TS_TI2FP2;
sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sSlaveConfig.TriggerPrescaler = TIM_ICPSC_DIV1;
sSlaveConfig.TriggerFilter = 0;
HAL_TIM_SlaveConfigSynchronization(&mTimUserHandle, &sSlaveConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&mTimUserHandle, &sConfigIC, TIM_CHANNEL_1);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
HAL_TIM_IC_ConfigChannel(&mTimUserHandle, &sConfigIC, TIM_CHANNEL_2);
//Enable interrupt
HAL_TIM_IC_Start_IT(&mTimUserHandle, TIM_CHANNEL_2);
HAL_TIM_IC_Start_IT(&mTimUserHandle, TIM_CHANNEL_1);
}
void tim_irq()
{
period = HAL_TIM_ReadCapturedValue(&mTimUserHandle, TIM_CHANNEL_2);
pulse = HAL_TIM_ReadCapturedValue(&mTimUserHandle, TIM_CHANNEL_1);
pc.printf("%d %d\n", period, pulse);
}
int main() {
tim_init();
pwm.period(0.0005); // 2KHz to test
pwm.write(0.5);
pc.printf("start\n");
while(1) {}
}
Are there anything missing with the way I’m setting things up?
Kind Regards,
Jon