PIC24 Support Libraries
Macros | Functions
pic24_timer.h File Reference
#include <stdint.h>
#include "pic24_chip.h"
#include "pic24_clockfreq.h"

Go to the source code of this file.

Macros

#define getTimerPrescale(TxCONbits)   getTimerPrescaleBits(TxCONbits.TCKPS)
 

Functions

uint16_t msToU16Ticks (uint16_t u16_ms, uint16_t u16_pre)
 
uint16_t usToU16Ticks (uint16_t u16_us, uint16_t u16_pre)
 
uint32_t usToU32Ticks (uint32_t u32_us, uint16_t u16_pre)
 
uint32_t ticksToMs (uint32_t u32_ticks, uint16_t u16_tmrPre)
 
uint32_t ticksToUs (uint32_t u32_ticks, uint16_t u16_tmrPre)
 
uint32_t ticksToNs (uint32_t u32_ticks, uint16_t u16_tmrPre)
 
uint16_t getTimerPrescaleBits (uint8_t u8_TCKPS)
 
uint32_t computeDeltaTicksLong (uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR, uint16_t u16_oflows)
 
uint16_t computeDeltaTicks (uint16_t u16_start, uint16_t u16_end, uint16_t u16_tmrPR)
 

Detailed Description

To do.

Definition in file pic24_timer.h.

Macro Definition Documentation

◆ getTimerPrescale

#define getTimerPrescale (   TxCONbits)    getTimerPrescaleBits(TxCONbits.TCKPS)

Given the TxCON register as a bitfield, determines the prescale based on the TCKPS bitfield. Works for PIC24H, PIC24F timers. Simply accesses the TCKPS bitfield then calls getTimerPrescaleBits with the bitfield.

Parameters
TxCONbitsThe TxCONbits for the timer in question
Returns
Prescale value.

Definition at line 23 of file pic24_timer.h.

Function Documentation

◆ computeDeltaTicks()

uint16_t computeDeltaTicks ( uint16_t  u16_start,
uint16_t  u16_end,
uint16_t  u16_tmrPR 
)

Computes delta ticks between two Timer register captures Assumes the delta time does not exceeds the timer period

Parameters
u16_startstart tick
u16_endend tick
u16_tmrPRTimer period register
Returns
delta ticks

Definition at line 193 of file pic24_timer.c.

◆ computeDeltaTicksLong()

uint32_t computeDeltaTicksLong ( uint16_t  u16_start,
uint16_t  u16_end,
uint16_t  u16_tmrPR,
uint16_t  u16_oflows 
)

Computes delta ticks between two Timer register captures Assumes long time interval and thus has a parameter for tracking timer overflows

Parameters
u16_startstart tick
u16_endend tick
u16_tmrPRTimer period register
u16_oflowsnumber of timer overflows
Returns
delta ticks

Definition at line 172 of file pic24_timer.c.

◆ getTimerPrescaleBits()

uint16_t getTimerPrescaleBits ( uint8_t  u8_TCKPS)

Given the TCKPS bitfield, return the timer prescale encoded by these bits. Use getTimerPrescale as a convenient way to extract the TCKPS bitfield from a TxCONbits SFT then call this function.

Parameters
u8_TCKPSTCKPS bitfield from the timer in question
Returns
Prescale value.

Definition at line 158 of file pic24_timer.c.

◆ msToU16Ticks()

uint16_t msToU16Ticks ( uint16_t  u16_ms,
uint16_t  u16_pre 
)

Converts milliseconds to 16-bit timer ticks.

Parameters
u16_msTime, in milliseconds, to convert to ticks
u16_prePrescale set for this timer. Note that getTimerPrescale can easily determine this.
Returns
Timer ticks corresponding to the given number of milliseconds.

Definition at line 53 of file pic24_timer.c.

◆ ticksToMs()

uint32_t ticksToMs ( uint32_t  u32_ticks,
uint16_t  u16_tmrPre 
)

Converts timer ticks to milliseconds

Parameters
u32_ticksTimer ticks
u16_tmrPreTimer prescale value
Returns
time in milliseconds

Definition at line 106 of file pic24_timer.c.

◆ ticksToNs()

uint32_t ticksToNs ( uint32_t  u32_ticks,
uint16_t  u16_tmrPre 
)

Converts timer ticks to nanoseconds

Parameters
u32_ticksTimer ticks
u16_tmrPreTimer prescale value
Returns
time in nanoseconds

Definition at line 139 of file pic24_timer.c.

◆ ticksToUs()

uint32_t ticksToUs ( uint32_t  u32_ticks,
uint16_t  u16_tmrPre 
)

Converts timer ticks to microseconds

Parameters
u32_ticksTimer ticks
u16_tmrPreTimer prescale value
Returns
time in microseconds

Definition at line 123 of file pic24_timer.c.

◆ usToU16Ticks()

uint16_t usToU16Ticks ( uint16_t  u16_us,
uint16_t  u16_pre 
)

Converts microseconds to 16-bit timer ticks.

Parameters
u16_usTime, in microseconds, to convert to ticks
u16_prePrescale set for this timer. Note that getTimerPrescale can easily determine this.
Returns
Timer ticks corresponding to the given number of microseconds.

Definition at line 71 of file pic24_timer.c.

◆ usToU32Ticks()

uint32_t usToU32Ticks ( uint32_t  u32_us,
uint16_t  u16_pre 
)

Converts microseconds to 32-bit timer ticks.

Parameters
u32_usTime, in microseconds, to convert to ticks
u16_prePrescale set for this timer. Note that getTimerPrescale can easily determine this.
Returns
Timer ticks corresponding to the given number of microseconds.

Definition at line 90 of file pic24_timer.c.