Stable enough ADC

This commit is contained in:
Ben V. Brown
2022-04-19 22:23:48 +10:00
parent f397e49533
commit 25283e434f
10 changed files with 404 additions and 382 deletions

View File

@@ -23,19 +23,15 @@ void resetWatchdog() {
uint16_t getHandleTemperature(uint8_t sample) { uint16_t getHandleTemperature(uint8_t sample) {
// We return the current handle temperature in X10 C
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for
// example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) =
// 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125
// mV per count So we need to subtract an offset of 0.5V to center on 0C
// (4964.8 counts)
//
int32_t result = getADCHandleTemp(sample); int32_t result = getADCHandleTemp(sample);
result -= 4965; // remove 0.5V offset result -= 10240; // remove 0.5V offset
// 10mV per C // 10mV per C
// 99.29 counts per Deg C above 0C // 204.7 counts per Deg C above 0C
result *= 100; result *= 10;
result /= 993; result /= 205;
if (result < 0) {
result = 0;
}
return result; return result;
} }
@@ -47,7 +43,6 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
} }
void unstick_I2C() { void unstick_I2C() {
MSG((char *)"I2C Unstick\r\n");
/* configure SDA/SCL for GPIO */ /* configure SDA/SCL for GPIO */
// GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin; // GPIO_BC(GPIOB) |= SDA_Pin | SCL_Pin;
// gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin); // gpio_init(SDA_GPIO_Port, GPIO_MODE_OUT_OD, GPIO_OSPEED_50MHZ, SDA_Pin | SCL_Pin);

View File

@@ -8,7 +8,7 @@
#include "IRQ.h" #include "IRQ.h"
#include "Pins.h" #include "Pins.h"
#include "configuration.h" #include "configuration.h"
#include "expMovingAverage.h" #include "history.hpp"
extern "C" { extern "C" {
#include "bflb_platform.h" #include "bflb_platform.h"
@@ -21,14 +21,15 @@ extern "C" {
#include "hal_timer.h" #include "hal_timer.h"
} }
#define ADC_Filter_Weight 32 #define ADC_Filter_Smooth 4
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Vin; history<uint16_t, ADC_Filter_Smooth> ADC_Vin;
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Temp; history<uint16_t, ADC_Filter_Smooth> ADC_Temp;
expMovingAverage<uint16_t, ADC_Filter_Weight> ADC_Tip; history<uint16_t, ADC_Filter_Smooth> ADC_Tip;
void adc_fifo_irq(void) { void adc_fifo_irq(void) {
if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) { if (ADC_GetIntStatus(ADC_INT_FIFO_READY) == SET) {
ADC_IntClr(ADC_INT_FIFO_READY);
// Read out all entries in the fifo // Read out all entries in the fifo
const uint8_t cnt = ADC_Get_FIFO_Count(); const uint8_t cnt = ADC_Get_FIFO_Count();
@@ -47,41 +48,26 @@ void adc_fifo_irq(void) {
case VIN_ADC_CHANNEL: case VIN_ADC_CHANNEL:
ADC_Vin.update(sample); ADC_Vin.update(sample);
break; break;
case 0: // 0 turns up when an invalid reading is taken
break;
default: default:
// MSG((char *)"ADC Invalid chan %d\r\n", source); MSG((char *)"ADC Invalid chan %d\r\n", source);
break; break;
} }
} }
// MSG((char *)"ADC Reading %d %d %d\r\n", ADC_Temp.average(), ADC_Vin.average(), ADC_Tip.average()); MSG((char *)"ADC Reading %d %d %d\r\n", ADC_Temp.average(), ADC_Vin.average(), ADC_Tip.average());
// Clear IRQ // Clear IRQ
ADC_IntClr(ADC_INT_FIFO_READY);
} }
} }
const ADC_Chan_Type adc_tip_pos_chans[] = {TIP_TEMP_ADC_CHANNEL};
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND};
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
// TODO Do we need to do the stop+start here or can we hot-write the config
void start_adc_tip(void) { void start_adc_tip(void) {
// Reconfigure the ADC to measure the tip temp // Reconfigure the ADC to measure the tip temp
// Single channel input mode // Single channel input mode
// The ADC has a 32 sample FiFo; we set this up to fire and interrupt at 16 samples // The ADC has a 32 sample FiFo; we set this up to fire and interrupt at 16 samples
// Then using that IRQ to know that sampling is done and can be stored // Then using that IRQ to know that sampling is done and can be stored
ADC_Stop();
ADC_Scan_Channel_Config(adc_tip_pos_chans, adc_tip_neg_chans, 1, ENABLE);
ADC_Start(); ADC_Start();
} }
const ADC_Chan_Type adc_misc_pos_chans[] = {TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
const ADC_Chan_Type adc_misc_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND};
static_assert(sizeof(adc_misc_pos_chans) == sizeof(adc_misc_neg_chans));
void start_adc_misc(void) { void stop_adc(void) {}
// Reconfigure the ADC to measure all other inputs in scan mode when we are not measuring the tip
ADC_Stop();
ADC_Scan_Channel_Config(adc_misc_pos_chans, adc_misc_neg_chans, 2, ENABLE);
ADC_Start();
}
static bool fastPWM; static bool fastPWM;
static void switchToSlowPWM(void); static void switchToSlowPWM(void);
@@ -102,7 +88,6 @@ void timer0_irq_callback(struct device *dev, void *args, uint32_t size, uint32_t
// Used to turn tip off at set point in cycle // Used to turn tip off at set point in cycle
PWM_Channel_Disable(PWM_Channel); PWM_Channel_Disable(PWM_Channel);
} else if (state == TIMER_EVENT_COMP2) { } else if (state == TIMER_EVENT_COMP2) {
start_adc_misc();
// This occurs at timer rollover, so if we want to turn on the output PWM; we do so // This occurs at timer rollover, so if we want to turn on the output PWM; we do so
if (PWMSafetyTimer) { if (PWMSafetyTimer) {
PWMSafetyTimer--; PWMSafetyTimer--;
@@ -181,10 +166,8 @@ extern osThreadId POWTaskHandle;
void GPIO_IRQHandler(void) { void GPIO_IRQHandler(void) {
if (SET == GLB_Get_GPIO_IntStatus(FUSB302_IRQ_GLB_Pin)) { if (SET == GLB_Get_GPIO_IntStatus(FUSB302_IRQ_GLB_Pin)) {
GLB_GPIO_IntClear(FUSB302_IRQ_GLB_Pin, SET); GLB_GPIO_IntClear(FUSB302_IRQ_GLB_Pin, SET);
MSG((char *)"GPIO IRQ FUSB\r\n");
#if POW_PD #if POW_PD
if (POWTaskHandle != nullptr) { if (POWTaskHandle != nullptr) {
MSG((char *)"Wake FUSB\r\n");
BaseType_t xHigherPriorityTaskWoken = pdFALSE; BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyFromISR(POWTaskHandle, 1, eSetBits, &xHigherPriorityTaskWoken); xTaskNotifyFromISR(POWTaskHandle, 1, eSetBits, &xHigherPriorityTaskWoken);
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE. /* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
@@ -215,13 +198,14 @@ bool getFUS302IRQLow() {
// return (RESET == gpio_input_bit_get(FUSB302_IRQ_GPIO_Port, FUSB302_IRQ_Pin)); // return (RESET == gpio_input_bit_get(FUSB302_IRQ_GPIO_Port, FUSB302_IRQ_Pin));
} }
uint16_t rescaleADC(const uint16_t value) { uint16_t rescaleADC(const uint16_t value) {
// return value;
uint32_t temp = value * 33; uint32_t temp = value * 33;
uint16_t res = temp / 32; uint16_t res = temp / 32;
return res; return res;
} }
uint16_t getADCHandleTemp(uint8_t sample) { return rescaleADC(ADC_Temp.average() >> 1); } uint16_t getADCHandleTemp(uint8_t sample) { return ADC_Temp.average(); }
uint16_t getADCVin(uint8_t sample) { return rescaleADC(ADC_Vin.average() >> 1); } uint16_t getADCVin(uint8_t sample) { return ADC_Vin.average(); }
// Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned // Returns either average or instant value. When sample is set the samples from the injected ADC are copied to the filter and then the raw reading is returned
uint16_t getTipRawTemp(uint8_t sample) { return rescaleADC(ADC_Tip.average() >> 2); } uint16_t getTipRawTemp(uint8_t sample) { return rescaleADC(ADC_Tip.average() >> 1); }

View File

@@ -12,7 +12,6 @@
#ifdef POW_QC #ifdef POW_QC
void QC_DPlusZero_Six() { void QC_DPlusZero_Six() {
// pull down D+ // pull down D+
// #TODO
gpio_write(QC_DP_LOW_Pin, 0); gpio_write(QC_DP_LOW_Pin, 0);
} }
void QC_DNegZero_Six() { void QC_DNegZero_Six() {

View File

@@ -26,6 +26,9 @@ void hardware_init() {
gpio_set_mode(OLED_RESET_Pin, GPIO_OUTPUT_MODE); gpio_set_mode(OLED_RESET_Pin, GPIO_OUTPUT_MODE);
gpio_set_mode(KEY_A_Pin, GPIO_INPUT_PD_MODE); gpio_set_mode(KEY_A_Pin, GPIO_INPUT_PD_MODE);
gpio_set_mode(KEY_B_Pin, GPIO_INPUT_PD_MODE); gpio_set_mode(KEY_B_Pin, GPIO_INPUT_PD_MODE);
gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE);
gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE);
gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE);
setup_timer_scheduler(); setup_timer_scheduler();
setup_adc(); setup_adc();
@@ -51,6 +54,12 @@ void setup_pwm(void) {
MSG((char *)"PWM Setup returns %d %d\r\n", err, pwm_clk); MSG((char *)"PWM Setup returns %d %d\r\n", err, pwm_clk);
PWM_Channel_Disable(PWM_Channel); PWM_Channel_Disable(PWM_Channel);
} }
const ADC_Chan_Type adc_tip_pos_chans[]
= {TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL, TMP36_ADC_CHANNEL, VIN_ADC_CHANNEL};
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND};
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
void setup_adc(void) { void setup_adc(void) {
MSG((char *)"Setting up ADC\r\n"); MSG((char *)"Setting up ADC\r\n");
// //
@@ -67,9 +76,9 @@ void setup_adc(void) {
adc_cfg.inputMode = ADC_INPUT_SINGLE_END; adc_cfg.inputMode = ADC_INPUT_SINGLE_END;
adc_cfg.v18Sel = ADC_V18_SEL_1P82V; adc_cfg.v18Sel = ADC_V18_SEL_1P82V;
adc_cfg.v11Sel = ADC_V11_SEL_1P1V; adc_cfg.v11Sel = ADC_V11_SEL_1P1V;
adc_cfg.gain1 = ADC_PGA_GAIN_NONE; adc_cfg.gain1 = ADC_PGA_GAIN_1;
adc_cfg.gain2 = ADC_PGA_GAIN_NONE; adc_cfg.gain2 = ADC_PGA_GAIN_1;
adc_cfg.chopMode = ADC_CHOP_MOD_AZ_PGA_ON; adc_cfg.chopMode = ADC_CHOP_MOD_AZ_PGA_RPC_ON;
adc_cfg.biasSel = ADC_BIAS_SEL_MAIN_BANDGAP; adc_cfg.biasSel = ADC_BIAS_SEL_MAIN_BANDGAP;
adc_cfg.vcm = ADC_PGA_VCM_1V; adc_cfg.vcm = ADC_PGA_VCM_1V;
adc_cfg.offsetCalibEn = DISABLE; adc_cfg.offsetCalibEn = DISABLE;
@@ -80,16 +89,17 @@ void setup_adc(void) {
ADC_Reset(); ADC_Reset();
ADC_Init(&adc_cfg); ADC_Init(&adc_cfg);
adc_fifo_cfg.dmaEn = DISABLE; adc_fifo_cfg.dmaEn = DISABLE;
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_16; adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_8;
ADC_FIFO_Cfg(&adc_fifo_cfg); ADC_FIFO_Cfg(&adc_fifo_cfg);
ADC_MIC_Bias_Disable();
// Enable FiFo IRQ // Enable FiFo IRQ
MSG((char *)"Int Enable\r\n");
Interrupt_Handler_Register(GPADC_DMA_IRQn, adc_fifo_irq); Interrupt_Handler_Register(GPADC_DMA_IRQn, adc_fifo_irq);
ADC_IntMask(ADC_INT_FIFO_READY, UNMASK); ADC_IntMask(ADC_INT_FIFO_READY, UNMASK);
CPU_Interrupt_Enable(GPADC_DMA_IRQn); CPU_Interrupt_Enable(GPADC_DMA_IRQn);
MSG((char *)"Start\r\n"); ADC_Stop();
start_adc_misc(); ADC_Scan_Channel_Config(adc_tip_pos_chans, adc_tip_neg_chans, sizeof(adc_tip_pos_chans) / sizeof(ADC_Chan_Type), DISABLE);
MSG((char *)"Started\r\n"); ADC_FIFO_Clear();
} }
struct device *timer0; struct device *timer0;

View File

@@ -105,7 +105,8 @@ static ADC_Gain_Coeff_Type adcGainCoeffCal = {
* @{ * @{
*/ */
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief Software reset the whole ADC * @brief Software reset the whole ADC
* *
* @param None * @param None
@@ -123,7 +124,8 @@ void ADC_Reset(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, BL_CLR_REG_BIT(regCmd, AON_GPADC_SOFT_RST)); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, BL_CLR_REG_BIT(regCmd, AON_GPADC_SOFT_RST));
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC glable enable * @brief ADC glable enable
* *
* @param None * @param None
@@ -139,7 +141,8 @@ void ADC_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC glable disable * @brief ADC glable disable
* *
* @param None * @param None
@@ -155,7 +158,8 @@ void ADC_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC normal mode init * @brief ADC normal mode init
* *
* @param cfg: ADC normal mode configuration * @param cfg: ADC normal mode configuration
@@ -230,7 +234,8 @@ void ADC_Init(ADC_CFG_Type *cfg) {
ADC_Gain_Trim(); ADC_Gain_Trim();
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC normal mode channel config * @brief ADC normal mode channel config
* *
* @param posCh: ADC pos channel type * @param posCh: ADC pos channel type
@@ -260,7 +265,8 @@ void ADC_Channel_Config(ADC_Chan_Type posCh, ADC_Chan_Type negCh, BL_Fun_Type co
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, regCfg1); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, regCfg1);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC scan mode channel config * @brief ADC scan mode channel config
* *
* @param posChList[]: ADC pos channel list type * @param posChList[]: ADC pos channel list type
@@ -333,7 +339,8 @@ void ADC_Scan_Channel_Config(const ADC_Chan_Type posChList[], const ADC_Chan_Typ
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG1, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC normal mode convert start * @brief ADC normal mode convert start
* *
* @param None * @param None
@@ -357,7 +364,8 @@ void ADC_Start(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC normal mode convert stop * @brief ADC normal mode convert stop
* *
* @param None * @param None
@@ -374,7 +382,8 @@ void ADC_Stop(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, regCmd);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC FIFO configuration * @brief ADC FIFO configuration
* *
* @param fifoCfg: ADC FIFO confifuration pointer * @param fifoCfg: ADC FIFO confifuration pointer
@@ -407,7 +416,8 @@ void ADC_FIFO_Cfg(ADC_FIFO_Cfg_Type *fifoCfg) {
BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal); BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC get DMA FIFO data count * @brief ADC get DMA FIFO data count
* *
* @param None * @param None
@@ -423,7 +433,8 @@ uint8_t ADC_Get_FIFO_Count(void) {
return BL_GET_REG_BITS_VAL(tmpVal, GPIP_GPADC_FIFO_DATA_COUNT); return BL_GET_REG_BITS_VAL(tmpVal, GPIP_GPADC_FIFO_DATA_COUNT);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC get DMA FIFO full status * @brief ADC get DMA FIFO full status
* *
* @param None * @param None
@@ -443,7 +454,8 @@ BL_Sts_Type ADC_FIFO_Is_Full(void) {
} }
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC get DMA FIFO empty status * @brief ADC get DMA FIFO empty status
* *
* @param None * @param None
@@ -463,7 +475,8 @@ BL_Sts_Type ADC_FIFO_Is_Empty(void) {
} }
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC read DMA FIFO data * @brief ADC read DMA FIFO data
* *
* @param None * @param None
@@ -479,7 +492,8 @@ uint32_t ADC_Read_FIFO(void) {
return (tmpVal); return (tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC parse result * @brief ADC parse result
* *
* @param orgVal: Original A to D value * @param orgVal: Original A to D value
@@ -558,7 +572,8 @@ void ADC_Parse_Result(uint32_t *orgVal, uint32_t len, ADC_Result_Type *result) {
} }
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC mask or unmask certain or all interrupt * @brief ADC mask or unmask certain or all interrupt
* *
* @param intType: interrupt type * @param intType: interrupt type
@@ -610,7 +625,8 @@ BL_Mask_Type ADC_IntGetMask(ADC_INT_Type intType) {
return 0; return 0;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC mask or unmask certain or all interrupt * @brief ADC mask or unmask certain or all interrupt
* *
* @param intType: interrupt type * @param intType: interrupt type
@@ -745,7 +761,8 @@ void ADC_IntMask(ADC_INT_Type intType, BL_Mask_Type intMask) {
} }
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC clear certain or all interrupt * @brief ADC clear certain or all interrupt
* *
* @param intType: interrupt type * @param intType: interrupt type
@@ -891,7 +908,8 @@ void ADC_IntClr(ADC_INT_Type intType) {
} }
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC get interrupt status * @brief ADC get interrupt status
* *
* @param intType: interrupt type * @param intType: interrupt type
@@ -947,7 +965,8 @@ BL_Sts_Type ADC_GetIntStatus(ADC_INT_Type intType) {
return bitStatus; return bitStatus;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC install interrupt callback * @brief ADC install interrupt callback
* *
* @param intType: ADC interrupt type * @param intType: ADC interrupt type
@@ -963,7 +982,8 @@ void ADC_Int_Callback_Install(ADC_INT_Type intType, intCallback_Type *cbFun) {
adcIntCbfArra[intType] = cbFun; adcIntCbfArra[intType] = cbFun;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC DMA interrupt handler * @brief ADC DMA interrupt handler
* *
* @param None * @param None
@@ -1023,7 +1043,8 @@ void GPADC_DMA_IRQHandler(void) {
} }
#endif #endif
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC VBAT enable * @brief ADC VBAT enable
* *
* @param None * @param None
@@ -1039,7 +1060,8 @@ void ADC_Vbat_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC VBAT disable * @brief ADC VBAT disable
* *
* @param None * @param None
@@ -1055,7 +1077,8 @@ void ADC_Vbat_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC TSEN Config * @brief ADC TSEN Config
* *
* @param tsenMod: None * @param tsenMod: None
@@ -1118,7 +1141,8 @@ void ADC_Tsen_Init(ADC_TSEN_MOD_Type tsenMod) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC TSEN Enable * @brief ADC TSEN Enable
* *
* @return None * @return None
@@ -1132,7 +1156,8 @@ void ADC_Tsen_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC TSEN Disable * @brief ADC TSEN Disable
* *
* @return None * @return None
@@ -1146,7 +1171,8 @@ void ADC_Tsen_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC Clear fifo * @brief ADC Clear fifo
* *
* @return None * @return None
@@ -1161,7 +1187,8 @@ void ADC_FIFO_Clear(void) {
BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal); BL_WR_REG(GPIP_BASE, GPIP_GPADC_CONFIG, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief config pga * @brief config pga
* *
* @param pga_vcmi_enable: enable or not vcmi * @param pga_vcmi_enable: enable or not vcmi
@@ -1184,7 +1211,8 @@ void ADC_PGA_Config(uint8_t pga_vcmi_enable, uint8_t pga_os_cal) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief TSEN_Get_V_Error * @brief TSEN_Get_V_Error
* *
* @param None * @param None
@@ -1243,7 +1271,8 @@ uint32_t TSEN_Get_V_Error(void) {
return v_error; return v_error;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief Trim TSEN * @brief Trim TSEN
* *
* @param tsen_offset: None * @param tsen_offset: None
@@ -1266,7 +1295,8 @@ BL_Err_Type ATTR_CLOCK_SECTION ADC_Trim_TSEN(uint16_t *tsen_offset) {
return ERROR; return ERROR;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH * @brief SET ADC TSEN TSVBE LOW/HIGH
* *
* @param None * @param None
@@ -1281,7 +1311,8 @@ void ADC_SET_TSVBE_LOW(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH * @brief SET ADC TSEN TSVBE LOW/HIGH
* *
* @param None * @param None
@@ -1296,7 +1327,8 @@ void ADC_SET_TSVBE_HIGH(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CONFIG2, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief SET ADC TSEN TSVBE LOW/HIGH * @brief SET ADC TSEN TSVBE LOW/HIGH
* *
* @param tsen_offset: tsen_offset form efuse trim data * @param tsen_offset: tsen_offset form efuse trim data
@@ -1360,7 +1392,8 @@ float TSEN_Get_Temp(uint32_t tsen_offset) {
return temp; return temp;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC MIC Config * @brief ADC MIC Config
* *
* @param adc_mic_config: adc_mic_config * @param adc_mic_config: adc_mic_config
@@ -1404,7 +1437,8 @@ BL_Err_Type ADC_Mic_Init(ADC_MIC_Type *adc_mic_config) {
return SUCCESS; return SUCCESS;
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC MIC bias control * @brief ADC MIC bias control
* *
* @param None * @param None
@@ -1420,7 +1454,8 @@ void ADC_MIC_Bias_Enable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief ADC MIC bias control * @brief ADC MIC bias control
* *
* @param None * @param None
@@ -1436,7 +1471,8 @@ void ADC_MIC_Bias_Disable(void) {
BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal); BL_WR_REG(AON_BASE, AON_GPADC_REG_CMD, tmpVal);
} }
/****************************************************************************/ /** /****************************************************************************/
/**
* @brief Trim ADC Gain * @brief Trim ADC Gain
* *
* @param None * @param None

View File

@@ -268,7 +268,7 @@ void bl_show_info(void) {
MSG("Build:%s,%s\r\n", __TIME__, __DATE__); MSG("Build:%s,%s\r\n", __TIME__, __DATE__);
MSG("Copyright (c) 2021 Bouffalolab team\r\n"); MSG("Copyright (c) 2021 Bouffalolab team\r\n");
#if 0 #if 1
MSG("root clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK) / 1000000); /*root clock before f_div*/ MSG("root clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_ROOT_CLOCK) / 1000000); /*root clock before f_div*/
MSG("fclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_FCLK) / 1000000); /*after f_div,this is system core clock*/ MSG("fclk clock:%dM\r\n", system_clock_get(SYSTEM_CLOCK_FCLK) / 1000000); /*after f_div,this is system core clock*/

View File

@@ -49,7 +49,7 @@
#define BSP_IR_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK #define BSP_IR_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
#define BSP_IR_CLOCK_DIV 0 #define BSP_IR_CLOCK_DIV 0
#define BSP_ADC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK #define BSP_ADC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_XCLK
#define BSP_ADC_CLOCK_DIV 128 #define BSP_ADC_CLOCK_DIV 255
#define BSP_DAC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_AUPLL_24000000_HZ #define BSP_DAC_CLOCK_SOURCE ROOT_CLOCK_SOURCE_AUPLL_24000000_HZ
#define BSP_DAC_CLOCK_DIV 2 #define BSP_DAC_CLOCK_DIV 2
#define BSP_CAM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_PLL_96M #define BSP_CAM_CLOCK_SOURCE ROOT_CLOCK_SOURCE_PLL_96M

View File

@@ -115,7 +115,7 @@
#ifdef MODEL_Magic #ifdef MODEL_Magic
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C #define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic #define VOLTAGE_DIV 600 // 290 - Default divider from schematic
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV #define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
#define MIN_CALIBRATION_OFFSET 100 // Min value for calibration #define MIN_CALIBRATION_OFFSET 100 // Min value for calibration
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit #define PID_POWER_LIMIT 70 // Sets the max pwm power limit

View File

@@ -64,7 +64,7 @@
#define ADC0_CONFIG \ #define ADC0_CONFIG \
{ \ { \
.clk_div = ADC_CLOCK_DIV_32, .vref = ADC_VREF_3V2, .continuous_conv_mode = DISABLE, .differential_mode = DISABLE, .data_width = ADC_DATA_WIDTH_16B_WITH_256_AVERAGE, \ .clk_div = ADC_CLOCK_DIV_32, .vref = ADC_VREF_3V2, .continuous_conv_mode = DISABLE, .differential_mode = DISABLE, .data_width = ADC_DATA_WIDTH_16B_WITH_256_AVERAGE, \
.fifo_threshold = ADC_FIFO_THRESHOLD_1BYTE, .gain = ADC_GAIN_1 \ .fifo_threshold = ADC_FIFO_THRESHOLD_8BYTE, .gain = ADC_GAIN_1 \
} }
#endif #endif
#endif #endif

View File

@@ -665,8 +665,6 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// If we have tripped thermal runaway, turn off heater and show warning // If we have tripped thermal runaway, turn off heater and show warning
if (heaterThermalRunaway) { if (heaterThermalRunaway) {
currentTempTargetDegC = 0; // heater control off currentTempTargetDegC = 0; // heater control off
// TODO WARNING
warnUser(translatedString(Tr->WarningThermalRunaway), 10 * TICKS_SECOND); warnUser(translatedString(Tr->WarningThermalRunaway), 10 * TICKS_SECOND);
heaterThermalRunaway = false; heaterThermalRunaway = false;
return; return;
@@ -800,15 +798,15 @@ void showDebugMenu(void) {
} }
void showWarnings() { void showWarnings() {
MSG((char *)"showWarningsshowWarnings\r\n"); // MSG((char *)"showWarningsshowWarnings\r\n");
return; return; // TODO remove this patch
// Display alert if settings were reset // Display alert if settings were reset
if (settingsWereReset) { if (settingsWereReset) {
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr); // MSG((char *)"WarnUser - %ld\r\n\r\n", (uint64_t)Tr);
warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND); warnUser(translatedString(Tr->SettingsResetMessage), 10 * TICKS_SECOND);
} }
@@ -817,7 +815,7 @@ void showWarnings() {
// In this case though, we dont want to nag the user _too_ much // In this case though, we dont want to nag the user _too_ much
// So only show first 2 times // So only show first 2 times
while (DetectedAccelerometerVersion == AccelType::Scanning) { while (DetectedAccelerometerVersion == AccelType::Scanning) {
MSG((char *)"Accel Detect"); // MSG((char *)"Accel Detect");
osDelay(5); osDelay(5);
} }
// Display alert if accelerometer is not detected // Display alert if accelerometer is not detected
@@ -847,14 +845,14 @@ uint8_t disconnectedTipF[sizeof(disconnectedTip)];
/* StartGUITask function */ /* StartGUITask function */
void startGUITask(void const *argument) { void startGUITask(void const *argument) {
(void)argument; (void)argument;
MSG((char *)"startGUITask\r\n"); // MSG((char *)"startGUITask\r\n");
prepareTranslations(); prepareTranslations();
MSG((char *)"OLEDInit\r\n"); // MSG((char *)"OLEDInit\r\n");
OLED::initialize(); // start up the LCD OLED::initialize(); // start up the LCD
MSG((char *)"setBrightness\r\n"); // MSG((char *)"setBrightness\r\n");
OLED::setBrightness(getSettingValue(SettingsOptions::OLEDBrightness)); OLED::setBrightness(getSettingValue(SettingsOptions::OLEDBrightness));
MSG((char *)"setInverseDisplay\r\n"); // MSG((char *)"setInverseDisplay\r\n");
OLED::setInverseDisplay(getSettingValue(SettingsOptions::OLEDInversion)); OLED::setInverseDisplay(getSettingValue(SettingsOptions::OLEDInversion));
uint8_t tempWarningState = 0; uint8_t tempWarningState = 0;
@@ -862,7 +860,7 @@ void startGUITask(void const *argument) {
bool tempOnDisplay = false; bool tempOnDisplay = false;
bool tipDisconnectedDisplay = false; bool tipDisconnectedDisplay = false;
bool showExitMenuTransition = false; bool showExitMenuTransition = false;
MSG((char *)"flip\r\n"); // MSG((char *)"flip\r\n");
{ {
// Generate the flipped screen into ram for later use // Generate the flipped screen into ram for later use
@@ -875,24 +873,24 @@ void startGUITask(void const *argument) {
} }
} }
} }
MSG((char *)"tipTemp\r\n"); // MSG((char *)"tipTemp\r\n");
getTipRawTemp(1); // reset filter getTipRawTemp(1); // reset filter
MSG((char *)"setRotation\r\n"); // MSG((char *)"setRotation\r\n");
OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1); OLED::setRotation(getSettingValue(SettingsOptions::OrientationMode) & 1);
MSG((char *)"Bootlogo\r\n"); // MSG((char *)"Bootlogo\r\n");
// BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR); // BootLogo::handleShowingLogo((uint8_t *)FLASH_LOGOADDR);
MSG((char *)"showWarnings\r\n"); // MSG((char *)"showWarnings\r\n");
showWarnings(); showWarnings();
MSG((char *)"AutoStartMode\r\n"); // MSG((char *)"AutoStartMode\r\n");
if (getSettingValue(SettingsOptions::AutoStartMode)) { if (getSettingValue(SettingsOptions::AutoStartMode)) {
// jump directly to the autostart mode // jump directly to the autostart mode
gui_solderingMode(getSettingValue(SettingsOptions::AutoStartMode) - 1); gui_solderingMode(getSettingValue(SettingsOptions::AutoStartMode) - 1);
buttonLockout = true; buttonLockout = true;
} }
MSG((char *)"GUI Thread Start\r\n"); // MSG((char *)"GUI Thread Start\r\n");
for (;;) { for (;;) {
ButtonState buttons = getButtonState(); ButtonState buttons = getButtonState();