brazos-trapezoidal
Macros | Functions | Variables
SRMCPwm.c File Reference

Motor Control PWM driver. More...

#include "Compiler_defs.h"
#include "mc_types.h"
#include "C_Extensions.h"
#include "SRMCPwm.h"
#include "SRMCPwm_mm_config.h"
Include dependency graph for SRMCPwm.c:

Go to the source code of this file.

Macros

#define BUFFER_TRANSMIT_MTU4_TADCR_BF   3 /* Transfers buffer at crest and trough */
 
#define MILLION   1000000.0
 
#define BILLION   1000000000.0
 
#define PWM_OUTPUT_OFF()   {MTU.TOERA.BYTE = 0xC0;}
 
#define PWM_OUTPUT_ON()   {MTU.TOERA.BYTE = 0xFF;}
 
#define PWM_TIMER_START()   {MTU.TSTRA.BYTE |= 0xC0;}
 
#define PWM_TIMER_STOP()   {MTU.TSTRA.BYTE &= 0x3F;}
 

Functions

void SRMCPwm__Initialize (unsigned short int pwm_frequency, unsigned short int dead_time_ns, CB_TYPE cb)
 It Initializes the module MCPwm and its variables. MTU3 and MTU4 are selected for PWM outputs @pwm_frequency defines the PWM frequency in Hz. @dead_time_ns defines the dead time inserted between complementary channels. This is defined in nanoseconds. More...
 
unsigned short int SRMCPwm__GetMaxPwm (void)
 
void SRMCPwm__PwmISR (void)
 
void SRMCPwm__TurnOnLowSideGates (void)
 
void SRMCPwm__LoadAllPwmValues (unsigned short int pwm_a, unsigned short int pwm_b, unsigned short int pwm_c)
 
void SRMCPwm__EnablePwmOutput (SRMCPWM_GATE_NAME_TYPE gate_name)
 
void SRMCPwm__DisablePwmOutput (SRMCPWM_GATE_NAME_TYPE gate_name)
 
void SRMCPwm__TurnOffLowSideGates (void)
 
void SRMCPwm__TurnOnHighSideGates (void)
 
void SRMCPwm__TurnOffHighSideGates (void)
 
void SRMCPwm__TurnOffAllGates (void)
 
void SRMCPwm__StartCounter (void)
 
void SRMCPwm__StopCounter (void)
 
unsigned short int SRMCPwm__GetPwmFrequencyHz (void)
 
unsigned short int SRMCPwm__GetDeadtimeNanosec (void)
 
unsigned char SRMCPwm__GetHwFaultStatus (void)
 
void SRMCPwm__Handler250us (void)
 
void SRMCPwm__StartDiagIfAvailable (unsigned long timeout_to_zero, unsigned long timeout_to_one)
 
void SRMCPwm__DiagnosticHandler (void)
 
SRMCPWM_ERROR_TYPE SRMCPwm__GetDiagFeedback (void)
 

Variables

CB_TYPE CallBackFcnAtPwm = NULL
 
PWM_DRIVE_STATE_TYPE DriveStatus [NUMBER_OF_MOTORS]
 
const PWM_INIT_TYPE SRMCPWM_INIT [NUMBER_OF_MOTORS] = PWM_INITIALIZE_FUNCTIONS
 
const PWM_VOID_VOID_TYPE SRMCPWM_TURNONLOWSIDES [NUMBER_OF_MOTORS] = PWM_LOWERON_FUNCTIONS
 
const PWM_LOAD_ALL_TYPE SRMCPWM_LOADPWM [NUMBER_OF_MOTORS] = PWM_LOADALL_FUNCTIONS
 
const PWM_DISABLE_ENABLE_TYPE SRMCPWM_DISABLEPWM [NUMBER_OF_MOTORS] = PWM_DISABLE_FUNCTIONS
 
const PWM_DISABLE_ENABLE_TYPE SRMCPWM_ENABLEPWM [NUMBER_OF_MOTORS] = PWM_ENABLE_FUNCTIONS
 
const PWM_GET_MAX_TYPE SRMCPWM_GETMAXPWM [NUMBER_OF_MOTORS] = PWM_GETMAXPWM_FUNCTIONS
 

Detailed Description

Motor Control PWM driver.

Motor control PWM initializer, control functions, and ISR



Definition in file SRMCPwm.c.

Macro Definition Documentation

◆ BILLION

#define BILLION   1000000000.0

