i am using 2 gpt timer in hal layer 1timer for 1ms and 2nd one is for 1microsecond and i also use timer callback routine also..
now the thing is when i start the timer 2 for one micro second in timer 1 callback routine so my code is not work and curser goes in bsp_cfg handelr error
In reply to WarrenM:
In reply to niku:
In reply to Richard:
Hello Niku
So you want something like this:
Where the purple trace is being generated by the 1us interrupt callback function.
The code below does this. You will see that it is very similar to previous code example.
In the previous code example version I started GPT1 on an ELC event but I used an interrupt to stop the timer.
This version uses the same ELC event to start the timer GPT1 (the rising edge of GPT0 - yellow trace )
but I now use another ELC event to stop the timer (falling edge of GPT0)
Therefore, GPT1 will now run for GPT0 high period.
Hope this helps and is of interest.
Richard
/* HAL-only entry function */#include "hal_data.h"ssp_err_t ssp_err;void hal_entry(void){ /* TODO: add your own code here */ /* Open GPT0 - configured to generate 1ms PWN @ 50% duty */ ssp_err = g_gpt0.p_api->open(g_gpt0.p_ctrl, g_gpt0.p_cfg); if(SSP_SUCCESS != ssp_err) { __BKPT(1); } /* GPT0 GTIOCB0 has been enabled * Set the starting condition of this pin * Refer to Hardware Users Manual * 23.2.14 General PWM Timer I/O Control Register (GTIOR) * Table 23.5 Settings of GTIOA[4:0] and GTIOB[4:0] bits */ R_GPTA0->GTIOR_b.GTIOB = 0x6; /* Set initial output low - Output high at GTCCRB compare match - Output low at cycle end */ /* Open GPT1 - 1us interrupt generated on rising edge of PWM */ ssp_err = g_gpt1.p_api->open(g_gpt1.p_ctrl, g_gpt1.p_cfg); if(SSP_SUCCESS != ssp_err) { __BKPT(1); } /* Configure GPT1 to START on ELC_GPTB event. We will link GPT0 compare match B to ELC_GPTB */ R_GPTA1->GTSSR_b.SSELCB = 1; /* GPT1 can be started by ELC event */ /* Configure GPT1 to STOP on ELC_GPTH event. We will link GPT0 overflow to ELC_GPTB */ R_GPTA1->GTPSR_b.PSELCH = 1; /* GPT1 can be stoped by ELC event */ /* Link ELC_GPTB to GPT0 Compare Match B */ g_elc.p_api->linkSet(ELC_PERIPHERAL_GPT_B, ELC_EVENT_GPT0_CAPTURE_COMPARE_B); /* Link ELC_GPTH to GPT0 Overflow */ g_elc.p_api->linkSet(ELC_PERIPHERAL_GPT_H, ELC_EVENT_GPT0_COUNTER_OVERFLOW); /* Start GPT0 - PWM timer * GPT1 will be started automatically be GPT0 */ g_gpt0.p_api->start(g_gpt0.p_ctrl); while(1);}void cb_gpt1(timer_callback_args_t *p_args){ SSP_PARAMETER_NOT_USED(p_args); /* As an example, toggle an I/O pin to show interrupt occuring 1us * after the GPT0 rising edge */ static uint8_t toggle_p411 = 0; if( 0 == toggle_p411 ) { R_IOPORT4->PCNTR1 = 0x08000800; /* Set pin high / pin is output */ } else { R_IOPORT4->PCNTR1 = 0x00000800; /* Clear pin low / pin is output */ } toggle_p411 = (uint8_t)(1 - toggle_p411);}