SCTimer0 with LPC11U66

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SCTimer0 with LPC11U66

623 次查看
Mr_Damian
Contributor I

Mr_Damian_0-1721634591185.png

I'm using the LPC11U66 and I'm trying to turn on a different RGB led every second. In order to turn on the led, I need to set the pin low to sink the current. The timings are correct.

The problem that I'm having is I can set the pins low, but I can't set them high to turn a specific led off, until the whole sequence is done. The led sequence should be:

Green led, Red led, Blue led, but actually I'm get mixture of colours as the led that should be off, aren't.

I was wondering if there is a setting that I'm missing ?

My code:

#include <stdint.h>
#include <chip.h>
#include "chip.h"
#include "sct_11u6x.c"
#include "iocon_11u6x.c"
 
 
 
    const uint32_t blueLedPin = 13U;
    const uint32_t greenLedPin = 2U;
    const uint32_t redLedPin = 7U;
 
    static uint32_t event;
    static uint32_t state;
    static uint32_t counter;
 
/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/
 
/* PWM cycle time - time of a single PWM sweep */
#define PWMCYCLERATE (120 - 1)
 
/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/
 
/*****************************************************************************
 * Private functions
 ****************************************************************************/
 
 
 
/*****************************************************************************
 * Public functions
 ****************************************************************************/
 
 
 
/**
 * @brief Application main program
 * @return Nothing (This function will not return)
 */
void LedPwm_ConfigureSctimer0(void)
{
 
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SCT0_1);
Chip_SYSCTL_PeriphReset(RESET_SCT0);
Chip_SCT_Init(LPC_SCT0);
 
 
Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 2, (IOCON_FUNC3 | IOCON_DIGMODE_EN)); // Green LED SCT0_OUT1
Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 7, (IOCON_FUNC2 | IOCON_DIGMODE_EN)); // Red LED SCT0_OUT2
Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 13, (IOCON_FUNC2 | IOCON_DIGMODE_EN)); // Blue LED SCT0_OUT3
 
LPC_SCT0->OUTPUT = (1 << 1) | (1 << 2) | (1 << 3);
 
 
/* Configure the SCT as a 32bit counter using the bus clock */
LPC_SCT0->CONFIG = SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK | SCT_CONFIG_NORELOADL_U | (1 << 17);
 
LPC_SCT0->CTRL_L |=  (1 << 1) | (1 << 3) | (PWMCYCLERATE << 5) ; //  100,000 Khz
 
 
  // Select events that will start the counter 
   LPC_SCT0->START = (1 << 0) ;  // Start counter on event 0
 
 
 
 
/* Setup for match mode */
LPC_SCT0->REGMODE_L = 0;
 
LPC_SCT0 -> OUTPUTDIRCTRL = 0;
 
 
 
LPC_SCT0->MATCH[1].U = 100000 - 1; // 1 seconds
LPC_SCT0->MATCH[2].U = 200000 - 1; // 1 seconds
LPC_SCT0->MATCH[3].U = 300000 - 1; // 1 seconds
LPC_SCT0->MATCH[0].U = 400000 - 1; // 1 seconds
 
 
 
/* Each SCTimer/PWM supports:
– 5 match/capture registers.
– 6 events.
– 8 states.
– 4 inputs and 4 outputs*/
 
   // --------------------------------------
   // Define states in which this event is enabled 
   LPC_SCT0->EVENT[0].STATE = (1 << 0);  // Enable event 0 in state 0
 
   // Setup the event (21.6.25)
   LPC_SCT0->EVENT[0].CTRL = (1 << 0)  | // MATCHSEL:  Select match reg 1
                             (0 << 4)  | // HEVENT:   Not set for unified counter
                             (0 << 5)  | // OUTSEL:   N/A as match only event
                             (0 << 6)  | // IOSEL:    N/A as match only event
                             (0 << 10) | // IOCOND:   N/A as match only event
(1 << 12) | // COMBMODE: Match only
                             (1 << 14) | // STATELD:  Load STATEV into STATE
                             (1 << 15);  // STATEV:   Transition into state 1
 
 
   // ------------------------------------
   // Define states in which this event is enabled 
   LPC_SCT0->EVENT[1].STATE = (1 << 1); // Enable event 1 in state 1
 
   // Setup the event (21.6.25)
   LPC_SCT0->EVENT[1].CTRL = (2 << 0)  | // MATCHSEL:  Select match reg 2
                             (0 << 4)  | // HEVENT:   Not set for unified counter
                             (0 << 5)  | // OUTSEL:   N/A as match only event
                             (0 << 6)  | // IOSEL:    N/A as match only event
                             (0 << 10) | // IOCOND:   N/A as match only event
