LPC-link2 external trigger for HSADC

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

LPC-link2 external trigger for HSADC

3,694 Views
ravithakur
Contributor I

I am using the LPC-link2 as a development board for the LPC4370. I want to use external trigger to initiate my HSADC0 capture. Page 454 and 455 of UM10503 describes the GIMA register that can be used to select the external trigger source. On further observation, pin P1_3 set as SGPIO10  on the LPC-link2 came out to be the best option for achieving this. I am doing the following to initialize it

  • Enabling the SGPIO clock: Chip_Clock_EnableOpts(CLK_PERIPH_SGPIO, true, true, 1);
  • Set SGPIO10 to input: LPC_SGPIO->GPIO_OENREG = (0 << 10);
  • Select the pin mux for P1_3 to be SGPIO10: Chip_SCU_PinMux(1, 3, 0, SCU_MODE_FUNC2 | SCU_MODE_PULLDOWN);
  • Select SGPIO10 as the trigger source in the GIMA

I am also attaching my code to this post. I am unable to trigger the HSADC0 with this set up. I see my external trigger at the pin of the MCU but no interrupt from HSADC indicating data in the fifo. If anyone has any suggestions about how I can achieve external trigger of HSADC0, I would really appreciate it.

Labels (3)
0 Kudos
17 Replies

2,383 Views
shivam0078
Contributor I

Kindly suggest a way to trigger HSADC using SGPIO10.

Thanks in advance

0 Kudos

2,991 Views
maneesh_pawar
Contributor I

 I want to have ADCHS data and external trigger synchronized. Is my configuration of the SGPIO10 pin incorrect to accept and external signal as trigger?

THANKS IN ADVANCE

0 Kudos

2,965 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

maneesh_pawar

This is a very old thread of two or three years ago. it's closed already. Please create a new thread for it. 

We will assign support engineer to follow it up.

Thanks,

Jun Zhang

0 Kudos

3,120 Views
ravithakur
Contributor I

I am attaching the archive of the project to this post. Any help is appreciated.

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hi ravi thakur,

Thanks for your reply.

I find two error.

1. The match value of match channel 0 is not configured.

2. The HALT bit should be clear to start the SCT counter, so you should use the Chip_SCT_ClearControl() function instead Chip_SCT_SetControl() function.

Hope this is clear.

TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos

3,120 Views
ravithakur
Contributor I

I am using the Chip_SCT_SetControl() function to write a '0' to clear the halt bit and do I need to set a match value for the counter if I want an IO transition to cause the event. Does a default match value of 0 not work? I do not want any time delay between the IO transition and the event that generates the SCT output to the HSADC.

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hi ravi thakur,

I've adapted the main code, please give a try.

/*
===============================================================================
 Name        : ctin_test.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===============================================================================
*/

#include "chip.h"

#include "board.h"

// TODO: insert other include files here

// TODO: insert other definitions and declarations here
#define SCT_MATCHSEL0      (0 <<  0) // Match register 0
#define SCT_HEVENT         (0 <<  4)
#define SCT_OUTSEL_IN      (0 <<  5) // Pin selected by IOSEL is input
#define SCT_IOSEL          (4 <<  6) // Input 4 = ctin4
#define SCT_IOCOND_RISE    (1 << 10) // Trigger on rising edge on input
#define SCT_IOCOND_HIGH    (1 << 10) // Trigger on input level high
#define SCT_COMBMODE_IO    (2 << 12) // Only input transition to cause event

#define SCT_STATELD_NONE   (1 << 14) // Use no states
#define SCT_STATEV_NONE    (0 << 15) // Use no states

#define SCT_STOP_L         (1 << 1)  // Stop = 1
#define SCT_CLRCTR_L       (1 << 3)  // Clear unified counter
#define SCT_BIDIR_L        (0 << 4)  // Set counters to count up
#define SCT_PRE_L          (0 << 5)  // Set pre-scaler value to 0
#define SCT_HALT_CLR       (1 << 2)  // Clear HALT

void SCT_IRQHandler(void) {
     Board_LED_Set(0, true);
     Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_0);
}

