how to setup LPC_INMUX to feed external input to SCT?

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

how to setup LPC_INMUX to feed external input to SCT?

1,421 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larsen on Sat Aug 29 01:21:04 MST 2015
LPC824, LPCXpresso 7.9.0, LPC Xpresso V2/MBED board.

The SCT state machine (SM) I am making, has a pin-input (SW1 button PIO0_04) and an output to the LED (green act low PIO0_16).
The SM should simply monitor SW1 and generate a light flash of programmable duration for each falling edge on SW1 - a one-shot in essence.
It does not work - the SCT does not see the SW1, judging from the debugger. The SW1 is working, I can detect by GPIO check.

In the debug->peripherals->SCT->INPUT I can observe the state of the input(s) - they all remain 0 all time. Why?

Here is what I think must be the essential code part:
void app_setup_pin(void)
{
/* Enable SWM clock before altering SWM */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 4, false);//Push botton SW1 = PIO0_04
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 16, true);//green led act low = PIO0_16
/* Connect SCT input 0 to SW1 pin PIO0_04 */
Chip_SWM_DisableFixedPin(SWM_FIXED_ADC11);//PIO_04 disable
Chip_SWM_MovablePinAssign(SWM_SCT_IN0_I, 4);//=SW1=Wake texted
Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0,  SCT_INP_IN0 );//??
/* Connect SCT output 0 to LED pin PIO_16 */
Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O, 16);//12=Red, 16=Green, 27=Blue
}

A note about LPC_INMUX: In the debugger->peripherals->INPUTMUX[LPS824]. After running this code and halting in the __WFI() the debugger->peripherals->INPUTMUX[LPS824]->SCT0-INMUX0->INP-N has changed from UNKNOWN(0xF) to SCT_IN0_CHANGE_THE <<- Now that's a weird text, and it continues:

Hovering over the name SCT_IN0_CHANGE_THE gives a text.
Quote:
SCT_IN0 change the name since this is not the function sct_in0 but the first selection for sct input in the mux. in fact it could be functionally sct_in3(input 3 of the sct). Assign to pin using the switch matix"



What does that try to explain me?
What could be a likely reason I cannot see changes in debug->peripherals->SCT->INPUT field.

Thanks for any help - this problem has bugged me for days now!
Labels (1)
0 Kudos
9 Replies

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larsen on Fri Sep 04 01:39:07 MST 2015
You are right, starblue. There is a mistake in the library - yes it must be me who has changed it by accident - no one else can it be.
What a relief to be able to get on with the real work. Thanks.
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Fri Sep 04 01:19:22 MST 2015
Your definition of SWM_SCT_IN0_I is wrong, the = 0x70 should be on SWM_SCT_IN1_I (see the PINASSIGNx registers in the user manual).

Did you change that?  I checked in LPCOpen 2.19, where it is correct.
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larsen on Thu Sep 03 13:47:27 MST 2015
Hi, nxp69442

Ok I give up. There is too much black magic here.

1) How can the code you show work because there is missing the dreaded halt bit also recommended by others here. So after the sct_fsm_init(); there need to be  a call to
Chip_SCT_ClearControl(LPC_SCT, SCT_CTRL_HALT_L);

2) I have added this halt line in order to get it to work somehow. There is no mistake - when using
Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0, SCT_INP_IN0);
the led is constant on. And when using
Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0, SCT_INP_IN1);
it works - the led switch on when button is pushed.

I dont know - can it be we are using different versions I use: LPCXpresso v7.9.0 [Build 455] [2015-07-23]

Can it be the chip's revision are different? This one is marked Q824 z 58 01 14 271A. the board is marked lpc82x Xpresso v2/mbed,  W0-0572 E225430kb-01x

Ok I cannot exclude that some of the solder jumpers are in another state than the default - but I cannot see how any external wire could alter the SCT_INP_INx - can you?

By the way, if the SM is set to use input pin1 instead of input pin0, then the code need to use SCT_INP_IN2, i.e. one higher again.

As I wrote - I have given up in understanding this. So I have attached the example I have based on your code. - plus the red.state machine as decribed In the hope someone can reproduce a bit of what I see.
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcmunich on Thu Sep 03 03:20:24 MST 2015
Hi Larsen,
I just tested this and it works for me.
As you can see, I am using SCT_INP_IN0 only.
Please don't try to read too much into this "FIXME" comment.

