cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103 pwm input to read as5048 pwm signal

domanski0karol
Associate III
Posted on October 13, 2016 at 10:30

Hi, I would like to read pwm output from as5048 encoder and I dont know how to do it. I understand this pwm frame, but how I may read output pwm step by step?

http://ams.com/eng/content/download/438523/1341157/143015 page 27.
3 REPLIES 3
Posted on October 13, 2016 at 14:52

So couldn't you use a TIM in PWM Input Mode with a minimal prescaler, and CH1/CH2 providing period/duty. Confirm the period matches 1 KHz, and check duty and divide down into 4096 points. ie check min/max points, and scale

Review other PWM Input examples..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
domanski0karol
Associate III
Posted on October 14, 2016 at 10:49

I do something like this, it is proper way to read pwm signal from encoder?

void TIMERS_Configuration(void) {

TIM_ICInitTypeDef TIM_ICInitStructure;

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; // _Falling

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

TIM_ICInitStructure.TIM_ICFilter = 0x0;

TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

TIM_Cmd(TIM3, ENABLE);

TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);

}

void NVIC_Configuration(void) {

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

float IC2Value, DutyCycle, Frequency;

void TIM3_IRQHandler(void) {

TIM_ClearITPendingBit(TIM3, TIM_IT_CC2);

IC2Value = TIM_GetCapture2(TIM3);

if (IC2Value != 0) {

DutyCycle = (TIM_GetCapture1(TIM3) * 100) / IC2Value;

Frequency = SystemCoreClock / IC2Value;

} else {

DutyCycle = 0;

Frequency = 0;

}

}

Walid FTITI_O
Senior II
Posted on October 14, 2016 at 18:53

Hi, 

Try to preceed like the ready-to-use example ''TIM_InputCapture'' in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef1.html

at this path:  STM32Cube_FW_F1_V1.4.0\Projects\STM3210E_EVAL\Examples\TIM\TIM_InputCapture

If you are using Standard peripheral libray , it willl be the ''InputCapture'' example at this path:  STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\TIM\InputCapture

-Hannibal-