AnsweredAssumed Answered

Getting SCT to trigger ADC

Question asked by Greg Wilson-Lindberg on Nov 29, 2017
Latest reply on Nov 30, 2017 by jeremyzhou

I'm trying to use SCT2 to trigger the ADC and am having no luck. Here is the initialization code that I'm using:

// LPC_SCT2->CONFIG |= 0;               // 16-bit timer
LPC_SCT2->CONFIG |= (1 << 18);     // 16-bit timer, auto limit high
LPC_SCT2->CTRL_H |= (64 << 5);     // Pre-scaler & halt H timer
// LPC_SCT2->LIMIT_H |= (1 << 0);    // Event 0 limit high

 

LPC_SCT2->MATCHREL[0].H = 5000 - 1;    // match 0 @ 200 Hz = 5 msec, toggle will make it 100 Hz, 10ms
LPC_SCT2->MATCH[0].H = 5000 - 1;           // match 0 @ 200 Hz = 5 msec

 

LPC_SCT2->EVENT[0].STATE = 0xFFFF;    // event 0 happens in all states
LPC_SCT2->EVENT[0].CTRL = (0 << 0) |     // Match 0
                                                    (1 << 4) |     // High counter
                                                    (1 << 12);    // match condition only

 

LPC_SCT2->EVEN = (1 << 0); // enable event 0 interrupt
NVIC_EnableIRQ(SCT2_IRQn);

 

LPC_SCT2->OUT[3].SET = (1 << 0);             // event 0 will set SCT2_OUT3
LPC_SCT2->OUT[3].CLR = (1 << 0);             // event 0 will clear SCT2_OUT3
LPC_SCT2->RES = (3 << 6);                         // output 3 toggles on conflict

 

LPC_SCT2->OUT[0].SET = (1 << 0);             // event 0 will set SCT2_OUT0
LPC_SCT2->OUT[0].CLR = (1 << 0);             // event 0 will clear SCT2_OUT0
LPC_SCT2->RES = (3 << 6) | (3 << 0);          // output 0 toggles on conflict
// Output SCT_OUT0 on PIO2_3, pin 76
/* SCT1_OUT0, SCT1_OUT1, SCT1_OUT2, SCT2_OUT0 */
LPC_SWM->PINASSIGN[8] = 0x43FFFFFFUL;

 

LPC_SCT2->CTRL_H &= ~SCT_CTRL_HALT_L; // un-halt

 

// after everything is setup, enable the ADC
Chip_ADC_SetupSequencer(LPC_ADC0, ADC_SEQA_IDX,
                                                (ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_TEMP_INT) |
                                                 ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_TEMP_TOP) |
                                                 ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_36V_POWERSUPPLY) |
                                                 ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_36V_BATTERY) |
                                                 ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_MOTOR_CURRENT) |
                                                 ADC0_SEQ_CTRL_HWTRIG_SCT2_OUT3 |   // User SCT2 OUT[3] for trigger
                                                 ADC_SEQ_CTRL_MODE_EOS |
                                                 ADC_SEQ_CTRL_SEQ_ENA));

 

I'm getting the interrupt for Event[0] but it seems that OUT[3] is not toggling. I can't look at OUT[3], the SWM only allows SCT2_OUT[0-2] to go to pins, and the ADC only allows SCT2_OUT[3-4] to trigger, so I set up OUT[0] to operate in the same way and I don't get an output for OUT[0].

 

I'm obviously missing something, if any one can help me out I would appreciate it.

Outcomes