86 lines
2.5 KiB
C
86 lines
2.5 KiB
C
//
|
|
// Created by ilya on 14.12.23.
|
|
//
|
|
#include <stdbool.h>
|
|
#include "Adcs.h"
|
|
#include "at32f435_437.h"
|
|
|
|
|
|
//todo Проверить правильность инициализации Adcs
|
|
void Adc_Battery(tAdc *env){
|
|
//*gpio*//
|
|
gpio_init_type gpio_initstructure;
|
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
|
crm_periph_clock_enable(CRM_ADC2_PERIPH_CLOCK, TRUE);
|
|
|
|
gpio_default_para_init(&gpio_initstructure);
|
|
gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
|
|
gpio_initstructure.gpio_pins = GPIO_PINS_2;
|
|
gpio_init(GPIOA, &gpio_initstructure);
|
|
|
|
//*adc*//
|
|
env->vcc = ADC_Initial(ADC2, ADC_CHANNEL_2,0,env->calibCoef,1);
|
|
env->vccIo = vAdcGetIo(&env->vcc);
|
|
}
|
|
|
|
void Adc_BoardVoltage(tAdc *env){
|
|
// nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
|
|
//*gpio*//
|
|
gpio_init_type gpio_initstructure;
|
|
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
|
|
crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
|
|
|
|
gpio_default_para_init(&gpio_initstructure);
|
|
gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
|
|
gpio_initstructure.gpio_pins = GPIO_PINS_3;
|
|
gpio_init(GPIOC, &gpio_initstructure);
|
|
|
|
env->vcc = ADC_Initial(ADC1, ADC_CHANNEL_13,0,env->calibCoef,1);
|
|
env->vccIo = vAdcGetIo(&env->vcc);
|
|
}
|
|
|
|
void Adc_AntGnss(tAdc *env){
|
|
//*gpio*//
|
|
gpio_init_type gpio_initstructure;
|
|
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
|
|
crm_periph_clock_enable(CRM_ADC3_PERIPH_CLOCK, TRUE);
|
|
|
|
gpio_default_para_init(&gpio_initstructure);
|
|
gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
|
|
gpio_initstructure.gpio_pins = GPIO_PINS_3;
|
|
gpio_init(GPIOA, &gpio_initstructure);
|
|
|
|
env->vcc = ADC_Initial(ADC3, ADC_CHANNEL_3,0,1,1);
|
|
env->vccIo = vAdcGetIo(&env->vcc);
|
|
|
|
}
|
|
tAdcs ADCS;
|
|
|
|
void Adcs_Init() {
|
|
tAdcs *env = &ADCS;
|
|
env->battery.calibCoef = (float)1.60;
|
|
env->boardVoltageVal.calibCoef = 1;// 8.97
|
|
Adc_AntGnss(&env->antGnss);
|
|
Adc_Battery(&env->battery);
|
|
Adc_BoardVoltage(&env->boardVoltageVal);
|
|
}
|
|
|
|
bool Adcs_SetCalibBoardVoltage(tAdc *env, float *externalCalibCoef) {
|
|
env->calibCoef = 1;
|
|
Adc_BoardVoltage(env);
|
|
uint16_t volts = AdcGet(&env->vccIo, 1000);
|
|
*externalCalibCoef = (float)12000.0/(float)volts;
|
|
env->calibCoef = *externalCalibCoef;
|
|
Adc_BoardVoltage(env);
|
|
volts = AdcGet(&env->vccIo, 1000);
|
|
if((volts>11500) && (volts<12500)){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void Adcs_InitBip() {
|
|
tAdcs *env = &ADCS;
|
|
// Adc_BipButtons(&env->bipADC);
|
|
} |