diff --git a/code/ina226.c b/code/ina226.c new file mode 100644 index 0000000..e60eb0e --- /dev/null +++ b/code/ina226.c @@ -0,0 +1,98 @@ +// 文件编码: GB18030 +/* + * ina226.c + * + * Created on: 2025年10月16日 + * Author: LHYe200 + */ + + +#include "ina226.h" +#include "zf_driver_soft_iic.h" + +static uint8 is_iic_init = 0; +INA226_t ina226[INA226_NUM]; + +static soft_iic_info_struct ina226_soft_iic_config; + + +void INA226_Init() +{ + uint8 addr_list[INA226_NUM] = INA226_ADDR; + uint8 mode[2] = INA226_DEF_MODE; + float max_current_A = 20.0f; + float rshunt_mOhm = 10.0f; + float amp_fix_k = 1.0f; + float vot_fix_k = 1.0f; + uint8 counter; + + for(counter = 0; counter < INA226_NUM; counter++) + { + INA226_Single_Init(&ina226[counter], addr_list[counter], mode, max_current_A, rshunt_mOhm, amp_fix_k, vot_fix_k); + } +} + +void INA226_Single_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_current_A, float rshunt_mOhm, float amp_fix_k, float vot_fix_k) +{ + float cal; + if(!is_iic_init) + { + soft_iic_init(&ina226_soft_iic_config, addr, INA226_SOFT_WAIT_TIME, INA226_SCL_PIN, INA226_SDA_PIN); + is_iic_init = 1; + } + ina226->config.addr = addr; + ina226->config.mode[0] = mode[0]; + ina226->config.mode[1] = mode[1]; + ina226->config.max_current_A = max_current_A; + ina226->config.rshunt_mOhm = rshunt_mOhm; + ina226->config.vot_fix_k = vot_fix_k; + ina226->config.amp_fix_k = amp_fix_k; + + ina226->calibration.c_lsb_mA = max_current_A / 65.535f; // Current LSB + cal = (5120.0f) / (ina226->calibration.c_lsb_mA * ina226->config.rshunt_mOhm) * ina226->config.amp_fix_k; + ina226->calibration.cal[0] = (uint8)((uint16)cal >> 8); + ina226->calibration.cal[1] = (uint8)((uint16)cal & 0xFF); + + memset(&ina226->result, 0, sizeof(ina226->result)); + + soft_iic_write_8bit_registers(&ina226_soft_iic_config, INA226_CONFIG_REG, ina226->config.mode, 2); + soft_iic_write_8bit_registers(&ina226_soft_iic_config, INA226_CALIBRATION_REG, ina226->calibration.cal, 2); + +} + +void INA226_Read(INA226_t *ina226) +{ + uint8 counter; + if(!is_iic_init) return; + + ina226_soft_iic_config.addr = ina226->config.addr; + + // Read voltage, current, power, and shunt voltage registers + + soft_iic_read_8bit_registers(&ina226_soft_iic_config, INA226_BUSVOT_REG, ina226->result.org_reg[1],2); + soft_iic_read_8bit_registers(&ina226_soft_iic_config, INA226_CURRENT_REG, ina226->result.org_reg[3],2); + soft_iic_read_8bit_registers(&ina226_soft_iic_config, INA226_POWER_REG, ina226->result.org_reg[2],2); + soft_iic_read_8bit_registers(&ina226_soft_iic_config, INA226_SHUNTVOT_REG, ina226->result.org_reg[0],2); + + + ina226->result.voltage_V = (int16)((ina226->result.org_reg[1][0] << 8) | ina226->result.org_reg[1][1]) * 0.00125f; + ina226->result.current_A = (int16)((ina226->result.org_reg[3][0] << 8) | ina226->result.org_reg[3][1]) * ina226->calibration.c_lsb_mA * 0.001f; + ina226->result.power_W = (int16)((ina226->result.org_reg[2][0] << 8) | ina226->result.org_reg[2][1]) * ina226->calibration.c_lsb_mA * 0.025f; + ina226->result.shunt_voltage_mV = (int16)((ina226->result.org_reg[0][0] << 8) | ina226->result.org_reg[0][1]) * 0.0025f; + + ina226->result.voltage_V = ina226->result.voltage_V > 0 ? ina226->result.voltage_V : 0; + ina226->result.current_A = ina226->result.current_A > 0 ? ina226->result.current_A : 0; + ina226->result.power_W = ina226->result.power_W > 0.016 && ina226->result.current_A > 0 && ina226->result.voltage_V > 0 ? ina226->result.power_W : 0; + ina226->result.shunt_voltage_mV = ina226->result.shunt_voltage_mV > 0 ? ina226->result.shunt_voltage_mV : 0; + + for(counter = 0; counter < 9; counter++) + { + ina226->result.past_voltage_V[counter] = ina226->result.past_voltage_V[counter+1]; + ina226->result.past_current_A[counter] = ina226->result.past_current_A[counter+1]; + } + ina226->result.past_voltage_V[9] = ina226->result.voltage_V; + ina226->result.past_current_A[9] = ina226->result.current_A; + + ina226->result.energy_J += (ina226->result.past_voltage_V[9] * ina226->result.past_current_A[9] + ina226->result.past_voltage_V[8] * ina226->result.past_current_A[8]) * (INA226_READ_TIME_MS / 2000.0f); + ina226->result.quantity_C += (ina226->result.past_current_A[9] + ina226->result.past_current_A[8]) * (INA226_READ_TIME_MS / 2000.0f); +} diff --git a/code/ina226.h b/code/ina226.h new file mode 100644 index 0000000..7c32ea9 --- /dev/null +++ b/code/ina226.h @@ -0,0 +1,84 @@ +// 文件编码: GB18030 +/* + * ina226.h + * + * Created on: 2025年10月16日 + * Author: LHYe200 + */ + +#ifndef CODE_INA226_H_ +#define CODE_INA226_H_ + +#include "zf_common_typedef.h" + +#define INA226_NUM 2 + +#define INA226_ALT_PIN {P15_2, P15_3} +#define INA226_ADDR {0x40, 0x45} +#define INA226_DEF_MODE {0x44, 0x4F} +#define INA226_DEF_CAL {0x0D, 0x1B} + + +#define INA226_READ_TIME_MS 1 + + +#define INA226_SOFT_WAIT_TIME 0 + +#define INA226_SDA_PIN P15_1 +#define INA226_SCL_PIN P15_0 + + +#define INA226_CONFIG_REG 0x00 +#define INA226_SHUNTVOT_REG 0x01 +#define INA226_BUSVOT_REG 0x02 +#define INA226_POWER_REG 0x03 +#define INA226_CURRENT_REG 0x04 +#define INA226_CALIBRATION_REG 0x05 + + + + +typedef struct +{ + uint8 addr; + float max_current_A; + float rshunt_mOhm; + float vot_fix_k; + float amp_fix_k; + uint8 mode[2]; +} INA226_Config; + +typedef struct +{ + float c_lsb_mA; + uint8 cal[2]; +} INA226_Calibration; + +typedef struct +{ + float voltage_V; + float current_A; + float power_W; + float shunt_voltage_mV; + float energy_J; + float quantity_C; + uint8 alert_flag; + uint8 org_reg[4][2]; + float past_voltage_V[10]; + float past_current_A[10]; +} INA226_Result; + +typedef struct +{ + INA226_Config config; + INA226_Calibration calibration; + INA226_Result result; +} INA226_t; + +extern INA226_t ina226[INA226_NUM]; + +void INA226_Single_Init(INA226_t *ina226, uint8 addr, uint8 mode[2], float max_current_A, float rshunt_mOhm, float amp_fix_k, float vot_fix_k); +void INA226_Read(INA226_t *ina226); + + +#endif /* CODE_INA226_H_ */ diff --git a/code/power_out.c b/code/power_out.c new file mode 100644 index 0000000..0fe57fa --- /dev/null +++ b/code/power_out.c @@ -0,0 +1,146 @@ +/* + * power_out.c + * + * Created on: 2025年10月16日 + * Author: LHYe200 + */ + + +#include "power_out.h" +#include "zf_driver_adc.h" +#include "zf_driver_pwm.h" +#include "zf_driver_gpio.h" + + +Power_Out_t power_outs[POWER_OUT_NUM]; + + + + +void Power_Out_Single_Init(Power_Out_t *power_out, int16 vot_channel, int16 amp_channel, float votK[2], float ampK[2], int16 enable_pin, uint8 can_adjust, int16 vot_pwm_channel) +{ + if(enable_pin != POWER_OUT_FUNCTION_DISABLE) + { + gpio_init((gpio_pin_enum)enable_pin, GPO, 0, GPO_PUSH_PULL); + } + power_out->config.voltage_read_channel = vot_channel; + power_out->config.current_read_channel = amp_channel; + Init_lowPass_alpha(&power_out->config.vot_filter, POWER_OUT_READ_TIME_MS / 1000.0f, 10.0f); + Init_lowPass_alpha(&power_out->config.amp_filter, POWER_OUT_READ_TIME_MS / 1000.0f, 10.0f); + power_out->config.votK[0] = votK[0]; + power_out->config.votK[1] = votK[1]; + power_out->config.ampK[0] = ampK[0]; + power_out->config.ampK[1] = ampK[1]; + power_out->config.enable_pin = enable_pin; + power_out->config.can_adjust = can_adjust; + power_out->config.vot_pwm_channel = vot_pwm_channel; + + power_out->status.voltage_V = 0.0f; + power_out->status.current_A = 0.0f; + power_out->status.power_W = 0.0f; + power_out->status.energy_J = 0.0f; + power_out->status.quantity_C = 0.0f; + memset(power_out->status.past_voltage_V, 0, sizeof(power_out->status.past_voltage_V)); + memset(power_out->status.past_current_A, 0, sizeof(power_out->status.past_current_A)); + + power_out->set_voltage_V = 0.0f; + power_out->set_current_A = 0.0f; + power_out->max_power_W = 300.0f; + power_out->enabled = 0; + if(vot_channel != POWER_OUT_FUNCTION_DISABLE) + { + adc_init((adc_channel_enum)vot_channel, ADC_12BIT); + } + if(amp_channel != POWER_OUT_FUNCTION_DISABLE) + { + adc_init((adc_channel_enum)amp_channel, ADC_12BIT); + } + + if(vot_pwm_channel != POWER_OUT_FUNCTION_DISABLE) + { + pwm_init((pwm_channel_enum)vot_pwm_channel, VOT_PWM_FREQUENCY_HZ, 5000); + } +} + +void Power_Out_Init() +{ + int16 vot_channel_list[POWER_OUT_NUM] = POWER_OUT_VOT_ADC_CHANNEL; + int16 amp_channel_list[POWER_OUT_NUM] = POWER_OUT_AMP_ADC_CHANNEL; + int16 vot_pwm_channel_list[POWER_OUT_NUM] = POWER_OUT_VOT_PWM_CHANNEL; + int16 enable_pin_list[POWER_OUT_NUM] = POWER_OUT_ENABLE_PIN; + float votK[POWER_OUT_NUM][2] = POWER_OUT_VOT_ADC_K; + float ampK[POWER_OUT_NUM][2] = POWER_OUT_AMP_ADC_K; + + uint8 counter; + for(counter = 0; counter < POWER_OUT_NUM; counter++) + { + uint8 can_adjust = vot_pwm_channel_list[counter] != -1 ? 1 : 0; + Power_Out_Single_Init(&power_outs[counter], vot_channel_list[counter], amp_channel_list[counter], votK[counter], ampK[counter], enable_pin_list[counter], can_adjust, vot_pwm_channel_list[counter]); + } +} + +void Power_Out_Enable(Power_Out_t *power_out, uint8 enable) +{ + if(power_out->config.enable_pin != POWER_OUT_FUNCTION_DISABLE) + { + gpio_set_level((gpio_pin_enum)power_out->config.enable_pin, enable); + } + power_out->enabled = enable; +} + +void Power_Out_Set_PWM(Power_Out_t *power_out, uint32 duty_cycle) +{ + if(power_out->config.can_adjust && power_out->config.vot_pwm_channel != POWER_OUT_FUNCTION_DISABLE) + { + pwm_set_duty((pwm_channel_enum)power_out->config.vot_pwm_channel, duty_cycle); + } +} + +void Power_Out_Single_Read(Power_Out_t *power_out) +{ + float tmp = 0.0f; + if(power_out->config.voltage_read_channel != POWER_OUT_FUNCTION_DISABLE) + { + // tmp = (float)adc_convert((adc_channel_enum)power_out->config.voltage_read_channel); + tmp = (float)adc_mean_filter_convert((adc_channel_enum)power_out->config.voltage_read_channel,2); + power_out->status.voltage_V = Low_pass_filter(&power_out->config.vot_filter, tmp) * power_out->config.votK[0] + power_out->config.votK[1]; + } + else + { + power_out->status.voltage_V = power_out->set_voltage_V; + } + if(power_out->config.current_read_channel != POWER_OUT_FUNCTION_DISABLE) + { + // tmp = (float)adc_convert((adc_channel_enum)power_out->config.current_read_channel); + tmp = (float)adc_mean_filter_convert((adc_channel_enum)power_out->config.current_read_channel,2); + power_out->status.current_A = Low_pass_filter(&power_out->config.amp_filter, tmp) * power_out->config.ampK[0] + power_out->config.ampK[1]; + power_out->status.current_A = power_out->status.current_A > 0.0f ? power_out->status.current_A : 0.0f; + } + else + { + power_out->status.current_A = power_out->set_current_A; + } + + power_out->status.power_W = power_out->status.voltage_V * power_out->status.current_A; + uint8 counter; + for(counter = 0; counter < 9; counter++) + { + power_out->status.past_voltage_V[counter] = power_out->status.past_voltage_V[counter+1]; + power_out->status.past_current_A[counter] = power_out->status.past_current_A[counter+1]; + } + power_out->status.past_voltage_V[9] = power_out->status.voltage_V; + power_out->status.past_current_A[9] = power_out->status.current_A; + + power_out->status.energy_J += (power_out->status.past_voltage_V[9] * power_out->status.past_current_A[9] + power_out->status.past_voltage_V[8] * power_out->status.past_current_A[8]) * (POWER_OUT_READ_TIME_MS / 2000.0f); + power_out->status.quantity_C += (power_out->status.past_current_A[9] + power_out->status.past_current_A[8]) * (POWER_OUT_READ_TIME_MS / 2000.0f); + +} + +void Power_Out_Read() +{ + uint8 counter; + for(counter = 0; counter < POWER_OUT_NUM; counter++) + { + Power_Out_Single_Read(&power_outs[counter]); + } +} diff --git a/code/power_out.h b/code/power_out.h new file mode 100644 index 0000000..094bac7 --- /dev/null +++ b/code/power_out.h @@ -0,0 +1,76 @@ +/* + * power_out.h + * + * Created on: 2025年10月16日 + * Author: LHYe200 + */ + +#ifndef CODE_POWER_OUT_H_ +#define CODE_POWER_OUT_H_ + +#include "zf_common_typedef.h" +#include "filter.h" + + +#define POWER_OUT_NUM 8 +#define POWER_OUT_READ_TIME_MS 1 + +#define POWER_OUT_FUNCTION_DISABLE -1 + +#define POWER_OUT_VOT_ADC_CHANNEL {ADC0_CH0_A0, ADC0_CH1_A1, ADC0_CH2_A2, ADC0_CH3_A3, ADC0_CH4_A4, ADC0_CH5_A5, ADC0_CH6_A6, ADC0_CH7_A7} +#define POWER_OUT_AMP_ADC_CHANNEL {ADC2_CH3_A35, ADC2_CH4_A36, ADC2_CH5_A37, ADC2_CH6_A38, ADC2_CH7_A39, ADC2_CH10_A44, ADC2_CH11_A45, ADC2_CH12_A46} +#define POWER_OUT_VOT_PWM_CHANNEL {POWER_OUT_FUNCTION_DISABLE, POWER_OUT_FUNCTION_DISABLE, POWER_OUT_FUNCTION_DISABLE, POWER_OUT_FUNCTION_DISABLE, ATOM1_CH0_P02_0, ATOM1_CH1_P02_1, ATOM1_CH2_P02_2, ATOM1_CH3_P02_3} +#define POWER_OUT_ENABLE_PIN {P33_13, P33_12, P33_11, P33_10, P33_7, P33_6, P33_5, P33_4} + +#define POWER_OUT_VOT_ADC_K {{0.0015, -0.0437}, {0.0015, -0.045}, {0.0015, -0.0451}, {0.0015, -0.0451}, {0.0049, 0.0297}, {0.0049, -0.0292}, {0.0049, -0.0179}, {0.0049, 0.0397}} +#define POWER_OUT_AMP_ADC_K {{0.0029, -0.1382}, {0.002868, -0.1325}, {0.0029, -0.1335}, {0.0029, -0.1294}, {0.0029, -0.1083}, {0.0029, -0.1174}, {0.0028, -0.0563}, {0.002831, -0.0786}} + +#define VOT_PWM_FREQUENCY_HZ 100000 + +#define VOT_PROTECT_K {0.9,1.1} // 电压保护系数 +#define AMP_PROTECT_K 1.1 // 电流保护系数 + +typedef struct +{ + float voltage_V; + float current_A; + float power_W; + float energy_J; + float quantity_C; + float past_voltage_V[10]; + float past_current_A[10]; +} Power_Out_Status_t; + +typedef struct +{ + int16 voltage_read_channel; + int16 current_read_channel; + float votK[2]; // 电压校准系数 + float ampK[2]; // 电流校准系数 + low_pass_filter_t vot_filter; + low_pass_filter_t amp_filter; + int16 enable_pin; + uint8 can_adjust; // 是否允许调节输出 + int16 vot_pwm_channel; +} Power_Out_Config_t; + +typedef struct +{ + Power_Out_Config_t config; + Power_Out_Status_t status; + float set_voltage_V; + float set_current_A; + float max_power_W; + uint8 enabled; +} Power_Out_t; + +extern Power_Out_t power_outs[POWER_OUT_NUM]; + +void Power_Out_Single_Init(Power_Out_t *power_out, int16 vot_channel, int16 amp_channel, float votK[2], float ampK[2], int16 enable_pin, uint8 can_adjust, int16 vot_pwm_channel); +void Power_Out_Init(void); +void Power_Out_Enable(Power_Out_t *power_out, uint8 enable); +void Power_Out_Set_PWM(Power_Out_t *power_out, uint32 duty_cycle); +void Power_Out_Single_Read(Power_Out_t *power_out); +void Power_Out_Read(void); + +#endif /* CODE_POWER_OUT_H_ */ diff --git a/code/status_led.c b/code/status_led.c index 63036a4..6ead227 100644 --- a/code/status_led.c +++ b/code/status_led.c @@ -20,6 +20,11 @@ void Status_LED_Init(void) gpio_init((gpio_pin_enum)STATUS_LED_3, GPO, GPIO_HIGH, GPO_PUSH_PULL); gpio_init((gpio_pin_enum)STATUS_LED_4, GPO, GPIO_HIGH, GPO_PUSH_PULL); gpio_init((gpio_pin_enum)STATUS_LED_5, GPO, GPIO_HIGH, GPO_PUSH_PULL); + gpio_init((gpio_pin_enum)STATUS_LED_6, GPO, GPIO_HIGH, GPO_PUSH_PULL); + gpio_init((gpio_pin_enum)STATUS_LED_7, GPO, GPIO_HIGH, GPO_PUSH_PULL); + gpio_init((gpio_pin_enum)STATUS_LED_8, GPO, GPIO_HIGH, GPO_PUSH_PULL); + gpio_init((gpio_pin_enum)STATUS_LED_9, GPO, GPIO_HIGH, GPO_PUSH_PULL); + gpio_init((gpio_pin_enum)STATUS_LED_10, GPO, GPIO_HIGH, GPO_PUSH_PULL); } void Flash_LED(status_led_index_enum led) diff --git a/code/status_led.h b/code/status_led.h index 059586a..15fabea 100644 --- a/code/status_led.h +++ b/code/status_led.h @@ -22,7 +22,7 @@ typedef enum // 枚 STATUS_LED_7 = P11_6, //WHITE STATUS_LED_8 = P11_9, //WARMWHITE STATUS_LED_9 = P10_1, //ICEBLUE - STATUS_LED_20 = P10_2, //PINK + STATUS_LED_10 = P10_2, //PINK }status_led_index_enum; diff --git a/code/vofa_client.h b/code/vofa_client.h index f17f24e..8b47f8b 100644 --- a/code/vofa_client.h +++ b/code/vofa_client.h @@ -11,7 +11,7 @@ #include "zf_common_headfile.h" -#define VOFA_CLIENT_COM_INTERFACE (1) // 0:串口 1:WIFI无线SPI 2:自定义 +#define VOFA_CLIENT_COM_INTERFACE (0) // 0:串口 1:WIFI无线SPI 2:自定义 #define VOFA_RECEIVE_CH (64) // 接收通道数,最大256个通道 #define VOFA_SEND_CH (32) // 发送通道数 diff --git a/user/cpu0_main.c b/user/cpu0_main.c index 38b466d..76fe90c 100644 --- a/user/cpu0_main.c +++ b/user/cpu0_main.c @@ -33,33 +33,88 @@ * 2022-09-15 pudding first version ********************************************************************************************************************/ #include "zf_common_headfile.h" -#pragma section all "cpu0_dsram" -// 将本语句与#pragma section all restore语句之间的全局变量都放在CPU0的RAM中 +#include "power_out.h" +#include "status_led.h" +#include "vofa_client.h" + +#pragma section all "cpu0_dsram" -// 本例程是开源库空工程 可用作移植或者测试各类内外设 -// 本例程是开源库空工程 可用作移植或者测试各类内外设 -// 本例程是开源库空工程 可用作移植或者测试各类内外设 // **************************** 代码区域 **************************** int core0_main(void) { clock_init(); // 获取时钟频率<务必保留> debug_init(); // 初始化默认调试串口 - // 此处编写用户代码 例如外设初始化代码等 + Power_Out_Init(); + Status_LED_Init(); + VOFA_Client_Init(); + ON_LED(STATUS_LED_7); + ON_LED(STATUS_LED_8); + uint32 t = 0; + uint8 dir = 0; + Power_Out_Enable(&power_outs[0], 1); + Power_Out_Enable(&power_outs[1], 1); + Power_Out_Enable(&power_outs[2], 1); + Power_Out_Enable(&power_outs[3], 1); + Power_Out_Enable(&power_outs[4], 1); + Power_Out_Enable(&power_outs[5], 1); + Power_Out_Enable(&power_outs[6], 1); + Power_Out_Enable(&power_outs[7], 1); - // 此处编写用户代码 例如外设初始化代码等 - cpu_wait_event_ready(); // 等待所有核心初始化完毕 + // Power_Out_Set_PWM(&power_outs[4], 3000); + // Power_Out_Set_PWM(&power_outs[5], 4000); + // Power_Out_Set_PWM(&power_outs[6], 5000); + // Power_Out_Set_PWM(&power_outs[7], 6000); + + pit_ms_init(CCU60_CH0, POWER_OUT_READ_TIME_MS); // 初始化PIT0 用于读取电源模块状态 + + cpu_wait_event_ready(); while (TRUE) { - // 此处编写需要循环执行的代码 - - - - - // 此处编写需要循环执行的代码 + Flash_LED(STATUS_LED_6); + + VOFA_Set_JustFloat_Data(0, power_outs[0].status.voltage_V); + VOFA_Set_JustFloat_Data(1, power_outs[0].status.current_A); + VOFA_Set_JustFloat_Data(2, power_outs[1].status.voltage_V); + VOFA_Set_JustFloat_Data(3, power_outs[1].status.current_A); + VOFA_Set_JustFloat_Data(4, power_outs[2].status.voltage_V); + VOFA_Set_JustFloat_Data(5, power_outs[2].status.current_A); + VOFA_Set_JustFloat_Data(6, power_outs[3].status.voltage_V); + VOFA_Set_JustFloat_Data(7, power_outs[3].status.current_A); + VOFA_Set_JustFloat_Data(8, power_outs[4].status.voltage_V); + VOFA_Set_JustFloat_Data(9, power_outs[4].status.current_A); + VOFA_Set_JustFloat_Data(10, power_outs[5].status.voltage_V); + VOFA_Set_JustFloat_Data(11, power_outs[5].status.current_A); + VOFA_Set_JustFloat_Data(12, power_outs[6].status.voltage_V); + VOFA_Set_JustFloat_Data(13, power_outs[6].status.current_A); + VOFA_Set_JustFloat_Data(14, power_outs[7].status.voltage_V); + VOFA_Set_JustFloat_Data(15, power_outs[7].status.current_A); + VOFA_Send_Datas(16); + system_delay_ms(1); + + // if(dir == 0) + // { + // t += 10; + // if(t >= 10000) + // { + // dir = 1; + // t = 10000; + // } + // } + // else + // { + // t -= 10; + // if(t <= 0) + // { + // dir = 0; + // t = 0; + // } + // } + // Power_Out_Set_PWM(&power_outs[7], t); + // system_delay_ms(1); } } diff --git a/user/isr.c b/user/isr.c index f28abbf..8233bc0 100644 --- a/user/isr.c +++ b/user/isr.c @@ -35,7 +35,7 @@ #include "isr_config.h" #include "isr.h" - +#include "power_out.h" // 对于TC系列默认是不支持中断嵌套的,希望支持中断嵌套需要在中断内使用 interrupt_global_enable(0); 来开启中断嵌套 // 简单点说实际上进入中断后TC系列的硬件自动调用了 interrupt_global_disable(); 来拒绝响应任何的中断,因此需要我们自己手动调用 interrupt_global_enable(0); 来开启中断的响应。 @@ -44,7 +44,7 @@ IFX_INTERRUPT(cc60_pit_ch0_isr, 0, CCU6_0_CH0_ISR_PRIORITY) { interrupt_global_enable(0); // 开启中断嵌套 pit_clear_flag(CCU60_CH0); - + Power_Out_Read(); }