blinking LED using PIT

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

blinking LED using PIT

ソリューションへジャンプ
646件の閲覧回数
jwjung
Contributor II

Using the s32k312 board and using the PIT, I try to turn the LED on and off every second. Even though I've done all the settings for the PIT, it's not working normally. Where should I fix it to work properly?

 

/*==================================================================================================
*   Project              : RTD AUTOSAR 4.7
*   Platform             : CORTEXM
*   Peripheral           : S32K3XX
*   Dependencies         : none
*
*   Autosar Version      : 4.7.0
*   Autosar Revision     : ASR_REL_4_7_REV_0000
*   Autosar Conf.Variant :
*   SW Version           : 3.0.0
*   Build Version        : S32K3_RTD_3_0_0_D2303_ASR_REL_4_7_REV_0000_20230331
*
*   Copyright 2020 - 2023 NXP Semiconductors
*
*   NXP Confidential. This software is owned or controlled by NXP and may only be
*   used strictly in accordance with the applicable license terms. By expressly
*   accepting such terms or by downloading, installing, activating and/or otherwise
*   using the software, you are agreeing that you have read, and that you agree to
*   comply with and are bound by, such license terms. If you do not agree to be
*   bound by the applicable license terms, then you may not retain, install,
*   activate or otherwise use the software.
==================================================================================================*/
 
/**
*   @file main.c
*
*   @addtogroup main_module main module documentation
*   @{
*/
 
/* Including necessary configuration files. */
#include "Mcal.h"
#include "stdio.h"
#include "IntCtrl_Ip.h"
#include "Pit_Ip_PBcfg.h"
#include "Pit_Ip.h"
 
 
volatile int exit_code = 0;
/* User includes */
 
#include "../RTD/include/Siul2_Dio_Ip.h" // ==> #include "Siul2_Dio_Ip.h"
#include "../generate/include/Siul2_Dio_Ip_Cfg.h" // ==> #include "Siul2_Dio_Ip_Cfg.h"
#include "Siul2_Port_Ip.h" // <== #include "../RTD/include/Siul2_Port_Ip.h"
 
#include "../generate/include/Clock_Ip_Cfg.h"
#include "../RTD/include/Clock_Ip.h"
 
 
#define LED3(v) Siul2_Dio_Ip_WritePin(LED3_PORT, LED3_PIN, v)
 
 
#define Siul2_Port_Ip_PortStatusType Siul2_Port_Ip_Init(uint32 pinCount, const Siul2_Port_Ip_PinSettingsConfig config[])
#define Clock_Ip_StatusType Clock_Ip_Init(Clock_Ip_ClockConfigType const * Config)
 
 
/* PIT time-out period - equivalent to 1s */
// PIT_PERIOD 40000000 - 1s
#define PIT0_PERIOD 30000
#define PIT0_INSTANCE 0U
#define CH_0 0U
 
uint16 Timer1ms_Cnt = 0U;
volatile uint8 led_state = 0U;
 
void PIT0_Notification(void){ // been call by &PIT_0_ChannelConfig_PB
Timer1ms_Cnt++;
}
 
 
 
/*!
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - startup asm routine
 * - main()
*/
int main(void)
{
    /* Write your code here */
 
LED3(0);
// clock init
Clock_Ip_Init(&Clock_Ip_aClockConfig[0]);
 
//using pin init
Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
 
//Interrupt Service Routine(ISR), General Purpose Timer(GPT)
IntCtrl_Ip_Init(&IntCtrlConfig_0);
 
// assign enable interrupt
IntCtrl_Ip_EnableIrq(PIT0_IRQn);
 
Pit_Ip_Init(PIT0_INSTANCE, &PIT_0_InitConfig_PB);
Pit_Ip_InitChannel(PIT0_INSTANCE, PIT_0_CH_0);
Pit_Ip_EnableChannelInterrupt(PIT0_INSTANCE, CH_0);
// The driver needs to be initialized. This function is called for starting the Pit timer channel.
Pit_Ip_StartChannel(PIT0_INSTANCE, CH_0, PIT0_PERIOD);
 
//RUN LED3
while(1){
if(Timer1ms_Cnt  == 1000U && led_state == 0U){
LED3(1);
Timer1ms_Cnt = 0U;
led_state =1U;
}
else if(Timer1ms_Cnt  == 1000U && led_state == 1U){
LED3(0);
Timer1ms_Cnt = 0U;
led_state = 0U;
}
}
    return 0;
}
 
/** @} */

 

0 件の賞賛
返信
1 解決策
631件の閲覧回数
Senlent
NXP TechSupport
NXP TechSupport

Hi@jwjung

please refer to the demo we provided in S32 DS, you can try to modified it as you need.

Senlent_0-1708328801282.png

 

元の投稿で解決策を見る

0 件の賞賛
返信
1 返信
632件の閲覧回数
Senlent
NXP TechSupport
NXP TechSupport

Hi@jwjung

please refer to the demo we provided in S32 DS, you can try to modified it as you need.

Senlent_0-1708328801282.png

 

0 件の賞賛
返信