Definition at line 46 of file SRMCPwm.c.

◆ BUFFER_TRANSMIT_MTU4_TADCR_BF

#define BUFFER_TRANSMIT_MTU4_TADCR_BF   3 /* Transfers buffer at crest and trough */

Definition at line 41 of file SRMCPwm.c.

◆ MILLION

#define MILLION   1000000.0

Definition at line 45 of file SRMCPwm.c.

◆ PWM_OUTPUT_OFF

#define PWM_OUTPUT_OFF ( )    {MTU.TOERA.BYTE = 0xC0;}

Definition at line 62 of file SRMCPwm.c.

◆ PWM_OUTPUT_ON

#define PWM_OUTPUT_ON ( )    {MTU.TOERA.BYTE = 0xFF;}

Definition at line 63 of file SRMCPwm.c.

◆ PWM_TIMER_START

#define PWM_TIMER_START ( )    {MTU.TSTRA.BYTE |= 0xC0;}

Definition at line 64 of file SRMCPwm.c.

◆ PWM_TIMER_STOP

#define PWM_TIMER_STOP ( )    {MTU.TSTRA.BYTE &= 0x3F;}

Definition at line 65 of file SRMCPwm.c.

Function Documentation

◆ SRMCPwm__DiagnosticHandler()

void SRMCPwm__DiagnosticHandler ( void  )

Definition at line 287 of file SRMCPwm.c.

◆ SRMCPwm__DisablePwmOutput()

void SRMCPwm__DisablePwmOutput ( SRMCPWM_GATE_NAME_TYPE  gate_name)

Disables PWM output according the parameter gate_name. It disconnects the PWM output to the internal PWM peripheral.

Parameters
gate_nameselects the gate to be disconnected.

Definition at line 229 of file SRMCPwm.c.

◆ SRMCPwm__EnablePwmOutput()

void SRMCPwm__EnablePwmOutput ( SRMCPWM_GATE_NAME_TYPE  gate_name)

Enable the PWM output according the parameter gate_name. It connects the PWM output to the internal PWM peripheral.

Parameters
gate_nameselects the gate to be connected.

Definition at line 215 of file SRMCPwm.c.

◆ SRMCPwm__GetDeadtimeNanosec()

unsigned short int SRMCPwm__GetDeadtimeNanosec ( void  )

Get the configured dead time in the PWM peripheral.

Returns
dead time in nanoseconds, decimal and no fractional number.

Definition at line 251 of file SRMCPwm.c.

◆ SRMCPwm__GetDiagFeedback()

SRMCPWM_ERROR_TYPE SRMCPwm__GetDiagFeedback ( void  )

Definition at line 296 of file SRMCPwm.c.

◆ SRMCPwm__GetHwFaultStatus()

unsigned char SRMCPwm__GetHwFaultStatus ( void  )

This function returns over current or over temperature error from driver module

Definition at line 258 of file SRMCPwm.c.

◆ SRMCPwm__GetMaxPwm()

unsigned short int SRMCPwm__GetMaxPwm ( void  )

Get the max PWM counts configured in the peripheral. Note that this method uses a shadowed variable, which was set during the initialization of this module.

Returns
Max PWM in timer counts.

Definition at line 97 of file SRMCPwm.c.

◆ SRMCPwm__GetPwmFrequencyHz()

unsigned short int SRMCPwm__GetPwmFrequencyHz ( void  )

Get the specified PWM frequency.

Returns
frequency in Hertz, decimal and no fractional number.

Definition at line 242 of file SRMCPwm.c.

◆ SRMCPwm__Handler250us()

void SRMCPwm__Handler250us ( void  )

Checks active level pulse duration in IPM SD pin

Definition at line 268 of file SRMCPwm.c.

◆ SRMCPwm__Initialize()

void SRMCPwm__Initialize ( unsigned short int  pwm_frequency,
unsigned short int  dead_time_ns,
CB_TYPE  cb 
)

It Initializes the module MCPwm and its variables. MTU3 and MTU4 are selected for PWM outputs @pwm_frequency defines the PWM frequency in Hz. @dead_time_ns defines the dead time inserted between complementary channels. This is defined in nanoseconds.

Definition at line 80 of file SRMCPwm.c.

◆ SRMCPwm__LoadAllPwmValues()

void SRMCPwm__LoadAllPwmValues ( unsigned short int  pwm_a,
unsigned short int  pwm_b,
unsigned short int  pwm_c 
)

