新手上路
- 积分
- 42
- 金钱
- 42
- 注册时间
- 2020-4-24
- 在线时间
- 15 小时
|
2金钱
本帖最后由 lyzsuper 于 2020-4-24 15:28 编辑
想设计两个stm32f103系统使用外部8M的晶振,精度为10us的systick,同步后按同样的2ms周期运行能在1个小时内误差不超1ms,
目前简单一点先不同步,使用同时上电的方法进行同步测试,
但是测试发现一开始相差300us,每1分钟就会累积6ms的误差,是systick就是这样的还是我配置的问题?
由于我想做基于时基的无线跳频系统,所以需要时间同步,除了systick还有什么方案可以考虑的? 谢谢大家
测试的代码如下:
- #define PERIOD 2000
- #define TIME_ACCURACY 10
- #define TIME_PERIOD (PERIOD / TIME_ACCURACY)
- uint32_t systick_count = 0;
- uint32_t run_time_target;
- uint32_t count_target = 0;
- void GPIO_test_Init(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB,GPIO_Pin_12);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- GPIO_SetBits(GPIOB,GPIO_Pin_5);
- }
- void SysTick_Handler(void)
- {
- systick_count++;
- }
- int main(void)
- {
- SystemInit();
- SysTick_Config(SystemCoreClock / 1000000 * TIME_ACCURACY);
- GPIO_test_Init();
-
- run_time_target = systick_count + TIME_PERIOD;
- while(1){
- while(systick_count <= run_time_target){
- }
- run_time_target += TIME_PERIOD;
- GPIOB->ODR ^= ( uint32_t)GPIO_Pin_5;
- count_target++;
- if(count_target >= 500){
- count_target = 0;
- GPIOB->ODR ^= ( uint32_t)GPIO_Pin_12;
- }
- }
-
- }
复制代码
|
|