int main(void) {

    SystemCoreClockUpdate();
    Chip_Clock_EnableOpts(CLK_MX_GPIO, true, true, 1);
    Board_Init();
    Board_LED_Set(0, false);

    // TODO: insert code here
    Chip_Clock_EnableOpts(CLK_MX_SCU, true, true, 1);
    
       
    //Set pin2_13 as ctin4. ctin4 is the default input to sct4
    Chip_SCU_PinMux(2, 13, SCU_MODE_PULLDOWN, SCU_MODE_FUNC1);

    //SCT outputs are ORed with timer match outputs by default
    //Setting this bit disables this
    //LPC_CREG->CREG6 = (1 << 4);

    //Enable SCT clock
    Chip_SCT_Init(LPC_SCT);
    Chip_RGU_TriggerReset(RGU_SCT_RST);
    while(Chip_RGU_InReset(RGU_SCT_RST)){} //do nothing while in reset

    //Configure SCT to run on bus clock, enable unify and INSYNCn bit is set
    //by default
    Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER |
                               SCT_CONFIG_CLKMODE_BUSCLK);

    LPC_SCT->EVENT[0].STATE = 0x00000001; // Enable event 0
    LPC_SCT->EVENT[0].CTRL = SCT_MATCHSEL0 | SCT_OUTSEL_IN | SCT_IOSEL |
                                   SCT_IOCOND_HIGH | SCT_COMBMODE_IO |
                                   SCT_STATELD_NONE | SCT_STATEV_NONE;

    Chip_SCT_EnableEventInt(LPC_SCT, SCT_EVT_0);
    Chip_SCT_ClearEventFlag(LPC_SCT, SCT_EVT_0);

    Chip_SCT_ClearControl(LPC_SCT, SCT_HALT_CLR);

    //while (LPC_SCT->INPUT == 0){} //works, led is turned on

  while(LPC_SCT->EVFLAG == 0){} //does not work, led is off

    //while (LPC_SCT->INPUT == 0){} //works, led is turned on

    Board_LED_Set(0, true); // can replace this with a write to the output register

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
}






TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos

3,120 Views
chuangnan_wang
Contributor I

Hi jeremyzhou, thanks for the sharing. I have tried you code in my lpc_link2, but I am struggle to set it up. I have done bellowing:

1.software version: LPCXpresso v8.2.2

2. I import the zip file and change the main function into your code, then build and run it in debug mode

3. I try to trigger it using a 3 V DC signal, with half second on and half second off, but the LED no turn on 

4. check P1_13 by using GPIO mode, which shows that is the correct pin.

5. I also try to using  "while (LPC_SCT->INPUT == 0){}  //works, led is turned on", but still not work

Do you have any clue that what I have done wrong?

 

0 Kudos

3,120 Views
ravithakur
Contributor I

This worked! Thank you very much for your help.

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

You're welcome

0 Kudos

3,120 Views
ravithakur
Contributor I

Thank you for the reply. I see that I completely missed the part in the user manual in the SGPIO chapter that says "SGPIO output pins SGPIO10 and SGPIO12 can trigger the 12-bit ADC". I will look in to your suggestion. 

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hiravi thakur

What's going on? Do you already made it?

TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos

3,120 Views
ravithakur
Contributor I

I am unable to generate events in the SCT. I am attaching my simple test code to this post. Any help would be appreciated.

In the code I am configuring P2_13 as CTIN_4. In the SCT, the counter is set to 32 bit and being clocked by the bus. I write 0x1 to the EVSTATEMSK0 register to enable it. In the EVCTRL0 register, IOSEL is set to 4 (for CTIN_4), OUTSEL is '0' to select the input selected by IOSEL. I set IOCOND to RISE and COMBMODE is set to IO. I am not using states so STATELD and STATEV is set to 0. In the code I have a while loop that waits for the EVFLAG to have a non zero value and it sets the LED.

while(LPC_SCT->EVFLAG == 0){}

I do not see that happening. The code stays in the while loop and the led does not light up.

If I check for the real time value of the SCT inputs in the INPUTS register (0x4000 0048) I see that activity on the pin is being detected here.

while (LPC_SCT->INPUT == 0){} 

the code gets out of the while loop and sets the led. I do not know why the event flag is not being set. Please advise.

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hi ravi thakur,

Thanks for your reply.

To replicate the issue, I was wondering if you share a compile-able demo, then I can run it with the LPC-link2 board directly.

I'm looking forward to your reply.

TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hi  ravi thakur

Thank you for your interest in NXP Semiconductor products and 
the opportunity to serve you.
To implement it successful, you can configure the SGPIO10 to output PWM, meanwhile select the SGPIO10 as the trigger source of the HSADC.
Hope this is clear.
TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos

3,120 Views
ravithakur
Contributor I

Thank you for the reply. In my setup, I want to have ADC data and external trigger synchronized. Is my configuration of the SGPIO10 pin incorrect to accept and external signal as trigger?

0 Kudos

3,120 Views
jeremyzhou
NXP Employee
NXP Employee

Hi ravi thakur,

Maybe you can select the COUNT_n as the trigger, for instance CTOUT_0.

The SCT can detect external signal of I/O as event likes Fig1 indicates, then the event can arise the SCT_CTOUT_n output high or low level (Fig 2).

pastedImage_1.png

                                                                           Fig 1

pastedImage_2.png

                                                                          Fig 2

TIC
 
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
0 Kudos