查看: 802|回复: 0
收起左侧

关于CH32V103C8T6和CH32V307VCT6的延时函数区别---延时差异

[复制链接]

  离线 

  • TA的每日心情
    飞起
    2022-10-5 00:04
  • 签到天数: 2 天

    [LV.1]

    发表于 2022-3-28 19:37:16 | 显示全部楼层 |阅读模式

    有人预言,RISC-V或将是继Intel和Arm之后的第三大主流处理器体系。欢迎访问全球首家只专注于RISC-V单片机行业应用的中文网站

    您需要 登录 才可以下载或查看,没有帐号?立即注册

    x
    最近调试CH32V103C8T6时,发现CH32V103C8T6的延时函数输入1000,可以延时出1s,但是CH32V307VCT6输入延时1000,却延时超过1s


    如下是CH32V103C8T6的延时函数代码,包括延时Ms和Us。执行Delay_Ms (1000)时可以看到延时实现1s。
    1. /********************************** (C) COPYRIGHT  *******************************
    2. * File Name          : debug.c
    3. * Author             : WCH
    4. * Version            : V1.0.0
    5. * Date               : 2020/04/30
    6. * Description        : This file contains all the functions prototypes for UART
    7. *                      Printf , Delay functions.
    8. *******************************************************************************/
    9. #include "debug.h"

    10. static uint8_t  p_us=0;
    11. static uint16_t p_ms=0;

    12. /*******************************************************************************
    13. * Function Name  : Delay_Init
    14. * Description    : Initializes Delay Funcation.
    15. * Input          : None
    16. * Return         : None
    17. *******************************************************************************/
    18. void Delay_Init(void)
    19. {
    20.         p_us=SystemCoreClock/8000000;
    21.         p_ms=(uint16_t)p_us*1000;
    22. }

    23. /*******************************************************************************
    24. * Function Name  : Delay_Us
    25. * Description    : Microsecond Delay Time.
    26. * Input          : n:Microsecond number.
    27. * Return         : None
    28. *******************************************************************************/
    29. void Delay_Us(uint32_t n)
    30. {
    31.         uint32_t i;

    32.         SysTick->CTLR = 0;
    33.         i = (uint32_t)n*p_us;

    34.         SysTick->CNTL0 = 0;
    35.         SysTick->CNTL1 = 0;
    36.         SysTick->CNTL2 = 0;
    37.         SysTick->CNTL3 = 0;
    38.         SysTick->CTLR = 1;

    39.   while((*(__IO uint32_t*)0xE000F004) <= i);

    40. }

    41. /*******************************************************************************
    42. * Function Name  : Delay_Ms
    43. * Description    : Millisecond Delay Time.
    44. * Input          : n:Millisecond number.
    45. * Return         : None
    46. *******************************************************************************/
    47. void Delay_Ms (uint32_t n)
    48. {
    49.         uint32_t i;

    50.         SysTick->CTLR = 0;
    51.         i = (uint32_t)n*p_ms;

    52.         SysTick->CNTL0 = 0;
    53.         SysTick->CNTL1 = 0;
    54.         SysTick->CNTL2 = 0;
    55.         SysTick->CNTL3 = 0;
    56.         SysTick->CTLR = 1;

    57.   while((*(__IO uint32_t*)0xE000F004) <= i);
    58. }
    复制代码


    如下是CH32V307VCT6函数代码,包括延时Ms和Us。执行Delay_Ms (1000)时可以看到延时实现已经超过1s,感觉延时了很久。
    1. /********************************** (C) COPYRIGHT  *******************************
    2. * File Name          : debug.c
    3. * Author             : WCH
    4. * Version            : V1.0.0
    5. * Date               : 2021/06/06
    6. * Description        : This file contains all the functions prototypes for UART
    7. *                      Printf , Delay functions.
    8. *******************************************************************************/
    9. #include "debug.h"

    10. static uint8_t  p_us=0;
    11. static uint16_t p_ms=0;

    12. /*******************************************************************************
    13. * Function Name  : Delay_Init
    14. * Description    : Initializes Delay Funcation.
    15. * Input          : None
    16. * Return         : None
    17. *******************************************************************************/
    18. void Delay_Init(void)
    19. {
    20.         p_us=SystemCoreClock/8000000;
    21.         p_ms=(uint16_t)p_us*1000;
    22. }

    23. /*******************************************************************************
    24. * Function Name  : Delay_Us
    25. * Description    : Microsecond Delay Time.
    26. * Input          : n:Microsecond number.
    27. * Return         : None
    28. *******************************************************************************/
    29. void Delay_Us(uint32_t n)
    30. {
    31.     uint32_t i;

    32.     SysTick->CTLR = (1<<4);
    33.     i = (uint32_t)n*p_us;

    34.     SysTick->CMP = i;
    35.     SysTick->CTLR |= (1<<5)|(1<<0);

    36.     while((SysTick->SR & (1<<0)) != (1<<0));
    37.     SysTick->SR &= ~(1<<0);
    38. }

    39. /*******************************************************************************
    40. * Function Name  : Delay_Ms
    41. * Description    : Millisecond Delay Time.
    42. * Input          : n:Millisecond number.
    43. * Return         : None
    44. *******************************************************************************/
    45. void Delay_Ms(uint32_t n)
    46. {
    47.     uint32_t i;

    48.     SysTick->CTLR = (1<<4);
    49.     i = (uint32_t)n*p_ms;

    50.     SysTick->CMP = i;
    51.     SysTick->CTLR |= (1<<5)|(1<<0);

    52.     while((SysTick->SR & (1<<0)) != (1<<0));
    53.     SysTick->SR &= ~(1<<0);
    54. }
    复制代码



    同样的接口函数,为何不一样结果?函数内部都在对CTLR操作,还没看具体而这寄存器差异,看着有区别,CH32V307VCT6目前是144MHz,CH32V103C8T6目前是72MHz。




    上一篇:【CH32V307VCT6】通信端口之音频接口IIS/I2S介绍
    下一篇:【CH32V307VCT6】原理图_最小系统核心板V1
    RISCV作者优文
    全球首家只专注于RISC-V单片机行业应用的中文网站
    回复

    使用道具 举报

    高级模式
    B Color Image Link Quote Code Smilies

    本版积分规则

    关闭

    RISC-V单片机中文网上一条 /2 下一条


    版权及免责声明|RISC-V单片机中文网 |网站地图

    GMT+8, 2024-3-29 15:42 , Processed in 0.408445 second(s), 43 queries .

    快速回复 返回顶部 返回列表