Toggle LED using interrupt timer of 10ms with AUTOSAR

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

Toggle LED using interrupt timer of 10ms with AUTOSAR

Jump to solution
7,838 Views
pratik_a
Contributor III

Hi,

I want to toggle the LEDs using an interrupt timer.

I have managed to toggle the LED using incremental count as seen in the link below,

Solved: Re: Turn on the GPIO using NXPs32k322 - NXP Community

I want to generate an interrupt every 10ms. Any help is appreciated.

Regards,

Pratik

0 Kudos
Reply
1 Solution
7,688 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @pratik_a,

Please make sure the GptIsrEnable and GptChannelIsUsed options are enabled:

Julin_AragnM_0-1710370466472.png

Define the Pit notification and the ISR handler is defined:

Julin_AragnM_1-1710370529881.png

Julin_AragnM_2-1710370616700.png

Best regards,
Julián

View solution in original post

9 Replies
7,712 Views
pratik_a
Contributor III

Hi, 

I have included the snapshots of the included module configs, please take a look and let me know if I'm missing out on something.

I'm using the Segger Edu mini flasher so I'm unaware of how to debug with it. But I'm confident that the callback function is not called. As the LED connected at MSCR 83 glows which is independent of the callback function as seen in code above.

Dio_WriteChannel(83, STD_HIGH);

But the one included in the callback function never toggles.

Can you also confirm from the above code that my callback function is properly called upon and whether it is included in the interrupt vector? 

 

Regards,

Pratik

0 Kudos
Reply
7,754 Views
pratik_a
Contributor III

Hi @Julián_AragónM ,

I have been wanting to implement the Autosar method for timer functionality. As per the example provided, I have included the necessary components please refer to image 1.png

I want to generate an interrupt every 1 millisecond. 

Can you also confirm if the callback function is equivalent to ISR implementation in the code? I want to specifically implement an ISR routine which will be called every 1 millisecond, and my state engine will change its state accordingly.

Regards,

Pratik

0 Kudos
Reply
7,722 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @pratik_a,

It seems the components added to your project are okay, could this be an issue with the initialization of other modules apart from the GPT? Like the GPIO or the clocks? Could you confirm the example runs, and if the callback function is being stepped into?

An Interrupt Service Routine (ISR) is a function which runs when a hardware interrupt is triggered, the same way a Callback is a software implementation of this. An ISR needs to be installed with an interrupt vector (for example in the Siul2_Icu_Ip_BlinkLed_S32K344 example, SIUL_2_IRQn), and a Callback can be added into the interrupt routine.

You can modify the notification/callback function which will be modified by your state engine in this case.

Best regards,
Julián

0 Kudos
Reply
7,701 Views
pratik_a
Contributor III
Hi,
I'm still unable to make it work. Kindly help me with a way forward.
Regards,
Pratik
0 Kudos
Reply
7,689 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @pratik_a,

Please make sure the GptIsrEnable and GptChannelIsUsed options are enabled:

Julin_AragnM_0-1710370466472.png

Define the Pit notification and the ISR handler is defined:

Julin_AragnM_1-1710370529881.png

Julin_AragnM_2-1710370616700.png

Best regards,
Julián

7,640 Views
pratik_a
Contributor III

Hi @Julián_AragónM 

It worked...Thanks for your continuous help.

7,810 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @pratik_a,

The RTD 4.0.0 package includes examples for the General Purpose Timer:

Julin_AragnM_1-1709769385296.png

After the initialization the channel will start counting, the notification will be generated and a 'while(1) loop' will run to blink a LED. You can use these examples as reference and modify the counter to change the period.

Best regards,
Julián

 

0 Kudos
Reply
7,805 Views
pratik_a
Contributor III

Hi @Julián_AragónM ,

I tried the GPT example. I did all the necessary settings in the configuration tools. I'm posting my code below. Somehow it doesn't work, Kindly help.

@

/**
*   @file main.c
*
*   @addtogroup main_module main module documentation
*   @{
*/
 
/* Including necessary configuration files. */
#include "Mcal.h"
#include "Mcu.h"
#include "Port.h"
#include "Dio.h"
#include "Gpt.h"
#include "Platform.h"
 
 
 
static volatile uint8 toggleLed = 0U;
 
void Gpt_PitNotification(void)
{
    toggleLed = 1U;
}
 
/*void TestDelay(uint32 delay);
void TestDelay(uint32 delay)
{
    static volatile uint32 DelayTimer = 0;
    while(DelayTimer<delay)
    {
        DelayTimer++;
    }
    DelayTimer=0;
}*/
 
/* User includes */
 
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
 
 
int main(void)
{
uint8 pinValue = STD_LOW;
Mcu_Init(&Mcu_Config_BOARD_InitPeripherals);
 
/* Initialize the clock tree and apply PLL as system clock */
Mcu_InitClock(McuClockSettingConfig_0);
 
#if (STD_OFF == MCU_NO_PLL)
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
#endif
 
/* Apply a mode configuration */
Mcu_SetMode(McuModeSettingConf_0);
 
/* Initialize all pins using the Port driver */
Port_Init(NULL_PTR);
 
/* Initialize Platform driver */
Platform_Init(NULL_PTR);
    /* Initialize the high level configuration structure of Gpt driver */
#if (STD_ON == GPT_PRECOMPILE_SUPPORT)
Gpt_Init(NULL_PTR);
#else
Gpt_Init(&Gpt_Config_VS_0);
#endif
 
/* Start the Gpt timer */
Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0, 20000000U);
 
/* Enable the Gpt notification to get the event for toggling the LED periodically */
Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
Dio_WriteChannel(83, STD_HIGH);
    for(;;)
    {
    if (1U == toggleLed)
{
//count++;
pinValue = (STD_LOW == pinValue) ? STD_HIGH : STD_LOW;
Dio_WriteChannel(85, pinValue);
toggleLed = 0U;
}
    //Dio_WriteChannel(83, STD_HIGH);
    //Dio_WriteChannel(85, STD_HIGH);
//TestDelay(2000000);
//Dio_WriteChannel(85, STD_LOW);
//Dio_WriteChannel(83, STD_LOW);
//TestDelay(2000000);
    }
    return 0;
}
 
/** @} */

 

Also, can you guide me to where the void Gpt_PitNotification(void) function is declared? I just want to confirm if it is timer interrupt callback function?

0 Kudos
Reply
7,796 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @pratik_a,

PitNotification should be declared in the pit configuration file. It is indeed a callback function:

Julin_AragnM_0-1709847853749.pngJulin_AragnM_1-1709847860049.pngJulin_AragnM_2-1709847867425.png

Just to confirm, when debugging does the code step into the Gpt_PitNotification function?

Best regards,
Julián

0 Kudos
Reply