How to use the K64 pit to design the delay function?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to use the K64 pit to design the delay function?

1,092件の閲覧回数
zhailing
Contributor II

Hi

    I want to design a precise delay time;

for example:the stm32;

1.config the register  directly

void delay_ms(uint16_t ms) {  TIM6->PSC=35999;  TIM6->ARR=ms*2;  TIM6->CR1|=(1<<3);  TIM6->CR1|=0x1;  while((TIM6->SR&0X1)==0);  TIM6->SR=0; }


2.config the sdk
void TIM6_Delay_ms(uint16_t ms) {  /* 定义一个定时器基本定时初始化结构体变量 */  TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;    /* 时钟预分频数为36000,在主频72M时,计数器每500us加1*/  TIM_TimeBaseInitStruct.TIM_Prescaler= 35999;    /* 自动重装载寄存器值 */  TIM_TimeBaseInitStruct.TIM_Period=ms*2;    /* 把上面的值配置到寄存器 */  TIM_TimeBaseInit(TIM6, &TIM_TimeBaseInitStruct);    /* 设置定时时间到了以后停止定时器计数 */  TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single);    /* 清除SR中的UIF标志 */  TIM_ClearFlag(TIM6, TIM_IT_Update);    /* 打开定时器6 */  TIM_Cmd(TIM6, ENABLE);    /* 检测定时时间是否到来 */  while(TIM_GetFlagStatus(TIM6, TIM_IT_Update)==RESET);   /* 软件清除更新标志 */  TIM_ClearFlag(TIM6, TIM_IT_Update); }

How to config the register of k64?

Thangks and best regards 

zhai

0 件の賞賛
3 返答(返信)

886件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Zhai ling,

   About the K64 pit usage, please refer to our K64 sample code, which can be download from this link:

Welcome to Kinetis Expert | Kinetis Expert

 Click build an SDK, then select the board as FRDM-K64F120M, generate the code and download it, you can find the PIT code in folder:

SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\pit

pastedImage_1.png

The code in red frame can realize 1S PIT delay.

 

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

886件の閲覧回数
zhailing
Contributor II

Hi Kerry

   I have solute the qustion!

Thanks very much!

zhai

0 件の賞賛

886件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Zhai ling,

   If your question is solved, please help to mark the correct answer to close this question.

   Thank you and have a nice day!


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------