ADC and Timer

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

ADC and Timer

1,950 Views
Krishnaja
Contributor II

Hi,

I have modified adc_swtrigger_mpc5748g example.

If "result>threshold", I want to start the timers. But when condition is satisfied, the timer is not ONing. I want to know where I am going wrong.

 

  /* Initialize ADC */

  ADC_DRV_Reset(INST_ADCONV1);

  ADC_DRV_DoCalibration(INST_ADCONV1);

  ADC_DRV_ConfigConverter(INST_ADCONV1,&adConv1_ConvCfg0);

  ADC_DRV_EnableChannel(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, ADC_CHAN_NUM);

  /* Start a loop to read converted values and blink an LED */

  while(1)

  {

    ADC_DRV_StartConversion(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL);

    while(!(ADC_DRV_GetStatusFlags(INST_ADCONV1) & ADC_FLAG_NORMAL_ENDCHAIN));

    uint32_t len = ADC_DRV_GetConvResultsToArray(INST_ADCONV1, ADC_CONV_CHAIN_NORMAL, &result, 1u);

    DEV_ASSERT(len == 1u); /* only one value should be read from hardware registers */

    (void)len;

    ADC_DRV_ClearStatusFlags(INST_ADCONV1, ADC_FLAG_NORMAL_ENDCHAIN);

    if (result > ADC_THRESHOLD)

    {

              PINS_DRV_ClearPins(LED_PORT, (1 << LED));//LED_PORT:PTJ LED:4 on

              PINS_DRV_WritePin(PTA,10,1); //off LED

 

                            /* Initialize TIMING over PIT */

                                TIMING_Init(&timing_pal1_instance, &timing_pal1_InitConfig);

                             /* Get tick resolution in nanosecond unit for TIMING over PIT */

                                          TIMING_GetResolution(&timing_pal1_instance, TIMER_RESOLUTION_TYPE_NANOSECOND, &pitResolution);

                             /* Start PIT channel 0 counting with the period is 1 second,

                                    the period in tick = the period in nanosecond / PIT tick resolution in nanosecond */

                                          TIMING_StartChannel(&timing_pal1_instance, PIT_CHANNEL, PERIOD_BY_NS/pitResolution);

                             /* Initialize TIMING over STM */

                                TIMING_Init(&timing_pal2_instance, &timing_pal2_InitConfig);

                             /* Get tick resolution in nanosecond unit for TIMING over STM */

                                          TIMING_GetResolution(&timing_pal2_instance, TIMER_RESOLUTION_TYPE_NANOSECOND, &stmResolution);

                             /* Start STM channel 0 counting with the period is 1 second,

                                             the period in tick = the period in nanosecond / STM tick resolution nanosecond*/

                                          TIMING_StartChannel(&timing_pal2_instance, STM_CHANNEL, PERIOD_BY_NS2/stmResolution);

 

    }

    else

    {

              PINS_DRV_SetPins(LED_PORT, (1 << LED));//off

              PINS_DRV_WritePin(PTA,10,0); //on LED

 

              }

  }

Thanks!

Krishnaja

0 Kudos
7 Replies

1,704 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

As I had a while so I have tried to used adc_swtrigger_mpc5748g, adding stm_periodic_interrupt_mpc5748g configuration to the project.

If ADC threshold is achieved, LED is blinking (stm is running), if not LED stays ON or OFF (stm not running).

You may find in attachment

Hope it helps

0 Kudos

1,915 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Hi, it seems there is lot of changes. Could you mark what exactly you added to the example code?

0 Kudos

1,897 Views
Krishnaja
Contributor II

NOTE:

Black: adc_swtrigger_mpc5748g example code

Brown: timing_pal_mpc5748g example code

Blue: LED Off and On

0 Kudos

1,856 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

So you are trying to combine two examples together.

One point is the code itself and second is that both examples have certain processor expert configuration. Here I would recommend to choose a more complex example as a base and manually add configuration for second one.

0 Kudos

1,843 Views
Krishnaja
Contributor II

Hi David,

My requirement is, If voltage is greater than threshold(by using ADC) I want to on a timer(say for 5minutes).

Please suggest me a more complex example as a base as you recommended.

Thanks.

0 Kudos

1,778 Views
davidtosenovjan
NXP TechSupport
NXP TechSupport

Hi, I would combine two examples of the same type. Thus either both PD or both PAL.

Unfortunately there is no way how to partially import setting from one example to another. This needs to be done manually.

1,761 Views
Krishnaja
Contributor II

Hi David,

I manually added "timing_pal" component to adc_pal example and it is working fine.

Thank you.

Krishnaja.

0 Kudos