Bar Logo 4kW dsPIC33C PSFB DC-DC DA (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
45uint16_t PwrCtrl_UpdateAverageRolling(AVERAGING_ROLLING_t* data, uint16_t sample)
46{
47 data->Accumulator -= data->samples[data->Index]; //remove
48 data->samples[data->Index]= sample; //store
49 data->Accumulator += sample; //add the sample
50 //data->index = (data->index+1) % data->AveragingCount; //next index
51 __builtin_divmodud(data->Index+1, ROLLING_AVG_SAMPLE_POINTS, &data->Index); //next index
52 data->AverageValue = (uint16_t)(__builtin_divud(data->Accumulator, ROLLING_AVG_SAMPLE_POINTS));
53 return (data->AverageValue);
54}
55
56
57
58
69{
70 rampUp->RampComplete = false;
71
72 if (++rampUp->Counter > rampUp->Delay)
73 {
74 rampUp->Counter = 0;
75
76 if(*rampUp->ptrReference == *rampUp->ptrReferenceTarget)
77 {
78 rampUp->RampComplete = true;
79 }
80 else if ((*rampUp->ptrReference + rampUp->StepSize) < *rampUp->ptrReferenceTarget)
81 {
82 *rampUp->ptrReference += rampUp->StepSize;
83 }
84 else if ((*rampUp->ptrReference - rampUp->StepSize) > *rampUp->ptrReferenceTarget)
85 {
86 *rampUp->ptrReference -= rampUp->StepSize;
87 }
88 else
89 {
90 *rampUp->ptrReference = *rampUp->ptrReferenceTarget;
91 rampUp->RampComplete = true;
92 }
93 }
94
95 return (rampUp->RampComplete);
96}
97
bool PwrCtrl_RampReference(START_UP_RAMP_t *rampUp)
Softly increment / decrement to the set reference target.
uint16_t PwrCtrl_UpdateAverageRolling(AVERAGING_ROLLING_t *data, uint16_t sample)
Rolling Average the raw data over number of samples.
uint16_t PwrCtrl_UpdateAverage(AVERAGING_t *data, uint16_t sample)
Average the raw data over number of samples.
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.
Averaging data type.
uint32_t Accumulator
uint16_t AveragingCount
uint16_t AverageValue
uint16_t samples[ROLLING_AVG_SAMPLE_POINTS]