Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
pwrctrl_common.c
Go to the documentation of this file.
1
9#include <xc.h>
10#include <stdint.h> // include standard integer data types
11#include <stdbool.h> // include standard boolean data types
12#include <stddef.h>
13
14#include "pwrctrl.h"
15
16
25uint16_t PwrCtrl_UpdateAverage(AVERAGING_t* data, uint16_t sample)
26{
27 data->Accumulator += sample;
28 if(++data->Counter >= data->AveragingCount){
29 data->AverageValue = (uint16_t)(__builtin_divud(data->Accumulator, data->Counter));
30 data->Accumulator = 0;
31 data->Counter = 0;
32 }
33 return(data->AverageValue);
34}
35
36
47{
48 rampUp->RampComplete = false;
49
50 if (++rampUp->Counter > rampUp->Delay)
51 {
52 rampUp->Counter = 0;
53
54 if(*rampUp->ptrReference == *rampUp->ptrReferenceTarget)
55 {
56 rampUp->RampComplete = true;
57 }
58 else if ((*rampUp->ptrReference + rampUp->StepSize) < *rampUp->ptrReferenceTarget)
59 {
60 *rampUp->ptrReference += rampUp->StepSize;
61 }
62 else if ((*rampUp->ptrReference - rampUp->StepSize) > *rampUp->ptrReferenceTarget)
63 {
64 *rampUp->ptrReference -= rampUp->StepSize;
65 }
66 else
67 {
68 *rampUp->ptrReference = *rampUp->ptrReferenceTarget;
69 rampUp->RampComplete = true;
70 }
71 }
72
73 return (rampUp->RampComplete);
74}
75
bool PwrCtrl_RampReference(START_UP_RAMP_t *rampUp)
Softly increment / decrement to the set reference target.
uint16_t PwrCtrl_UpdateAverage(AVERAGING_t *data, uint16_t sample)
Average the raw data over number of samples.
uint32_t Accumulator
uint16_t AveragingCount
uint16_t AverageValue
uint16_t Counter
Stores data related to the ramping up/down of the reference.
bool RampComplete
indicates when ramp-up is complete
uint16_t Delay
Soft-Start Period (POD, RAMP PERIOD, PGD, etc.)
uint16_t * ptrReferenceTarget
pointer to the ramp-up reference target
uint16_t * ptrReference
pointer the reference variable
uint16_t Counter
Soft-Start Execution Counter. This setting is set/cleared by the device driver and is 'read only'.
uint16_t StepSize
Size/value of one reference increment/decrement or this period.