AnsweredAssumed Answered

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

Question asked by zhai ling on Mar 7, 2017
Latest reply on Mar 13, 2017 by Kerry Zhou

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

Outcomes