cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract sensor values from PWM signal?

MStew.1
Associate III

Hi everyone. I connected the SDS011 Dust Sensor with my Nucleo WL55JC1 via UART and I am receiving my sensor data. According to the Sensor data sheet the values can be also provided as output in PWM form on the certain pin.

In order to achieve this I thought to configure a Timer as Input Capture Mode in CubeMX then with the PWM signal read and transfer the data with DMA.

This way I didnt need to use the CPU to compute the particles value as I did with the UART because its in the PWM.

However I am having a bit troubles to implement this successfully, I think I am missing something? Is my idea to use Input Capture Mode correct or the wrong way?

In the User Manual for the Description of STM32WL HAL and low-layer drivers I found the function HAL_TIM_IC_Start_DMA (Starts the TIM Input Capture measurement in DMA mode) and think this suits well for my usecase?

I appreciate any tips in the right direction, thank you.

0693W00000FC9btQAD.jpg

3 REPLIES 3
S.Ma
Principal

Well, first, uart has the benefit there is no precise clock or oscillator required. Reporting speed is same as pwm. PWM high duration is the value to measure with precise clock, so you may not use HSI. There are various way to measure a pulse width with one timer per input. To get the same precision as uart, better use 32 bit timer as free run, input capture on both edge of input signal, interrupt detect the pin level and knowing previous interrupt capture, substract to get high period. Ideally detect when there is missing pwm = out of range input = timer values invalid.

Manny
Associate III

You can use an gpio as interrupt(edge trigger), and on rising edge you can start a timer(or reload it to zero) and on falling edge you can note that time(use the timer value to calculate the pulse width). As the time of pulse is in millisecond, make sure that the timer don't overflow in the 1001ms pulse.

MStew.1
Associate III

Ok thanks for the answers. I will try and play around to get it run this way.