ACDC Senior Project v1.0.0
Senior Project for Textron Aviation
Loading...
Searching...
No Matches
ACDC_TIMER.h File Reference

Header file containing functions for system timing using a hardware timer. More...

#include "ACDC_CLOCK.h"
#include "ACDC_stdint.h"
#include "ACDC_stdbool.h"

Go to the source code of this file.

Data Structures

struct  TIMx_CHx
 

Macros

#define TIM1_CH1_PB13   ((TIMx_CHx){TIM1, 1, GPIOB, GPIO_PIN_13, false})
 
#define TIM1_CH2_PB14   ((TIMx_CHx){TIM1, 2, GPIOB, GPIO_PIN_14, false})
 
#define TIM1_CH3_PA10   ((TIMx_CHx){TIM1, 3, GPIOA, GPIO_PIN_10, false})
 
#define TIM1_CH4_PA11   ((TIMx_CHx){TIM1, 4, GPIOA, GPIO_PIN_11, false})
 
#define TIM2_CH1_PA0   ((TIMx_CHx){TIM2, 1, GPIOA, GPIO_PIN_0, false})
 
#define TIM2_CH2_PA1   ((TIMx_CHx){TIM2, 2, GPIOA, GPIO_PIN_1, false})
 
#define TIM2_CH3_PA2   ((TIMx_CHx){TIM2, 3, GPIOA, GPIO_PIN_2, false})
 
#define TIM2_CH4_PA3   ((TIMx_CHx){TIM2, 4, GPIOA, GPIO_PIN_3, false})
 
#define TIM3_CH1_PA6   ((TIMx_CHx){TIM3, 1, GPIOA, GPIO_PIN_6, false})
 
#define TIM3_CH2_PA7   ((TIMx_CHx){TIM3, 2, GPIOA, GPIO_PIN_7, false})
 
#define TIM3_CH3_PB0   ((TIMx_CHx){TIM3, 3, GPIOB, GPIO_PIN_0, false})
 
#define TIM3_CH4_PB1   ((TIMx_CHx){TIM3, 4, GPIOB, GPIO_PIN_1, false})
 
#define TIM4_CH1_PB6   ((TIMx_CHx){TIM4, 1, GPIOB, GPIO_PIN_6, false})
 
#define TIM4_CH2_PB7   ((TIMx_CHx){TIM4, 2, GPIOB, GPIO_PIN_7, false})
 
#define TIM4_CH3_PB8   ((TIMx_CHx){TIM4, 3, GPIOB, GPIO_PIN_8, false})
 
#define TIM4_CH4_PB9   ((TIMx_CHx){TIM4, 4, GPIOB, GPIO_PIN_9, false})
 

Enumerations

enum  PWM_MODE { PWM_MODE_1 = 0b01100000 , PWM_MODE_2 = 0b01110000 }
 

Functions

void TIMER_Init (SystemClockSpeed SCS_x)
 (SHOULD NOT BE CALLED BY USER, CALLED IN ACDC_CLOCK.h) Initilizes the SysClock timer and sets the value of SysClock->LOAD
 
void TIMER_SetSystemClockSpeed (SystemClockSpeed SCS_x)
 (SHOULD NOT BE CALLED BY USER, CALLED IN ACDC_CLOCK.h) Sets the value for SysClock->LOAD
 
void TIMER_PWM_Init (TIMx_CHx TIMx_CHx_Pxx, PWM_MODE PWM_MODE_x, uint32_t frequency)
 Initializes PWM output on the specified timer and channel with the given parameters. (Default duty cycle = 0)
 
void TIMER_PWM_SetDuty (TIMx_CHx TIMx_CHx_Pxx, uint32_t dutyCycle)
 Sets the duty cycle of the PWM signal on the specified timer and channel.
 
uint32_t TIMER_PWM_GetDuty (TIMx_CHx TIMx_CHx_Pxx)
 Retrieves the current duty cycle of the specified timer and channel.
 
uint32_t TIMER_PWM_GetPeriod (TIMx_CHx TIMx_CHx_Pxx)
 Retrieves the period of the PWM signal on the specified timer.
 
uint64_t Millis ()
 Grabs and returns the total number of milliseconds since the MCU turned on.
 
uint64_t Micros ()
 Grabs and returns the total number of microseconds since the MCU turned on.
 
void Delay_MS (uint64_t delayVal)
 Pauses code execution for delayVal number of milliseconds.
 
void Delay_US (uint64_t delayVal)
 Pauses code execution for delayVal number of microseconds.
 

Detailed Description

Header file containing functions for system timing using a hardware timer.

Author
Devin Marx

This file defines functions for initializing a system clock timer, setting its value, and providing timing-related functionalities such as retrieving number of milliseconds since startup and introducing delays in code execution.

Version
0.1
Date
2023-11-7

Macro Definition Documentation

◆ TIM1_CH1_PB13

#define TIM1_CH1_PB13   ((TIMx_CHx){TIM1, 1, GPIOB, GPIO_PIN_13, false})

◆ TIM1_CH2_PB14

#define TIM1_CH2_PB14   ((TIMx_CHx){TIM1, 2, GPIOB, GPIO_PIN_14, false})

◆ TIM1_CH3_PA10

#define TIM1_CH3_PA10   ((TIMx_CHx){TIM1, 3, GPIOA, GPIO_PIN_10, false})

◆ TIM1_CH4_PA11

#define TIM1_CH4_PA11   ((TIMx_CHx){TIM1, 4, GPIOA, GPIO_PIN_11, false})

