Skip to content

refactor: update timer and ic modules #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/helpers/interval.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void INTERVAL_CaptureFour(uint16_t count, uint16_t mode, uint8_t prescaler) {
RPINR8bits.IC4R = PIN_MANAGER_DIGITAL_PINS_LA4;

TMR2_Initialize();
TMR2_PrescalerSet(prescaler & 0xF);
TMR2_SetPrescaler(prescaler & 0xF);
TMR2_Counter16BitSet(1);

IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER2);
Expand Down
2 changes: 1 addition & 1 deletion src/instruments/multimeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void GetCapacitance_InitCTMU_TMR5(uint8_t current_range, uint8_t trim,
CTMUICONbits.IRNG = current_range;

TMR5_Initialize();
TMR5_PrescalerSet(TMR_PRESCALER_64);
TMR5_SetPrescaler(TMR_PRESCALER_64);
TMR5_Period16BitSet(charge_time);
}

Expand Down
59 changes: 57 additions & 2 deletions src/registers/comparators/ic1.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,66 @@ extern "C" {
inline static void IC1_CombineOddEvenICModules(void) {
IC1CON2bits.IC32 = 1;
}


/**
@Summary
Sets the trigger event for capture complete interrupt

@Description
This routine sets the trigger event for the input capture module to
notify the ISR that a capture event is complete

@Preconditions
IC1_Initialize function should have been called

@Param
IC_PARAMS_CAPTURE_INTERRUPT

@Returns
None
*/
inline static void IC1_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
IC1CON1bits.ICI = i;
}

/**
@Summary
Defines the purpose of input capture pin source

@Description
This routine defines if the pin attached to IC module is used either to
trigger the IC1TMR or to synchronize the timer with another timer module.

@Preconditions
IC1_Initialize function should have been called

@Param
IC_PARAMS_SOURCE_TASK

@Returns
None
*/
inline static void IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
IC1CON2bits.ICTRIG = t;
}


/**
@Summary
Clears the set interrupt flag of IC1 capture interrupt

@Description
This routine will clear the interrupt flag of the IC1 capture
module.

@Preconditions
IC1_Initialize function should have been called

@Param
None

@Returns
None
*/
inline static void IC1_InterruptFlagClear(void) {
IFS0bits.IC1IF = 0;
}
Expand Down
59 changes: 57 additions & 2 deletions src/registers/comparators/ic2.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,66 @@ extern "C" {
inline static void IC2_CombineOddEvenICModules(void) {
IC2CON2bits.IC32 = 1;
}


/**
@Summary
Sets the trigger event for capture complete interrupt

@Description
This routine sets the trigger event for the input capture module to
notify the ISR that a capture event is complete

@Preconditions
IC2_Initialize function should have been called

@Param
IC_PARAMS_CAPTURE_INTERRUPT

@Returns
None
*/
inline static void IC2_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
IC2CON1bits.ICI = i;
}

/**
@Summary
Defines the purpose of input capture pin source

@Description
This routine defines if the pin attached to IC module is used either to
trigger the IC2TMR or to synchronize the timer with another timer module.

@Preconditions
IC2_Initialize function should have been called

@Param
IC_PARAMS_SOURCE_TASK

@Returns
None
*/
inline static void IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
IC2CON2bits.ICTRIG = t;
}


/**
@Summary
Clears the set interrupt flag of IC2 capture interrupt

@Description
This routine will clear the interrupt flag of the IC2 capture
module.

@Preconditions
IC2_Initialize function should have been called

@Param
None

@Returns
None
*/
inline static void IC2_InterruptFlagClear(void) {
IFS0bits.IC2IF = 0;
}
Expand Down
59 changes: 57 additions & 2 deletions src/registers/comparators/ic3.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,66 @@ extern "C" {
inline static void IC3_CombineOddEvenICModules(void) {
IC3CON2bits.IC32 = 1;
}


/**
@Summary
Sets the trigger event for capture complete interrupt

@Description
This routine sets the trigger event for the input capture module to
notify the ISR that a capture event is complete

@Preconditions
IC3_Initialize function should have been called

@Param
IC_PARAMS_CAPTURE_INTERRUPT

@Returns
None
*/
inline static void IC3_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
IC3CON1bits.ICI = i;
}

/**
@Summary
Defines the purpose of input capture pin source

@Description
This routine defines if the pin attached to IC module is used either to
trigger the IC3TMR or to synchronize the timer with another timer module.

@Preconditions
IC3_Initialize function should have been called

@Param
IC_PARAMS_SOURCE_TASK

@Returns
None
*/
inline static void IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
IC3CON2bits.ICTRIG = t;
}