int main(void)
{
/* Generic Initialization */
SystemCoreClockUpdate();
Board_Init();
Chip_Clock_SetSysClockDiv(2);
Chip_SWM_Init();
Chip_SCT_Init(LPC_SCT);/* enable the SCT clock     */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);

Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0, SCT_INP_IN0);

    Chip_SWM_DisableFixedPin(SWM_FIXED_ADC11);            //disable Pinmux for P0_4 (ADC11)

Chip_SWM_MovablePinAssign(SWM_SCT_IN0_I,   4);/* CTIN_0->PIO0_4             */
Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O, 16);/* CTOUT_0->PIO0_16 (green)   */
Chip_SWM_MovablePinAssign(SWM_SCT_OUT1_O,  12);/* CTOUT_1->PIO0_12 (red)      */


sct_fsm_init();              /* Initialize the SCT using the code generated by Red State */

     while(1)
    {
    __WFI();
    }
}
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larsen on Wed Sep 02 15:11:02 MST 2015
Thanks for the suggestions. It was not the halt bit which was not properly managed.

It works after count less permutations, but I need someone to explain what is this code doing which I have got to work. Let me explain.

The red-state machine is very simple: One state U_ENTRY with two transitions back to U_ENTRY.
Transition 1: Input pin 0, Action: Set output pin 0,1,2
Transition 2: !Input pin 0, Action: Clr output pin 0,1,2
See attached picture. I.e. the input pin 0 is just copied to the 3 output pins, So pushing/releasing SW1 will turn on/resp off all leds - the simplest useful SM I could come up with in order to simplfy debugging.

This works if I have the following code before the call sct_fsm_init();
void app_setup_pin(void)
{
/* Enable SWM clock before altering SWM */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 4, false);//Push botton SW1. <== should use this or not?
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 12, true);//led //12=Red, 16=Green, 27=Blue
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 16, true);//led //12=Red, 16=Green, 27=Blue
Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, 0, 27, true);//led //12=Red, 16=Green, 27=Blue

/* Connect SCT input 0 to SCT_IN0 */
Chip_SWM_DisableFixedPin(SWM_FIXED_ADC11);//PIO_04 disable
Chip_SWM_MovablePinAssign(SWM_SCT_IN0_I, 4);//=SW1, Note its IN0

/* Connect SCT output 0,1,2 to LED pin PIO_12,16,27 respectively */
Chip_SWM_MovablePinAssign(SWM_SCT_OUT0_O, 12);//12=Red, 16=Green, 27=Blue
Chip_SWM_MovablePinAssign(SWM_SCT_OUT1_O, 16);//12=Red, 16=Green, 27=Blue
Chip_SWM_MovablePinAssign(SWM_SCT_OUT2_O, 27);//12=Red, 16=Green, 27=Blue
        /* Connect the INMUX
Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0,  SCT_INP_IN1 );// all other, SCT_INP_IN0, 2, 3 do not work!!!
        /* Example is using Input pin 0, INMUX_0, so why does the following not work: */
       // Chip_INMUX_SetSCTInMux(LPC_INMUX, SCT_INMUX_0,  SCT_INP_IN0 ); //BAD
}
All those mux levels are difficult to track, but why should I use SCT_INP_IN1 in the code above when I use SCT_IN0?

When I browse to the definition of SCT_INP_IN0 I read this typedef with a suspicious comment:
typedef enum {
SCT_INP_IN0,                /*!< SCT0_IN0 selected by Pin Matrix */ /* FIXME: UM hints about changes */
SCT_INP_IN1,                /*!< SCT0_IN1 selected by Pin Matrix */
SCT_INP_IN2,                /*!< SCT0_IN2 selected by Pin Matrix */
SCT_INP_IN3,                /*!< SCT0_IN3 selected by Pin Matrix */
SCT_INP_ADC_THCMP_IRQ,      /*!< ADC Threshold compare IRQ */
SCT_INP_ACMP_O,             /*!< Analog comparator output */
SCT_INP_ARM_TXEV,           /*!< ARM TX Event */
SCT_INP_DEBUG_HALTED,       /*!< Debug halted event */
} SCT_INP_T;

What does this mean?
Thanks so far for all the suggestions, but I need the final mental "cleanup" as this result does not make sense to me right now.
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Wed Sep 02 06:07:00 MST 2015
Hi Larsen,

It looks like you might not be clearing the HALT flag for the SCT. The HALT bits  in the control register are set when you come out of reset by default. Typically you might want to set them before changing the SCT configuration (ie before calling sct_fsm_init() ) and then clear them to start the SCT running. If you are using the SCT as two 16bit timers you need to set / clear both the *_H and *_L setting in the code below. If it is configured as a unified timer you can just use the *_L settings.

