|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
dev_fan.c
Go to the documentation of this file.
1
2
3
10#include "dev_fan.h"
11#include "dev_temp.h"
12#include "config/macros.h"
13
14
21 FAN_DATA_t devFanData;
22 FAN_DATA_t* devFanDataPtr = &devFanData;
23
24 enum FAN_SETTINGS_e {
25 NO_CHANGE = 0,
26 CHANGE_SPEED = 1,
27};
28 typedef enum FAN_SETTINGS_e FAN_SETTINGS_t;
29
30 static FAN_SETTINGS_t changeSpeed = CHANGE_SPEED;
31
32//Private Function Call Prototypes
33static uint16_t Convert_From_Percentage (uint8_t percentage);
34static uint8_t Convert_From_Raw(uint16_t raw);
35static void Override_Speed(void);
36static void Calculate_Speed(void);
37static void Update_Speed(void);
38
39
40
49 void Dev_Fan_Initialize(void)
50{
51 devFanData.CurrentSpeedPercent = 0 ;
52 devFanData.TargetSpeedPercent = INIT_SPEED_PERCENT;
53 devFanData.MaxSpeedPercent = MAX_SPEED_PERCENT;
54 devFanData.Tick = 5 ;
55 devFanData.StepSizePercent = STEP_SIZE ;
56 devFanData.TargetSpeedRaw = 0 ;
57 devFanData.CurrentSpeedRaw = 0 ;
58 devFanData.MaxSpeedRaw = Convert_From_Percentage(MAX_SPEED_PERCENT);
59 //dev_fan_data.hystersis_raw = Convert_From_Percentage(HYSTERESIS);
60 devFanData.OverrideFlag = 0 ;
61}
62
63
76 void Dev_Fan_Task_100ms(void)
77{
78 static uint8_t currentTickCount;
79
80 if (devFanData.OverrideFlag == 1)
81 {
82 changeSpeed = CHANGE_SPEED;
83 Override_Speed();
84 Calculate_Speed();
85 Update_Speed();
86 }
87 else if (++currentTickCount >= devFanData.Tick)
88 {
89 Calculate_Speed();
90 Update_Speed();
91 currentTickCount = 0;
92 }
93}
94
95
110 void Dev_Fan_Task_1s(void)
111{
112 static uint8_t fanSpeedPercent = 0;
113 uint16_t TCelsiusNTC = Dev_Temp_Get_Temperature_Celcius();//
114
115 if(TCelsiusNTC > H_TEMPERATURE_THRESHOLD){
116 fanSpeedPercent += 2;
117 // Fan speed maximum clamping value
118 if(fanSpeedPercent >= MAX_SPEED_PERCENT){
119 fanSpeedPercent = MAX_SPEED_PERCENT;
120 }
121 else{}
122 }
123 else if(TCelsiusNTC < L_TEMPERATURE_THRESHOLD){
124 fanSpeedPercent -= 2;
125 // Fan speed minimum clamping value
126 if(fanSpeedPercent <= 10){
127 fanSpeedPercent = 10;//hw request to have a minimum load on auxiliary supply
128 }
129 else{}
130 }
131 else{}
132
133 Dev_Fan_Set_Speed(fanSpeedPercent);
134}
135
136
145 void Dev_Fan_Set_Override(void)
146{
147 devFanData.OverrideFlag = 1;
148 Override_Speed();
149}
150
151
159 void Dev_Fan_Set_Speed(uint8_t target_speed_percent)
160{
161 if (target_speed_percent <= MAX_SPEED_PERCENT)
162 {
163 devFanData.TargetSpeedPercent = target_speed_percent;
164 }
165}
166
167
175 static uint16_t Convert_From_Percentage(uint8_t percentage_value)
176{
177 return (percentage_value * MULTIPLIER) ;
178}
179
180
187 static void Override_Speed(void)
188{
189 devFanData.TargetSpeedPercent = MAX_SPEED_PERCENT;
190 devFanData.Tick = MIN_TICK;
191}
192
193
200 static void Calculate_Speed(void)
201{
202 devFanData.TargetSpeedPercent -= (devFanData.TargetSpeedPercent % devFanData.StepSizePercent);
203
204 devFanData.TargetSpeedRaw = Convert_From_Percentage(devFanData.TargetSpeedPercent);
205
206 if (devFanData.CurrentSpeedRaw > (devFanData.TargetSpeedRaw ))
207 {
208 devFanData.CurrentSpeedRaw -= Convert_From_Percentage(devFanData.StepSizePercent);
209 changeSpeed = CHANGE_SPEED;
210 }
211
212 else if (devFanData.CurrentSpeedRaw < (devFanData.TargetSpeedRaw ))
213 {
214 devFanData.CurrentSpeedRaw += Convert_From_Percentage(devFanData.StepSizePercent) ;
215 changeSpeed = CHANGE_SPEED;
216 }
217 else
218 {
219 changeSpeed = NO_CHANGE;
220 }
221}
222
223
230 static void Update_Speed(void)
231{
232 if (changeSpeed != NO_CHANGE)
233 {
234 if (devFanData.CurrentSpeedRaw > devFanData.MaxSpeedRaw)
235 {
236 devFanData.CurrentSpeedRaw = devFanData.MaxSpeedRaw;
237 }
238 FAN_PWM_DutyCycleSet(devFanData.CurrentSpeedRaw);
239 devFanData.CurrentSpeedPercent = Convert_From_Raw(devFanData.CurrentSpeedRaw);
240 }
241}
242
243
251 static uint8_t Convert_From_Raw(uint16_t raw)
252{
253 return ( raw * 0.02 ); //TODO: recalculate math
254}
255
256
Convert_From_Raw
static uint8_t Convert_From_Raw(uint16_t raw)
Definition dev_fan.c:251
FAN_SETTINGS_t
enum FAN_SETTINGS_e FAN_SETTINGS_t
Definition dev_fan.c:28
changeSpeed
static FAN_SETTINGS_t changeSpeed
Definition dev_fan.c:30
devFanDataPtr
FAN_DATA_t * devFanDataPtr
Definition dev_fan.c:22
FAN_SETTINGS_e
FAN_SETTINGS_e
Definition dev_fan.c:24
NO_CHANGE
@ NO_CHANGE
Definition dev_fan.c:25
CHANGE_SPEED
@ CHANGE_SPEED
Definition dev_fan.c:26
dev_fan.h
fan device driver
MIN_TICK
#define MIN_TICK
fastest possible tick. needed for override flag.
Definition dev_fan.h:41
STEP_SIZE
#define STEP_SIZE
in percent. needed for overide flag.
Definition dev_fan.h:42
MAX_SPEED_PERCENT
#define MAX_SPEED_PERCENT
macros defining the speed limits
Definition dev_fan.h:39
INIT_SPEED_PERCENT
#define INIT_SPEED_PERCENT
intial start fan value
Definition dev_fan.h:40
MULTIPLIER
#define MULTIPLIER
These have to be renamed to make the fan device driver abstract.
Definition dev_fan.h:30
dev_temp.h
Contains temperature initialization and execution functions.
L_TEMPERATURE_THRESHOLD
#define L_TEMPERATURE_THRESHOLD
Definition macros.h:156
H_TEMPERATURE_THRESHOLD
#define H_TEMPERATURE_THRESHOLD
Definition macros.h:157
Override_Speed
static void Override_Speed(void)
Override the fan speed with maximum speed.
Definition dev_fan.c:187
Dev_Fan_Task_100ms
void Dev_Fan_Task_100ms(void)
this function needs to be called every 100ms it contains the code to update the status of the fan
Definition dev_fan.c:76
Convert_From_Percentage
static uint16_t Convert_From_Percentage(uint8_t percentage)
Converts the percentage value to number of ticks.
Definition dev_fan.c:175
devFanData
FAN_DATA_t devFanData
Data Object of fan.
Definition dev_fan.c:21
Dev_Fan_Set_Speed
void Dev_Fan_Set_Speed(uint8_t target_speed_percent)
Sets the fan speed.
Definition dev_fan.c:159
Calculate_Speed
static void Calculate_Speed(void)
Calculates the fan speed.
Definition dev_fan.c:200
Dev_Fan_Set_Override
void Dev_Fan_Set_Override(void)
Sets the fan override bit and the fan speed.
Definition dev_fan.c:145
Dev_Fan_Initialize
void Dev_Fan_Initialize(void)
This function initializes the fan object.
Definition dev_fan.c:49
Update_Speed
static void Update_Speed(void)
Update the fan speed.
Definition dev_fan.c:230
Dev_Fan_Task_1s
void Dev_Fan_Task_1s(void)
This function needs to be called every 1s to keep the temperature of the board at a certain temperatu...
Definition dev_fan.c:110
Dev_Temp_Get_Temperature_Celcius
int8_t Dev_Temp_Get_Temperature_Celcius(void)
This converts the raw values to temperature celcius as per device lookup table.
Definition dev_temp.c:87
FAN_PWM_DutyCycleSet
#define FAN_PWM_DutyCycleSet
This macro defines the Custom Name for SCCP3_PWM_DutyCycleSet API.
Definition sccp3.h:90
FAN_DATA_s
A custom data type for fan.
Definition dev_fan.h:50
FAN_DATA_s::MaxSpeedRaw
uint16_t MaxSpeedRaw
based on period value (CCXPRL).
Definition dev_fan.h:58
FAN_DATA_s::Tick
uint16_t Tick
set the execution rate in multiples of 100ms
Definition dev_fan.h:54
FAN_DATA_s::OverrideFlag
uint8_t OverrideFlag
override flag. sets tick value to 1, step_size to 20 and target to 100%
Definition dev_fan.h:59
FAN_DATA_s::StepSizePercent
uint16_t StepSizePercent
set the increment rate per tick in percentage
Definition dev_fan.h:55
FAN_DATA_s::CurrentSpeedRaw
uint16_t CurrentSpeedRaw
current value raw.
Definition dev_fan.h:57
FAN_DATA_s::TargetSpeedRaw
uint16_t TargetSpeedRaw
targetted value raw.
Definition dev_fan.h:56
FAN_DATA_s::TargetSpeedPercent
uint8_t TargetSpeedPercent
targetted Speed in percentage
Definition dev_fan.h:52
FAN_DATA_s::MaxSpeedPercent
uint16_t MaxSpeedPercent
based on period value (CCXPRL). Use this to limit the fan max speed
Definition dev_fan.h:53
FAN_DATA_s::CurrentSpeedPercent
uint8_t CurrentSpeedPercent
Current Speed in percentage.
Definition dev_fan.h:51