/**
@Summary
Clears the set interrupt flag of IC3 capture interrupt

@Description
This routine will clear the interrupt flag of the IC3 capture
module.

@Preconditions
IC3_Initialize function should have been called

@Param
None

@Returns
None
*/
inline static void IC3_InterruptFlagClear(void) {
IFS2bits.IC3IF = 0;
}
Expand Down
75 changes: 73 additions & 2 deletions src/registers/comparators/ic4.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,89 @@ extern "C" {
inline static void IC4_CombineOddEvenICModules(void) {
IC4CON2bits.IC32 = 1;
}


/**
@Summary
Defines the purpose of input capture pin source

@Description
This routine defines if the pin attached to IC module is used either to
trigger the IC4TMR or to synchronize the timer with another timer module.

@Preconditions
IC4_Initialize function should have been called

@Param
IC_PARAMS_SOURCE_TASK

@Returns
None
*/
inline static void IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK t) {
IC4CON2bits.ICTRIG = t;
}

/**
@Summary
Clears the set interrupt flag of IC4 capture interrupt

@Description
This routine will clear the interrupt flag of the IC4 capture
module.

@Preconditions
IC4_Initialize function should have been called

@Param
None

@Returns
None
*/
inline static void IC4_InterruptFlagClear(void) {
IFS2bits.IC4IF = 0;
}


/**
@Summary
Enable IC4 interrupt

@Description
This routine will enable IC4 interrupt.

@Preconditions
IC4_Initialize function should have been called

@Param
None

@Returns
None
*/
inline static void IC4_InterruptEnable(void) {
IEC2bits.IC4IE = 1;
}

/**
@Summary
Sets the trigger event for capture complete interrupt

@Description
This routine sets the trigger event for the input capture module to
notify the ISR that a capture event is complete

@Preconditions
IC4_Initialize function should have been called

@Param
IC_PARAMS_CAPTURE_INTERRUPT

@Returns
None
*/
inline static void IC4_InputCaptureInterruptOn(IC_PARAMS_CAPTURE_INTERRUPT i) {
IC4CON1bits.ICI = i;
}

inline static void IC4_InterruptDisable(void) {
IEC2bits.IC4IE = 0;
Expand Down
51 changes: 50 additions & 1 deletion src/registers/comparators/ic_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ic2.h"
#include "ic3.h"
#include "ic4.h"
#include "../system/pin_manager.h"

void IC_PARAMS_InitiateAll(void) {
IC1_Initialize();
Expand Down Expand Up @@ -63,4 +64,52 @@ void IC_PARAMS_SetCaptureTimer(IC_PARAMS_CAPTURE_TIMER t) {
IC2_SetCaptureTimer(t);
IC3_SetCaptureTimer(t);
IC4_SetCaptureTimer(t);
}
}

void IC_PARAMS_ConfigureIntervalCaptureWithIC1AndIC2(uint8_t pin,
IC_PARAMS_CAPTURE_TIMER timer,
IC_PARAMS_CAPTURE_INTERRUPT interrupt,
IC_PARAMS_CAPTURE_MODE mode) {

IC1_InterruptFlagClear();

RPINR7bits.IC1R = PIN_MANAGER_DIGITAL_PINS[pin];

IC1_Initialize();
IC1_CombineOddEvenICModules();
IC1_SetCaptureTimer(timer);
IC1_InputCaptureInterruptOn(interrupt);
IC1_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
IC1_SetCaptureMode(mode);

IC2_Initialize();
IC2_CombineOddEvenICModules();
IC2_SetCaptureTimer(timer);
IC2_InputCaptureInterruptOn(interrupt);
IC2_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
IC2_SetCaptureMode(mode);
}

void IC_PARAMS_ConfigureIntervalCaptureWithIC3AndIC4(uint8_t pin,
IC_PARAMS_CAPTURE_TIMER timer,
IC_PARAMS_CAPTURE_INTERRUPT interrupt,
IC_PARAMS_CAPTURE_MODE mode) {

IC3_InterruptFlagClear();

RPINR8bits.IC3R = PIN_MANAGER_DIGITAL_PINS[pin];

IC3_Initialize();
IC3_CombineOddEvenICModules();
IC3_SetCaptureTimer(timer);
IC3_InputCaptureInterruptOn(interrupt);
IC3_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
IC3_SetCaptureMode(mode);

IC4_Initialize();
IC4_CombineOddEvenICModules();
IC4_SetCaptureTimer(timer);
IC4_InputCaptureInterruptOn(interrupt);
IC4_UseSourceTo(IC_PARAMS_SOURCE_TASK_TRIGGER);
IC4_SetCaptureMode(mode);
}
Loading