Toggle GPIO output on SCT?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle GPIO output on SCT?

1,499 Views
joren_joly
Contributor II

Hello,

I'm trying SCT timer for the first time, I would like to toggle pin 17 on the systemclock/10, but this code doesnt seem to work. Can anybody help me?

(I use the LPC824)

void SCT_Init(void){
/*The SCT operates as a unified 32-bit counter*/
LPC_SCT->CONFIG = (LPC_SCT->CONFIG & ~0x00060001) | 0x00000001;

LPC_SCT->MATCH[0].U = SystemCoreClock/10;
LPC_SCT->MATCHREL[0].U =SystemCoreClock/10;

LPC_SCT->EV[0].STATE =(1<<0);
LPC_SCT->EV[0].CTRL =(1<<12);

LPC_SCT->EV[1].STATE =(1<<0);
LPC_SCT->EV[1].CTRL =(1<<12);

LPC_SCT->OUT[0].SET =(1<<0);
LPC_SCT->OUT[0].CLR =(1<<1);

LPC_SCT->LIMIT_L =0x0003;
// LPC_SCT->CTRL_L &= ~(1<<2);
}

int main(void) {

// Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate();

printf("output from main clock is = %u \n", Chip_Clock_GetMainClockRate());
printf("output from system clock is = %u \n", Chip_Clock_GetSystemClockRate());

//set GPIO pin 12 as output
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT,0,12,1);
//set GPIO pin 12 low, this will let LED1 burn
Chip_GPIO_SetPinState(LPC_GPIO_PORT,0,12,false);

/*Assign SCT_out to board GPIO*/
Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O,17);

/* Initialize the SCT clock and reset the SCT */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT);
Chip_SYSCTL_PeriphReset(RESET_SCT);

/*Initialize SCT*/
SCT_Init();

/* Start the SCT counter by clearing Halt_L in the SCT control register */
Chip_SCT_ClearControl(LPC_SCT, SCT_CTRL_HALT_L);
}
return 0 ;
}

thanks!

Tags (2)
0 Kudos
Reply
4 Replies

1,330 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello Joren Joly

To configure the SCTimer I suggest you to use the SDK driver, in the driver you can find 2 functions that might be very useful for your application.

On one hand we have the function SCTIMER_CreateAndScheduleEvent() were you will be able to create an event that triggers every time your match happens.

 

To toggle the output the functions SCTIMER_SetupOutputSetAction() or SCTIMER_SetupOutputClearAction() will respond to the event you created with CreateAndScheduleEvent()

 

For more information I suggest you to check the sctimer_simple_pwm available at the sdk

https://mcuxpresso.nxp.com/en/welcome

 

Let me know if this is helpful. If you have more specific questions do not hesitate to ask me.

Best regards,

Omar

0 Kudos
Reply

1,330 Views
marek-trmac
NXP Employee
NXP Employee

Hi,

there is a peripheral tool allowing to configure initialization of the SDK drivers. The tool could help you to generate the code SCT.

Note: There is also Config tool allowing to configure clocks and Pins tool for pin routing.

Regards

Marek

Regards,
Marek
0 Kudos
Reply

1,330 Views
joren_joly
Contributor II

okay, which tool, so I can have a look? And this code should be kind of basic to do it coding wise, I'm just missing something, so if you could point me out my mistake that would help me so much! thanks!

0 Kudos
Reply

1,330 Views
marek-trmac
NXP Employee
NXP Employee

Hi Joren,

I'm not an expert for peripheral drivers, so I do not understand details of your code and cannot help. The code generated by the tools was tested, so if you use tools for configuration, the generated code should work (Then you can compare with your code).

Regards

Marek

Regards,
Marek
0 Kudos
Reply