请问一下FR8016H硬件定时器该怎么调呢?



  • 我照抄SDK里提供的example,好像不管用

    	#include "driver_timer.h"
    	static uint32_t tick0 = 0;
    	static uint32_t tick1 = 0;
    	static uint8_t tim0_run_num = 0;
    	__attribute__((section("ram_code"))) void timer0_isr_ram(void)
    	{
    		timer_clear_interrupt(TIMER0);
    		co_delay_10us(1);
    		//timer_reload(TIMER0);
    		if(tick0>10000) //1s
    		{
    			tick0 = 0;
    			tim0_run_num++;
    			if(tim0_run_num >= 4)
    				timer_stop(TIMER0);
    			co_printf("hwt0_us:%d,%d\r\n",timer_get_current_value(TIMER0),timer_get_load_value(TIMER0));
    		}
    		else
    			tick0++;
    	}
    	__attribute__((section("ram_code"))) void timer1_isr_ram(void)
    	{
    		timer_clear_interrupt(TIMER1);
    		co_delay_10us(1);
    		//timer_reload(TIMER1);
    		if(tick1>20000) //4s
    		{
    			timer_stop(TIMER1);
    			co_printf("hwt1_us:%d,%d\r\n",timer_get_current_value(TIMER1),timer_get_load_value(TIMER1));
    		}
    		else
    			tick1++;
    	}
    
    	void demo_timer(void)
    	{
    		co_printf("hardware timer demo\r\n");
    
    		tick1 = 0;
    		tick0 = 0;
    		tim0_run_num = 0;
    		timer_init(TIMER0,100,TIMER_PERIODIC);
    		timer_run(TIMER0);
    
    		timer_init(TIMER1,200,TIMER_PERIODIC);
    		timer_run(TIMER1);
    
    		NVIC_SetPriority(TIMER0_IRQn, 2);
    		NVIC_EnableIRQ(TIMER0_IRQn);
    
    		NVIC_SetPriority(TIMER1_IRQn, 2);
    		NVIC_EnableIRQ(TIMER1_IRQn);
    	}
    

    请问各位大佬,定时器是这么用的吗?



  • #include "driver_timer.h"
    static uint32_t tick0 = 0;
    static uint32_t tick1 = 0;
    static uint8_t tim0_run_num = 0;
    attribute((section("ram_code"))) void timer0_isr_ram(void)
    {
    timer_clear_interrupt(TIMER0);
    co_delay_10us(1);
    //timer_reload(TIMER0);
    if(tick0>10000) //1s
    {
    tick0 = 0;
    tim0_run_num++;
    if(tim0_run_num >= 4)
    timer_stop(TIMER0);
    co_printf("hwt0_us:%d,%d\r\n",timer_get_current_value(TIMER0),timer_get_load_value(TIMER0));
    }
    else
    tick0++;
    }
    attribute((section("ram_code"))) void timer1_isr_ram(void)
    {
    timer_clear_interrupt(TIMER1);
    co_delay_10us(1);
    //timer_reload(TIMER1);
    if(tick1>20000) //4s
    {
    timer_stop(TIMER1);
    co_printf("hwt1_us:%d,%d\r\n",timer_get_current_value(TIMER1),timer_get_load_value(TIMER1));
    }
    else
    tick1++;
    }

    void demo_timer(void)
    {
    co_printf("hardware timer demo\r\n");

    tick1 = 0;
    tick0 = 0;
    tim0_run_num = 0;
    timer_init(TIMER0,100,TIMER_PERIODIC);
    timer_run(TIMER0);
    
    timer_init(TIMER1,200,TIMER_PERIODIC);
    timer_run(TIMER1);
    
    NVIC_SetPriority(TIMER0_IRQn, 2);
    NVIC_EnableIRQ(TIMER0_IRQn);
    
    NVIC_SetPriority(TIMER1_IRQn, 2);
    NVIC_EnableIRQ(TIMER1_IRQn);
    

    }