140 lines
2.0 KiB
C
140 lines
2.0 KiB
C
/*
|
|
* psu_ctrl.c
|
|
*
|
|
* Created on: Mar 16, 2023
|
|
* Author: Keith.Lloyd
|
|
*/
|
|
#include "psu_ctrl.h"
|
|
#include "arm_math.h"
|
|
#include "fsl_gpio.h"
|
|
#include "spi.h"
|
|
#include "mode.h"
|
|
#include "amps.h"
|
|
#include "frq.h"
|
|
#include "adc.h"
|
|
#include "timer.h"
|
|
#include "utils.h"
|
|
#include "System/system.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
uint8_t PSU_Val_Limit;
|
|
uint8_t Psu_Pot_Val[2]; // 2 byte Data for SPI
|
|
extern uint8_t frequency;
|
|
uint8_t mode,psu_index;
|
|
extern uint8_t Power_Level;
|
|
uint8_t Psu_Pot_Data[5] = {V_18V,V_24V,V_27V,V_36V,V_55V}; // PSU Pot values.
|
|
|
|
extern SYSTEM_DATA_t sys;
|
|
|
|
|
|
void Set_PSU_Voltage(uint8_t value)
|
|
{
|
|
Psu_Pot_Val[0] = 0x0;
|
|
|
|
Psu_Pot_Val[1] = value;
|
|
|
|
Get_Max_PSU_Limit(); // Get the maximum limit to compare to for each frequency or mode
|
|
|
|
if (Psu_Pot_Val[1] > PSU_Val_Limit)
|
|
Psu_Pot_Val[1] = PSU_Val_Limit;
|
|
|
|
SPI0_SendBytes(Psu_Pot_Val, 2, PSU_VCTRL); // Update the Pot
|
|
|
|
}
|
|
|
|
void Get_Max_PSU_Limit(void) // Set up Maximum voltage for PSU
|
|
{
|
|
if (freqArray[frequency].frequency1 > MAX_DTYPE)
|
|
PSU_Val_Limit = MAX_AB_PSU;
|
|
else
|
|
PSU_Val_Limit = MAX_D_PSU;
|
|
|
|
if (mode == BROADCAST)
|
|
PSU_Val_Limit = MAX_BCAST_PSU;
|
|
|
|
if((Check_For_Clamp()))
|
|
PSU_Val_Limit = MAX_CLAMP_PSU;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Adjust_Psu(uint8_t direction)
|
|
{
|
|
|
|
if(direction == UP)
|
|
psu_index++;
|
|
else
|
|
psu_index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Psu_Match(void)
|
|
{// may need tap check plus current and voltage
|
|
if(freqArray[frequency].frequency1 <= MAX_DTYPE) //may need current and impedance check
|
|
{
|
|
switch (Power_Level)
|
|
{
|
|
|
|
case 0:
|
|
Set_PSU_Voltage(V_21V);
|
|
break;
|
|
|
|
case 1:
|
|
Set_PSU_Voltage(V_24V);
|
|
break;
|
|
|
|
case 2:
|
|
Set_PSU_Voltage(V_27V);
|
|
break;
|
|
|
|
case 3:
|
|
Set_PSU_Voltage(V_36V);
|
|
break;
|
|
|
|
case 4:
|
|
Set_PSU_Voltage(V_36V);
|
|
break;
|
|
|
|
default:
|
|
Set_PSU_Voltage(V_36V);
|
|
break;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
bool Wait_For_Psu(float32_t volt_limit)
|
|
{
|
|
uint16_t escape_count;
|
|
|
|
escape_count = 350;
|
|
|
|
while(sys.adc.V_PSU > volt_limit && escape_count > 0 )
|
|
{
|
|
Delay_Ticks(1);
|
|
escape_count--;
|
|
|
|
}
|
|
|
|
if(escape_count > 0)
|
|
return(true);
|
|
else
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|