Thanks for the response..I tried with the above changes but not getting the
require frequency of 0.5hz, with the reference of SDK code tried initially by
changing the configuration of unifiy bit to 32 bit counter too,I have attach the
latest change code, is anything need to be changed..?kindly suggest on this.
void SCT_Detection_Callback(void)
{
GPIO_PortToggle(GPIO, BLUE_LED_PORT, 1u << BLUE_LED_PIN);
widths = SCT0->COUNT;
SCT0->CTRL |= (1<<19);//clear counter
uint32_t CTRL_Enable_Event = SCT0->CTRL;
CTRL_Enable_Event &= (~(SCT_CTRL_HALT_H_MASK) ); //clear halt H bit
CTRL_Enable_Event |= SCT_CTRL_STOP_H_MASK; //set stop H bit
// SCT0->CTRL = CTRL_Enable_Event; //Write both changes at once
}
/*******************************************************************************
* Code
******************************************************************************/
/*!
* @brief Main function
*/
int main(void)
{
sctimer_config_t sctimerInfo;
uint32_t stateNumber;
uint32_t eventCounterL, eventCounterH;
uint32_t sctimerClock;
uint32_t matchValueL, matchValueH;
/* Board pin, clock, debug console init */
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_Select(BOARD_DEBUG_USART_CLK_ATTACH);
BOARD_InitPins();
BOARD_BootClockFRO30M();
BOARD_InitDebugConsole();
gpio_pin_config_t led_config = { kGPIO_DigitalOutput, 0, };
GPIO_PortInit(GPIO, BLUE_LED_PORT);
GPIO_PinInit(GPIO, BLUE_LED_PORT, BLUE_LED_PIN, &led_config);
if(SysTick_Config(SystemCoreClock / 100000U))
{
while(1)
{
}
}
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
sctimerClock = SCTIMER_CLK_FREQ;
/* Default configuration operates the counter in 32-bit mode */
SCTIMER_GetDefaultConfig(&sctimerInfo);
/* Switch to 16-bit mode */
sctimerInfo.enableCounterUnify = true ;//true[for 32 bit]
sprintf(txta, "%d ", sctimerInfo.enableCounterUnify);
LCD_Out(1,1,txta);
/* Calculate prescaler and match value for Counter L for 100ms interval */
matchValueL = MSEC_TO_COUNT(500U, sctimerClock);//changed values
sprintf(txtb, "%d ", matchValueL);
LCD_Out(2,1,txtb);
sctimerInfo.prescale_l = matchValueL / 65536;
matchValueL = matchValueL / (sctimerInfo.prescale_l + 1) - 1;
/* Calculate prescaler and match value for Counter H for 200ms interval */
matchValueH = MSEC_TO_COUNT(500U, sctimerClock);//changed values
sctimerInfo.prescale_h = matchValueH / 65536;
matchValueH = matchValueH / (sctimerInfo.prescale_h + 1) - 1;
/* Initialize SCTimer module */
SCTIMER_Init(SCT0, &sctimerInfo);
stateNumber = SCTIMER_GetCurrentState(SCT0);
/* Schedule a match event for Counter L every 0.1 seconds */
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_MatchEventOnly, matchValueL, 0, kSCTIMER_Counter_L,
&eventCounterL) == kStatus_Fail)
{
return -1;
}
/* Toggle first output when Counter L event occurs */
SCTIMER_SetupOutputToggleAction(SCT0, DEMO_FIRST_SCTIMER_OUT, eventCounterL);
/* Reset Counter L when Counter L event occurs */
SCTIMER_SetupCounterLimitAction(SCT0, kSCTIMER_Counter_L, eventCounterL);
/* Schedule a match event for Counter H every 0.2 seconds */
if (SCTIMER_CreateAndScheduleEvent(SCT0, kSCTIMER_MatchEventOnly, matchValueH, 0, kSCTIMER_Counter_H,
&eventCounterH) == kStatus_Fail)
{
return -1;
}
/* Toggle second output when Counter H event occurs */
SCTIMER_SetupOutputToggleAction(SCT0, DEMO_SECOND_SCTIMER_OUT, eventCounterH);//P1.20 WONT TOGGLE
/* Reset Counter H when Counter H event occurs */
SCTIMER_SetupCounterLimitAction(SCT0, kSCTIMER_Counter_H, eventCounterH);
SCTIMER_SetCallback(SCT0, sctimer_callback_table, eventCounterH);//kSCTIMER_Counter_H
SCTIMER_EnableInterrupts(SCT0,1<<eventCounterH);//kSCTIMER_Counter_H
NVIC_EnableIRQ(SCT0_IRQn);
/* Start the timer, use counter L as we are operating counter in 32-bit mode */
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_L);//D6 PIN WONT TOGGLE
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_H);//D5 PIN WONT TOGGLE
while (1)
{
}
}