Chip_SCT_SetControl(LPC_SCT,
   SCT_CTRL_CLRCTR_L | SCT_CTRL_HALT_L    // H Counter: Clear and halt
| SCT_CTRL_HALT_H | SCT_CTRL_CLRCTR_H // L Counter: Clear and halt
| SCT_CTRL_PRE_H(SystemCoreClock/1000000-1)   // Set the pre-scaler to 1Mhz
| SCT_CTRL_PRE_L(SystemCoreClock/1000000-1)) ; //  for both the L and H counters

sct_fsm_init(); // Apply SCT configuration

Chip_SCT_ClearControl(LPC_SCT,  SCT_CTRL_HALT_L ); // Clear L Halt bit to start counter.


There is an older example which ships with LPCXpresso that demonstrates the SCT using RedState on the LPC1800 series called LPC1850A_HitexA4_SCT_Blinky. The same configuration applies to the LPC820 series. It is in the archive:

<LPCXPRESSO INSTALL DIR>lpcxpresso_7.9.0_455/lpcxpresso/Examples/Legacy/NXP/LPC1000/LPC18xx/LPC1850A_Hitex.zip


You can import it by just going to the Quickstart Panel and choosing Import Project(s), then select Browse in the Project Archive section and find the zip file.

Ciao,
LPCXpresso-Support
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcmunich on Wed Sep 02 03:56:52 MST 2015
I can understand the confusion with slightly different naming, but they are basically same examples.
You can easily import only periph_SCT_2ch or all SCT projects into LPCXpresso (IDE) workspace.
...\code examples\LPC82x\LPCOpen\applications\lpc82x\lpcxpresso_projects\nxp_lpcxpresso_824

And yes, you need to figure out as to why your code doesn't work. But you have something to compare with.
BTW, this periph_SCT_2ch example and some others as well does use the code generated by red state tool.
I tend to agree with your comment on the weird text in peripheral view, and will inform the concerned team about it.
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larsen on Tue Sep 01 08:19:03 MST 2015
Thnaks, Its not stupid question, yes I am calling the Chip_SCT_Init() which does enable the clock.

   
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_SYSCTL_PeriphReset(RESET_SCT);
Chip_SCT_Init(LPC_SCT);/* enable the SCT clock  and reset sct   */
Chip_SCT_SetControl(LPC_SCT, SCT_CTRL_PRE_L(SystemCoreClock/1000000-1)); /* set prescaler, SCT clock = 1 MHz, clear counter   */

sct_fsm_init();
Chip_SCT_SetControl(LPC_SCT, SCT_CTRL_PRE_L(SystemCoreClock/1000000-1)); /* set prescaler, SCT clock = 1 MHz, clear counter   */
app_setup_pin();


It is slightly confucing, In this distribution for the cookbook there are two versions of similar function:
...\SCT cookbook AN11538\AN11538_v4.0\code examples\LPC82x\LPCOpen\applications\lpc82x\examples\SCTimer_PWM\periph_SCT_pwm_2ch

and
...\SCT cookbook AN11538\AN11538_v4.0\code examples\LPC82x\LPCOpen\applications\lpc82x\lpcxpresso_projects\nxp_lpcxpresso_824\nxp_lpcxpresso_824_SCT_PWM_examples\periph_SCT_2ch

I have tried the periph_SCT_pwm_2ch and it works, so now I have to figure out what the difference are. Problem is I try to use redState and the example uses manual calls.
I am lacking - in the cookbook examples which uses the red state. The examples are all of the manual type. I think it is important that the tools are backed up by good examples - i dont find any!

I ran In the example periph_SCT_4ch/main.c, the pwmAborted is never called when run on lpcxpresso board v2. This smells like the problem I have - input never read.

Do you have comments to the weird messages I point out above?

I will keep searching - but this is really frustrating
0 Kudos

1,171 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcmunich on Tue Sep 01 06:57:16 MST 2015
Hi Larsen,
Maybe a stupid question, did you enable the clock to the SCT?
Please refer to AN11538: SCTimer/PWM Cookbook on nxp website, a collection of some good examples with SCT.
http://www.nxp.com/documents/application_note/AN11538.zip

And it has couple of examples (2-ch PWM and 4-ch PWM) using the SW1 (PIO0_4) connected to SCT_IN0.
0 Kudos