◆ TIM2_CH1_PA0

#define TIM2_CH1_PA0   ((TIMx_CHx){TIM2, 1, GPIOA, GPIO_PIN_0, false})

◆ TIM2_CH2_PA1

#define TIM2_CH2_PA1   ((TIMx_CHx){TIM2, 2, GPIOA, GPIO_PIN_1, false})

◆ TIM2_CH3_PA2

#define TIM2_CH3_PA2   ((TIMx_CHx){TIM2, 3, GPIOA, GPIO_PIN_2, false})

◆ TIM2_CH4_PA3

#define TIM2_CH4_PA3   ((TIMx_CHx){TIM2, 4, GPIOA, GPIO_PIN_3, false})

◆ TIM3_CH1_PA6

#define TIM3_CH1_PA6   ((TIMx_CHx){TIM3, 1, GPIOA, GPIO_PIN_6, false})

◆ TIM3_CH2_PA7

#define TIM3_CH2_PA7   ((TIMx_CHx){TIM3, 2, GPIOA, GPIO_PIN_7, false})

◆ TIM3_CH3_PB0

#define TIM3_CH3_PB0   ((TIMx_CHx){TIM3, 3, GPIOB, GPIO_PIN_0, false})

◆ TIM3_CH4_PB1

#define TIM3_CH4_PB1   ((TIMx_CHx){TIM3, 4, GPIOB, GPIO_PIN_1, false})

◆ TIM4_CH1_PB6

#define TIM4_CH1_PB6   ((TIMx_CHx){TIM4, 1, GPIOB, GPIO_PIN_6, false})

◆ TIM4_CH2_PB7

#define TIM4_CH2_PB7   ((TIMx_CHx){TIM4, 2, GPIOB, GPIO_PIN_7, false})

◆ TIM4_CH3_PB8

#define TIM4_CH3_PB8   ((TIMx_CHx){TIM4, 3, GPIOB, GPIO_PIN_8, false})

◆ TIM4_CH4_PB9

#define TIM4_CH4_PB9   ((TIMx_CHx){TIM4, 4, GPIOB, GPIO_PIN_9, false})

Enumeration Type Documentation

◆ PWM_MODE

enum PWM_MODE
Enumerator
PWM_MODE_1 

Each PWM Cycle looks like this: ▔▔▔┃▂▂▂┃ (Starts High then transitions to Low)

PWM_MODE_2 

Each PWM Cycle looks like this: ▂▂▂┃▔▔▔┃ (Starts Low then transitions to High)

Function Documentation

◆ Delay_MS()

void Delay_MS ( uint64_t delayVal)

Pauses code execution for delayVal number of milliseconds.

Parameters
delayValNumber of milliseconds to delay for

◆ Delay_US()

void Delay_US ( uint64_t delayVal)

Pauses code execution for delayVal number of microseconds.

Parameters
delayValNumber of microseconds to delay for

◆ Micros()

uint64_t Micros ( )

Grabs and returns the total number of microseconds since the MCU turned on.

Returns
Number of microseconds since startup

◆ Millis()

uint64_t Millis ( )

Grabs and returns the total number of milliseconds since the MCU turned on.

Returns
Number of milliseconds since startup

◆ TIMER_Init()

void TIMER_Init ( SystemClockSpeed SCS_x)

(SHOULD NOT BE CALLED BY USER, CALLED IN ACDC_CLOCK.h) Initilizes the SysClock timer and sets the value of SysClock->LOAD

Parameters
SCS_xSystem Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)

◆ TIMER_PWM_GetDuty()

uint32_t TIMER_PWM_GetDuty ( TIMx_CHx TIMx_CHx_Pxx)

Retrieves the current duty cycle of the specified timer and channel.

Parameters
TIMx_CHx_PxxStruct containing configuration data for the specific timer and channel
Returns
Current duty cycle

◆ TIMER_PWM_GetPeriod()

uint32_t TIMER_PWM_GetPeriod ( TIMx_CHx TIMx_CHx_Pxx)

Retrieves the period of the PWM signal on the specified timer.

Parameters
TIMx_CHx_PxxStruct containing configuration data for the specific timer and channel
Returns
Period of the PWM signal in timer ticks.

◆ TIMER_PWM_Init()

void TIMER_PWM_Init ( TIMx_CHx TIMx_CHx_Pxx,
PWM_MODE PWM_MODE_x,
uint32_t frequency )

Initializes PWM output on the specified timer and channel with the given parameters. (Default duty cycle = 0)

Parameters
TIMx_CHx_PxxStruct containing configuration data for the specific timer and channel
PWM_MODE_xDesired PWM mode
frequencyDesired frequency (in Hz) for PWM to run at

◆ TIMER_PWM_SetDuty()

void TIMER_PWM_SetDuty ( TIMx_CHx TIMx_CHx_Pxx,
uint32_t dutyCycle )

Sets the duty cycle of the PWM signal on the specified timer and channel.

Parameters
TIMx_CHx_PxxStruct containing configuration data for the specific timer and channel
dutyCycleDuty cycle value in timer ticks.

◆ TIMER_SetSystemClockSpeed()

void TIMER_SetSystemClockSpeed ( SystemClockSpeed SCS_x)

(SHOULD NOT BE CALLED BY USER, CALLED IN ACDC_CLOCK.h) Sets the value for SysClock->LOAD

Parameters
SCS_xSystem Clock Speed (Ex. SCS_72Mhz, SCS_36Mhz, ...)