Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
main.c
1/*
2� [2023] Microchip Technology Inc. and its subsidiaries.
3
4 Subject to your compliance with these terms, you may use Microchip
5 software and any derivatives exclusively with Microchip products.
6 You are responsible for complying with 3rd party license terms
7 applicable to your use of 3rd party software (including open source
8 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19 THIS SOFTWARE.
20*/
21#include "system/system.h"
22#include "timer/tmr1.h"
23#include "os/os_scheduler.h"
24#include "device/dev_led.h"
26#include "config/comms_config.h"
27#include "pwm_hs/pwm.h"
28#include "fault/fault.h"
29#include "pwrctrl/pwrctrl_isr.h"
30#include "pwrctrl/pwrctrl.h"
31#include "system/pins.h"
32#include "adc/adc1.h"
33#include "sources/config/macros.h"
34
35// header file for calling custom peripheral configuration after MCC config
37uint16_t counter = 65500;
38
39/*
40 Main application
41*/
42
43
51int main(void)
52{
53
57
58
59 //disabling the interrupt
60 IEC4bits.CMP3IE = 0;
61 IPC19bits.CMP3IP = 6; // Primary OCP higher priority then all. 7 is highest, rest of the interrupts are at 1.
62 // Clearing IF flag before enabling the interrupt.
63 IFS4bits.CMP3IF = 0;
64 // Enabling CMP3 interrupt.
65 IEC4bits.CMP3IE = 1;
66
67 // Calling Custom PWM Daisy Chain Configuration
68 MCC_Custom_User_Config(); // pwm initialize and enable.
69
71 Dev_LED_Init();
72 psfb_ptr->SecRec.SR_Enabled = 0; // enabled after start power transfer
73 psfb_ptr->SecRec.SR_Flag = 0; // make sure it is off
74
75 ADC1_SoftwareTriggerEnable(); // add it here so that the very first time the values are available
78
79 while (counter--> 0) Nop(); // implementing delay for values to settle
80
81 OS_Init();
82 TMR1_TimeoutCallbackRegister (TMR1_CallBack); // scheduler timer 100us. statemachine
83
84 OS_Scheduler_RunForever();
85
86 while(1)
87 {
88
89 }
90}
91
92
101void __attribute__ ( ( __interrupt__ , auto_psv ) ) _ADCAN0Interrupt ( void )
102{
103 GPIO_debug_SetHigh(); // to keep track of the interrupt latency per cycle
104 //Read all the ADC value from the ADCBUF
105 psfb_ptr->Data.ISensePrimary = ADCBUF0;
106 psfb_ptr->Data.ISenseSecondary = ADCBUF1;
107
110
112
114
116
117 // Execute the fault detection
118 Fault_Execute(); // moving it here, so that all other faults are checked other than VCAP undervoltage
119
120 if (psfb_ptr->State > 1) { // if state is greater than precharge, give the phase shift control over to controller
121 ControlLoop_Interrupt_CallBack(); //update software based ADC, execute Faults
122 }
123
124 PwrCtrl_PWM_UpdateSecondaryRectifiers(); // check Ishunt within range
125
127 //clear the FB_P_CT_FILT interrupt flag
128 IFS5bits.ADCAN0IF = 0;
129}
This is the generated driver header file for the ADC1 driver.
This is the generated driver header file for the PWM driver.
This is the generated driver header file for the TMR1 driver.
app PBV psfb Frame map file Example
Contain the MCC Custom peripheral configuration that is not supported by MCC Melody tool.
Contains public fault functions.
POWER_CONTROL_t * psfb_ptr
Definition pwrctrl.c:28
Contains public function relevant for power control interrupt.
void App_PBV_psfb_Init()
This function initializes the local pbv objects. these objects are then passed on to the app_PBV_init...
void dev_MeasureOffsets_Initialize(void)
void MCC_Custom_User_Config(void)
Contains custom peripheral initialization.
void PwrCtrl_Initialize(void)
Initialize the power control parameters.
Definition pwrctrl.c:46
void PwrCtrl_OffsetDatatypesInitalize(void)
reset offset data types
Definition pwrctrl.c:214
void __attribute__((__interrupt__, auto_psv))
Executes the power converter control loop.
Definition main.c:101
void PwrCtrl_UpdateADConverterData(void)
This function updates the PSFB data members with ADC raw values.
void ControlLoop_Interrupt_CallBack(void)
Executes the power converter control loop.
Definition pwrctrl_isr.c:38
void PwrCtrl_PWM_UpdateSecondaryRectifiers(void)
set the PWM output to particular duty cycle.
uint16_t PwrCtrl_UpdateAverageRolling(AVERAGING_ROLLING_t *data, uint16_t sample)
Rolling Average the raw data over number of samples.
void Fault_Initialize(void)
Initialize the fault objects.
Definition fault.c:81
void Fault_Execute(void)
Executes the fault handlers.
Definition fault.c:134
static void ADC1_SoftwareTriggerEnable(void)
This inline function sets software common trigger.
Definition adc1.h:134
#define GPIO_debug_SetLow()
Sets the RD14 GPIO Pin which has a custom name of GPIO_debug to Low.
Definition pins.h:215
#define GPIO_debug_SetHigh()
Sets the RD14 GPIO Pin which has a custom name of GPIO_debug to High.
Definition pins.h:206
void SYSTEM_Initialize(void)
Initializes the System module.
Definition system.c:51
void TMR1_TimeoutCallbackRegister(void(*handler)(void))
This function can be used to override default callback and to define custom callback for TMR1 Timeout...
Definition tmr1.c:124
uint16_t ISensePrimary
Data value for primary current as measured with CT.
uint16_t ISenseSecondary
Data value for secondary current as measured with shunt.
uint8_t SR_Flag
uint8_t SR_Enabled
uint32_t Accumulator
SEC_REC_t SecRec
structure for secondary rectification data
PWR_CTRL_STATE_t State
Power Control State ID.
FEEDBACK_SETTINGS_t Data
Feedback channel settings.
AVERAGING_t ISecAveraging
secondary current average
uint16_t Secondary_Rolling_val
Secondary Current Rolling Average Value.
AVERAGING_ROLLING_t Secondary_Rolling
structure for Secondary current rolling average