原子哥delay_ms(1000)在刚画的STM32F103C8T6板子上面不准

2019-07-20 23:37发布

如图,延时1S实测7.2S,代码是拷贝的MINI的,未做修改。 [mw_shl_code=c,true]static u8 fac_us=0; static u16 fac_ms=0; #ifdef OS_CRITICAL_METHOD void SysTick_Handler(void) { OSIntEnter(); //???????? OSTimeTick(); //?÷??ucos???±??·??????ò OSIntExit(); //??·??????????í???? } #endif void delay_init() { #ifdef OS_CRITICAL_METHOD u32 reload; #endif SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); fac_us=SystemCoreClock/8000000; #ifdef OS_CRITICAL_METHOD . reload=SystemCoreClock/8000000; reload*=1000000/OS_TICKS_PER_SEC fac_ms=1000/OS_TICKS_PER_SEC; SysTick->CTRL|=SysTick_CTRL_TICKINT_Msk; SysTick->LOAD=reload; SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; #else fac_ms=(u16)fac_us*1000; #endif } #ifdef OS_CRITICAL_METHOD void delay_us(u32 nus) { u32 ticks; u32 told,tnow,tcnt=0; u32 reload=SysTick->LOAD; //LOAD???? ticks=nus*fac_us; //?è?????????? tcnt=0; told=SysTick->VAL; //???????±???????÷?? while(1) { tnow=SysTick->VAL; if(tnow!=told) { if(tnow<told)tcnt+=told-tnow;//????×???????SYSTICK?????????????????÷????????. else tcnt+=reload-tnow+told; told=tnow; if(tcnt>=ticks)break;//?±??????/?????????????±??,?ò????. } }; } //???±nms //nms:?????±??ms?? void delay_ms(u16 nms) { if(OSRunning==TRUE)//????os?????????? { if(nms>=fac_ms)//???±???±???ó??ucos??×????±?????? { OSTimeDly(nms/fac_ms);//ucos???± } nms%=fac_ms; //ucos??????·¨?á?©???????????±??,???????¨·??????± } delay_us((u32)(nms*1000)); //???¨·??????±,???±ucos??·¨?????÷??. } #else//????ucos?± //???±nus //nus???????±??us??. void delay_us(u32 nus) { u32 temp; SysTick->LOAD=nus*fac_us; //?±?????? SysTick->VAL=0x00; //?????????÷ SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //???????? do { temp=SysTick->CTRL; } while(temp&0x01&&!(temp&(1<<16)));//?????±?????? SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //??±??????÷ SysTick->VAL =0X00; //?????????÷ } //???±nms //×???nms??·??§ //SysTick->LOAD??24???????÷,?ù??,×??ó???±??: //nms<=0xffffff*8*1000/SYSCLK //SYSCLK??????Hz,nms??????ms //??72M??????,nms<=1864 void delay_ms(u16 nms) { u32 temp; SysTick->LOAD=(u32)nms*fac_ms;//?±??????(SysTick->LOAD??24bit) SysTick->VAL =0x00; //?????????÷ SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //???????? do { temp=SysTick->CTRL; } while(temp&0x01&&!(temp&(1<<16)));//?????±?????? SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //??±??????÷ SysTick->VAL =0X00; //?????????÷ } #endif [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
13条回答
lued
1楼-- · 2019-07-22 00:04
回复【4楼】正点原子:
---------------------------------
恩,SWD仿真,我是怀疑时钟问题,试了一下for延时,走1M个数大概用0.6S
正点原子
2楼-- · 2019-07-22 01:12
 精彩回答 2  元偷偷看……
lued
3楼-- · 2019-07-22 02:37
 精彩回答 2  元偷偷看……
正点原子
4楼-- · 2019-07-22 05:32
回复【9楼】lued:
---------------------------------
没遇到过,我也用过C8T6,横正常。
zds晴天依旧
5楼-- · 2019-07-22 09:37
我现在也遇到了跟你差不多的问题啊 后来楼主解决了没??
chijt
6楼-- · 2019-07-22 12:43
外部晶振没起振

一周热门 更多>