Load the user pwm duty to the respective registers. All parameters are given in pwm counts.

Parameters
pwm_a
pwm_b
pwm_c

Definition at line 174 of file SRMCPwm.c.

◆ SRMCPwm__PwmISR()

void SRMCPwm__PwmISR ( void  )

ISR for the PWM. This is configured to happen at the end of each PWM period.

Definition at line 105 of file SRMCPwm.c.

◆ SRMCPwm__StartCounter()

void SRMCPwm__StartCounter ( void  )

Start the PWM timer counter.

Definition at line 193 of file SRMCPwm.c.

◆ SRMCPwm__StartDiagIfAvailable()

void SRMCPwm__StartDiagIfAvailable ( unsigned long  timeout_to_zero,
unsigned long  timeout_to_one 
)

Definition at line 279 of file SRMCPwm.c.

◆ SRMCPwm__StopCounter()

void SRMCPwm__StopCounter ( void  )

Stop the timer counter. This method also turns off the Pwm ISR because the timer will be stopped.

Definition at line 204 of file SRMCPwm.c.

◆ SRMCPwm__TurnOffAllGates()

void SRMCPwm__TurnOffAllGates ( void  )

This method is created and reconfigure on fly the Gpio output, because the LOCK bits can be used and the OCx/OCxN will not be able to be reconfigured on fly.

Definition at line 161 of file SRMCPwm.c.

◆ SRMCPwm__TurnOffHighSideGates()

void SRMCPwm__TurnOffHighSideGates ( void  )

Turn OFF ALL HIGH GATES. This is related to the driver input and NOT to the PWM output.

Definition at line 148 of file SRMCPwm.c.

◆ SRMCPwm__TurnOffLowSideGates()

void SRMCPwm__TurnOffLowSideGates ( void  )

Turn OFF ALL LOW GATES. This is related to the driver input and NOT to the PWM output.

Definition at line 132 of file SRMCPwm.c.

◆ SRMCPwm__TurnOnHighSideGates()

void SRMCPwm__TurnOnHighSideGates ( void  )

Turn ON ALL HIGH GATES. This is related to the driver input and NOT to the PWM output.

Definition at line 140 of file SRMCPwm.c.

◆ SRMCPwm__TurnOnLowSideGates()

void SRMCPwm__TurnOnLowSideGates ( void  )

Turn ON ALL LOW GATES. This is related to the driver input and NOT to the PWM output.

Definition at line 120 of file SRMCPwm.c.

Variable Documentation

◆ CallBackFcnAtPwm

CB_TYPE CallBackFcnAtPwm = NULL

Definition at line 18 of file SRMCPwm.c.

◆ DriveStatus

PWM_DRIVE_STATE_TYPE DriveStatus[NUMBER_OF_MOTORS]

Definition at line 52 of file SRMCPwm.c.

◆ SRMCPWM_DISABLEPWM

const PWM_DISABLE_ENABLE_TYPE SRMCPWM_DISABLEPWM[NUMBER_OF_MOTORS] = PWM_DISABLE_FUNCTIONS

Definition at line 57 of file SRMCPwm.c.

◆ SRMCPWM_ENABLEPWM

const PWM_DISABLE_ENABLE_TYPE SRMCPWM_ENABLEPWM[NUMBER_OF_MOTORS] = PWM_ENABLE_FUNCTIONS

Definition at line 58 of file SRMCPwm.c.

◆ SRMCPWM_GETMAXPWM

const PWM_GET_MAX_TYPE SRMCPWM_GETMAXPWM[NUMBER_OF_MOTORS] = PWM_GETMAXPWM_FUNCTIONS

Definition at line 59 of file SRMCPwm.c.

◆ SRMCPWM_INIT

const PWM_INIT_TYPE SRMCPWM_INIT[NUMBER_OF_MOTORS] = PWM_INITIALIZE_FUNCTIONS

Definition at line 54 of file SRMCPwm.c.

◆ SRMCPWM_LOADPWM

const PWM_LOAD_ALL_TYPE SRMCPWM_LOADPWM[NUMBER_OF_MOTORS] = PWM_LOADALL_FUNCTIONS

Definition at line 56 of file SRMCPwm.c.

◆ SRMCPWM_TURNONLOWSIDES

const PWM_VOID_VOID_TYPE SRMCPWM_TURNONLOWSIDES[NUMBER_OF_MOTORS] = PWM_LOWERON_FUNCTIONS

Definition at line 55 of file SRMCPwm.c.