(1 << 12) | // COMBMODE: Match only
                             (1 << 14) | // STATELD:  Load STATEV into STATE
                             (2 << 15);  // STATEV:   Transition into state 2
 
 
   // ----------------------------------------
   // Define states in which this event is enabled 
   LPC_SCT0->EVENT[2].STATE = (1 << 2);  // Enable event 2 in state 2
 
   // Setup the event (21.6.25)
   LPC_SCT0->EVENT[2].CTRL = (3 << 0)  | // MATCHSEL: Select match reg 3
                             (0 << 4)  | // HEVENT:   Not set for unified counter
                             (0 << 5)  | // OUTSEL:   N/A as match only event
                             (0 << 6)  | // IOSEL:    N/A as match only event
                             (0 << 10) | // IOCOND:   N/A as match only event
                             (1 << 12) | // COMBMODE: Match only
                             (1 << 14) | // STATELD:  Load STATEV into STATE
                             (3 << 15);  // STATEV:   Transition into state 3
 
   // Define states in which this event is enabled 
   LPC_SCT0->EVENT[3].STATE = (1 << 3);  // Enable event 2 in state 2
 
   // Setup the event (
   LPC_SCT0->EVENT[3].CTRL = (0 << 0)  | // MATCHSEL: Select match reg 3
                             (0 << 4)  | // HEVENT:   Not set for unified counter
                             (0 << 5)  | // OUTSEL:   N/A as match only event
                             (0 << 6)  | // IOSEL:    N/A as match only event
                             (0 << 10) | // IOCOND:   N/A as match only event
                             (1 << 12) | // COMBMODE: Match only
                             (1 << 14) | // STATELD:  Load STATEV into STATE
                             (0 << 15);  // STATEV:   Transition into state 0
 
 
LPC_SCT0->OUT[1].CLR = (1 << 0); //Clear Output 1 Green when event 0 occurs
LPC_SCT0->OUT[2].SET = (1 << 0);
LPC_SCT0->OUT[3].SET = (1 << 0);
 
 
LPC_SCT0->OUT[1].SET = (1 << 1);
LPC_SCT0->OUT[2].CLR = (1 << 1); //Clear Output 2 Red when event 1 occurs
LPC_SCT0->OUT[3].SET = (1 << 1);
 
 
 
LPC_SCT0->OUT[1].SET = (1 << 2);
LPC_SCT0->OUT[2].SET = (1 << 2);
LPC_SCT0->OUT[3].CLR = (1 << 2); //Clear Output 3 Blue when event 2 occurs
 
 
LPC_SCT0->OUT[1].SET = (1 << 3);
LPC_SCT0->OUT[2].SET = (1 << 3);
LPC_SCT0->OUT[3].SET = (1 << 3);
 
 
   // Reset the SCTimer state to the start state 
   LPC_SCT0->STATE = 0;
 
/* Unhalt the counter to start */
LPC_SCT0->CTRL_U &= ~(1 << 2);
 
 
while (1)
{
// Read register values
state = LPC_SCT0->STATE_L;
event = LPC_SCT0->EVFLAG;
counter = LPC_SCT0->COUNT_U;
}
 
 
}



0 项奖励
回复
1 回复

601 次查看
Mr_Damian
Contributor I

Managed to resolve this issue, by just updating the outputs that needed changing of state and ignoring the ones that need to remain the same. 

Solution :

LPC_SCT0->OUT[1].CLR = (1 << 0); //Clear Output 1 Green when event 1 occurs
 
LPC_SCT0->OUT[1].SET = (1 << 1);
LPC_SCT0->OUT[2].CLR = (1 << 1); //Clear Output 2 Red when event 1 occurs
 
LPC_SCT0->OUT[2].SET = (1 << 2);
LPC_SCT0->OUT[3].CLR = (1 << 2); //Clear Output 3 Blue when event 0 occurs
 
LPC_SCT0->OUT[3].SET = (1 << 3);
0 项奖励
回复