cancel
Showing results for 
Search instead for 
Did you mean: 

generate pulse wave with stm32f10x and cmsis library

parisa
Senior
Posted on December 23, 2016 at 19:30

Hello

I'm supposed to generate pulse train with stm32f10x and cmsis library.

TIM_TimeBaseInitTypeDef TIMST;

 

TIMST.TIM_Prescaler=72;

 

TIMST.TIM_Period=1000;

 

TIMST.TIM_ClockDivision=TIM_CKD_DIV1;    

 

TIMST.TIM_CounterMode=    TIM_CounterMode_Up ;

 

TIM_TimeBaseInit(TIM2, &TIMST);

         TIM_OCInitTypeDef TIMCRC;

        TIMCRC.TIM_OCMode=TIM_OCMode_Toggle;

        TIMCRC.TIM_OCIdleState=TIM_OCIdleState_Reset;

        TIMCRC.TIM_OCNIdleState=TIM_OCNPolarity_Low;

        TIMCRC.TIM_OCPolarity=TIM_OCPolarity_High;

        TIMCRC.TIM_OCNPolarity=TIM_OCPolarity_Low;

        TIMCRC.TIM_OutputNState=TIM_OutputNState_Disable;

        TIMCRC.TIM_OutputState=TIM_OutputNState_Enable;

        TIMCRC.TIM_Pulse=

But I don't know how I can define Pulse variable value for specific output frequency.(Is this code correct? or I did some mistake? )

#stm32f10x #timer
2 REPLIES 2
Amel NASRI
ST Employee
Posted on December 26, 2016 at 17:46

Hi

Mohamadi.Parisa

‌,

Please precise what do you expect exactly as result?

Did you tried this code and it doesn't match what you need?

I recommend you to refer to theGeneral-purpose timer cookbook (

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/91/01/84/3f/7c/67/41/3f/DM00236305/files/DM00236pdf/jcr:content/translations/en.DM00236pdf

) : it explains various use cases related to timers and can be helpful for you to implement your own case.

-Amel-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

parisa
Senior
Posted on December 26, 2016 at 18:14

Thanks for your response.

Actually I want to create a square pulse (frequency <100khz) with Stm32f10x and timer output compare mode.I have seen different codes that they use PWM mode but I want to learn how can work in output compare mode with timers?

So I need to know how can I define Prescaler, Periode and Pulse variables for an specific output frequency? and where can I find simple code in output compare mode?

I haven't read time cookbook yet but maybe I will find my answer.