Cleanup ADC
This commit is contained in:
@@ -8,8 +8,11 @@
|
||||
#include "BSP.h"
|
||||
#include "Pins.h"
|
||||
#include "gd32vf103.h"
|
||||
#include <string.h>
|
||||
#include "systick.h"
|
||||
uint16_t ADCReadings[64]; // room for 32 lots of the pair of readings
|
||||
#define ADC_NORM_CHANNELS 2
|
||||
#define ADC_NORM_SAMPLES 32
|
||||
uint16_t ADCReadings[ADC_NORM_SAMPLES * ADC_NORM_CHANNELS]; // room for 32 lots of the pair of readings
|
||||
|
||||
// Functions
|
||||
void setup_gpio();
|
||||
@@ -42,8 +45,8 @@ void hardware_init() {
|
||||
// channel 0 -> temperature sensor, 1-> VIN
|
||||
uint16_t getADC(uint8_t channel) {
|
||||
uint32_t sum = 0;
|
||||
for (uint8_t i = 0; i < 32; i++)
|
||||
sum += ADCReadings[channel + (i * 2)];
|
||||
for (uint8_t i = 0; i < ADC_NORM_SAMPLES; i++)
|
||||
sum += ADCReadings[channel + (i * ADC_NORM_CHANNELS)];
|
||||
return sum >> 2;
|
||||
}
|
||||
|
||||
@@ -67,13 +70,12 @@ void setup_gpio() {
|
||||
gpio_init(PWM_Out_GPIO_Port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ,
|
||||
PWM_Out_Pin);
|
||||
//Analog Inputs ... as analog inputs
|
||||
gpio_init(TMP36_INPUT_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ,
|
||||
gpio_init(TMP36_INPUT_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ,
|
||||
TMP36_INPUT_Pin);
|
||||
gpio_init(TIP_TEMP_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ,
|
||||
gpio_init(TIP_TEMP_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ,
|
||||
TIP_TEMP_Pin);
|
||||
gpio_init(VIN_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_2MHZ, VIN_Pin);
|
||||
//Timer 2 remap to move timer 2 ch0 to pin PB4
|
||||
// gpio_pin_remap_config(GPIO_TIMER2_PARTIAL_REMAP, ENABLE);
|
||||
gpio_init(VIN_GPIO_Port, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, VIN_Pin);
|
||||
|
||||
//Remap PB4 away from JTAG NJRST
|
||||
gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE);
|
||||
//TODO - rest of pins as floating
|
||||
@@ -83,6 +85,7 @@ void setup_dma() {
|
||||
{
|
||||
/* enable DMA0 clock */
|
||||
rcu_periph_clock_enable(RCU_DMA0);
|
||||
rcu_periph_clock_enable(RCU_DMA1);
|
||||
/* ADC_DMA_channel configuration */
|
||||
dma_parameter_struct dma_data_parameter;
|
||||
|
||||
@@ -92,12 +95,12 @@ void setup_dma() {
|
||||
/* initialize DMA data mode */
|
||||
dma_data_parameter.periph_addr = (uint32_t) (&ADC_RDATA(ADC0));
|
||||
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
|
||||
dma_data_parameter.memory_addr = (uint32_t) (&ADCReadings);
|
||||
dma_data_parameter.memory_addr = (uint32_t) (ADCReadings);
|
||||
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
|
||||
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_32BIT;
|
||||
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
|
||||
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
|
||||
dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;
|
||||
dma_data_parameter.number = 64;
|
||||
dma_data_parameter.number = ADC_NORM_SAMPLES * ADC_NORM_CHANNELS;
|
||||
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
|
||||
dma_init(DMA0, DMA_CH0, &dma_data_parameter);
|
||||
|
||||
@@ -123,88 +126,72 @@ void setup_adc() {
|
||||
//Setup ADC in normal + injected mode
|
||||
//Want it to sample handle temp and input voltage normally via dma
|
||||
//Then injected trigger to sample tip temp
|
||||
|
||||
/* enable ADC0 clock */
|
||||
memset(ADCReadings, 0, sizeof(ADCReadings));
|
||||
rcu_periph_clock_enable(RCU_ADC0);
|
||||
/* enable ADC1 clock */
|
||||
rcu_periph_clock_enable(RCU_ADC1);
|
||||
/* config ADC clock */
|
||||
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV8);
|
||||
/* reset ADC */
|
||||
adc_deinit(ADC0);
|
||||
adc_deinit(ADC1);
|
||||
/* config ADC clock */
|
||||
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV16);
|
||||
//Run in normal parallel + inserted parallel
|
||||
adc_mode_config(ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL);
|
||||
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE | ADC_SCAN_MODE,
|
||||
ENABLE);
|
||||
adc_special_function_config(ADC1, ADC_CONTINUOUS_MODE | ADC_SCAN_MODE,
|
||||
ENABLE);
|
||||
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, ENABLE);
|
||||
adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);
|
||||
adc_special_function_config(ADC1, ADC_CONTINUOUS_MODE, ENABLE);
|
||||
adc_special_function_config(ADC1, ADC_SCAN_MODE, ENABLE);
|
||||
//Align right
|
||||
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
|
||||
adc_data_alignment_config(ADC1, ADC_DATAALIGN_RIGHT);
|
||||
//Setup reading 2 channels on regular mode (Handle Temp + )
|
||||
adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2);
|
||||
adc_channel_length_config(ADC1, ADC_REGULAR_CHANNEL, 2);
|
||||
//Setup reading 2 channels on regular mode (Handle Temp + dc in)
|
||||
adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, ADC_NORM_CHANNELS);
|
||||
adc_channel_length_config(ADC1, ADC_REGULAR_CHANNEL, ADC_NORM_CHANNELS);
|
||||
//Setup the two channels
|
||||
adc_regular_channel_config(ADC0, 0, TMP36_ADC0_CHANNEL,
|
||||
ADC_SAMPLETIME_71POINT5); //temp sensor
|
||||
adc_regular_channel_config(ADC1, 0, TMP36_ADC1_CHANNEL,
|
||||
ADC_SAMPLETIME_71POINT5); //temp sensor
|
||||
adc_regular_channel_config(ADC0, 1, VIN_ADC0_CHANNEL,
|
||||
ADC_SAMPLETIME_71POINT5); //DC Input voltage
|
||||
adc_regular_channel_config(ADC1, 1, VIN_ADC1_CHANNEL,
|
||||
ADC_SAMPLETIME_71POINT5); //DC Input voltage
|
||||
adc_regular_channel_config(ADC0, 0, TMP36_ADC0_CHANNEL, ADC_SAMPLETIME_71POINT5); //temp sensor
|
||||
adc_regular_channel_config(ADC1, 0, TMP36_ADC1_CHANNEL, ADC_SAMPLETIME_71POINT5); //temp sensor
|
||||
adc_regular_channel_config(ADC0, 1, VIN_ADC0_CHANNEL, ADC_SAMPLETIME_71POINT5); //DC Input voltage
|
||||
adc_regular_channel_config(ADC1, 1, VIN_ADC1_CHANNEL, ADC_SAMPLETIME_71POINT5); //DC Input voltage
|
||||
//Setup that we want all 4 inserted readings to be the tip temp
|
||||
adc_channel_length_config(ADC0, ADC_INSERTED_CHANNEL, 4);
|
||||
adc_channel_length_config(ADC1, ADC_INSERTED_CHANNEL, 4);
|
||||
for (int rank = 0; rank < 4; rank++) {
|
||||
adc_inserted_channel_config(ADC0, rank, TIP_TEMP_ADC0_CHANNEL,
|
||||
ADC_SAMPLETIME_1POINT5);
|
||||
adc_inserted_channel_config(ADC1, rank, TIP_TEMP_ADC1_CHANNEL,
|
||||
ADC_SAMPLETIME_1POINT5);
|
||||
adc_inserted_channel_config(ADC0, rank, TIP_TEMP_ADC0_CHANNEL, ADC_SAMPLETIME_1POINT5);
|
||||
adc_inserted_channel_config(ADC1, rank, TIP_TEMP_ADC1_CHANNEL, ADC_SAMPLETIME_1POINT5);
|
||||
}
|
||||
//Setup timer 1 channel 0 to trigger injected measurements
|
||||
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||
|
||||
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||
adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||
// Enable triggers for the ADC
|
||||
adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
|
||||
adc_external_trigger_config(ADC1, ADC_INSERTED_CHANNEL, ENABLE);
|
||||
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
|
||||
adc_software_trigger_enable(ADC1, ADC_REGULAR_CHANNEL);
|
||||
//Setup timer 1 channel 0 to trigger injected measurements
|
||||
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL,
|
||||
ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL,
|
||||
ADC0_1_EXTTRIG_INSERTED_T1_CH0);
|
||||
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE);
|
||||
adc_external_trigger_config(ADC1, ADC_REGULAR_CHANNEL, ENABLE);
|
||||
|
||||
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL,
|
||||
ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||
adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL,
|
||||
ADC0_1_EXTTRIG_REGULAR_NONE);
|
||||
|
||||
adc_tempsensor_vrefint_disable();
|
||||
adc_watchdog_disable(ADC0);
|
||||
adc_watchdog_disable(ADC1);
|
||||
adc_resolution_config(ADC0, ADC_RESOLUTION_12B);
|
||||
adc_resolution_config(ADC1, ADC_RESOLUTION_12B);
|
||||
/* clear the ADC flag */
|
||||
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOC);
|
||||
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOIC);
|
||||
adc_oversample_mode_disable(ADC0);
|
||||
adc_oversample_mode_disable(ADC1);
|
||||
adc_enable(ADC0);
|
||||
adc_enable(ADC1);
|
||||
delay_1ms(1);
|
||||
adc_calibration_enable(ADC0);
|
||||
adc_enable(ADC1);
|
||||
delay_1ms(1);
|
||||
adc_calibration_enable(ADC1);
|
||||
delay_1ms(1);
|
||||
//Enable DMA mode
|
||||
adc_dma_mode_enable(ADC0);
|
||||
//Enable interrupt on end of injected readings
|
||||
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOC);
|
||||
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOIC);
|
||||
adc_interrupt_enable(ADC0, ADC_INT_EOIC);
|
||||
eclic_irq_enable(ADC0_1_IRQn, 2, 0);
|
||||
adc_dma_mode_enable(ADC0);
|
||||
adc_dma_mode_enable(ADC1);
|
||||
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
|
||||
adc_software_trigger_enable(ADC1, ADC_REGULAR_CHANNEL);
|
||||
// adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
|
||||
// adc_software_trigger_enable(ADC1, ADC_REGULAR_CHANNEL);
|
||||
adc_tempsensor_vrefint_disable();
|
||||
}
|
||||
void setup_timers() {
|
||||
//Setup timer 1 to run the actual PWM level
|
||||
|
||||
124
workspace/TS100/Core/Inc/configuration.h
Normal file
124
workspace/TS100/Core/Inc/configuration.h
Normal file
@@ -0,0 +1,124 @@
|
||||
#pragma once
|
||||
/**
|
||||
* Configuration.h
|
||||
* Define here your default pre settings for TS80 or TS100
|
||||
*
|
||||
*/
|
||||
|
||||
//===========================================================================
|
||||
//============================= Default Settings ============================
|
||||
//===========================================================================
|
||||
/**
|
||||
* Default soldering temp is 320.0 C
|
||||
* Temperature the iron sleeps at - default 150.0 C
|
||||
*/
|
||||
#define SOLDERING_TEMP 320 // Default soldering temp is 320.0 °C
|
||||
#define SLEEP_TEMP 150 // Default sleep temperature
|
||||
#define BOOST_TEMP 420 // Default boost temp.
|
||||
#define BOOST_MODE_ENABLED 1 // 0: Disable 1: Enable
|
||||
|
||||
/**
|
||||
* Blink the temperature on the cooling screen when its > 50C
|
||||
*/
|
||||
#define COOLING_TEMP_BLINK 0 // 0: Disable 1: Enable
|
||||
|
||||
/**
|
||||
* How many seconds/minutes we wait until going to sleep/shutdown.
|
||||
* Values -> SLEEP_TIME * 10; i.e. 5*10 = 50 Seconds!
|
||||
*/
|
||||
#define SLEEP_TIME 5 // x10 Seconds
|
||||
#define SHUTDOWN_TIME 10 // Minutes
|
||||
|
||||
/**
|
||||
* Auto start off for safety.
|
||||
* Pissible values are:
|
||||
* 0 - none
|
||||
* 1 - Soldering Temperature
|
||||
* 2 - Sleep Temperature
|
||||
* 3 - Sleep Off Temperature
|
||||
*/
|
||||
#define AUTO_START_MODE 0 // Default to none
|
||||
|
||||
/**
|
||||
* OLED Orientation
|
||||
*
|
||||
*/
|
||||
#define ORIENTATION_MODE 0 // 0: Right 1:Left 2:Automatic - Default right
|
||||
#define REVERSE_BUTTON_TEMP_CHANGE 0 // 0:Default 1:Reverse - Reverse the plus and minus button assigment for temperatur change
|
||||
|
||||
/**
|
||||
* Temp change settings
|
||||
*/
|
||||
#define TEMP_CHANGE_SHORT_STEP 1 // Default temp change short step +1
|
||||
#define TEMP_CHANGE_LONG_STEP 10 // Default temp change long step +10
|
||||
#define TEMP_CHANGE_SHORT_STEP_MAX 50 // Temp change short step MAX value
|
||||
#define TEMP_CHANGE_LONG_STEP_MAX 100 // Temp change long step MAX value
|
||||
|
||||
/* Power pulse for keeping power banks awake*/
|
||||
#define POWER_PULSE_INCREMENT 1
|
||||
#define POWER_PULSE_MAX 50 // x10 max watts
|
||||
#ifdef MODEL_TS100
|
||||
#define POWER_PULSE_DEFAULT 0
|
||||
#else
|
||||
#define POWER_PULSE_DEFAULT 5
|
||||
#endif
|
||||
|
||||
/**
|
||||
* OLED Orientation Sensitivity on Automatic mode!
|
||||
* Motion Sensitivity <0=Off 1=Least Sensitive 9=Most Sensitive>
|
||||
*/
|
||||
#define SENSITIVITY 7 // Default 7
|
||||
|
||||
/**
|
||||
* Detailed soldering screen
|
||||
* Detailed idle screen (off for first time users)
|
||||
*/
|
||||
#define DETAILED_SOLDERING 0 // 0: Disable 1: Enable - Default 0
|
||||
#define DETAILED_IDLE 0 // 0: Disable 1: Enable - Default 0
|
||||
|
||||
#define CUT_OUT_SETTING 0 // default to no cut-off voltage (or 18W for TS80)
|
||||
#define TEMPERATURE_INF 0 // default to 0
|
||||
#define DESCRIPTION_SCROLL_SPEED 0 // 0: Slow 1: Fast - default to slow
|
||||
#define POWER_LIMIT_ENABLE 0 // 0: Disable 1: Enable - Default disabled power limit
|
||||
|
||||
#define TIP_GAIN 210 // 21 uV/C * 10, uV per deg C constant of the tip, Tip uV * 10 / coeff = tip temp
|
||||
|
||||
#define OP_AMP_Rf_TS100 750 * 1000 // 750 Kilo-ohms -> From schematic, R1
|
||||
#define OP_AMP_Rin_TS100 2370 // 2.37 Kilo-ohms -> From schematic, R2
|
||||
|
||||
#define OP_AMP_GAIN_STAGE_TS100 (1 + (OP_AMP_Rf_TS100 / OP_AMP_Rin_TS100))
|
||||
|
||||
#define OP_AMP_Rf_TS80 180 * 1000 // 180 Kilo-ohms -> From schematic, R6
|
||||
#define OP_AMP_Rin_TS80 2000 // 2.0 Kilo-ohms -> From schematic, R3
|
||||
|
||||
#define OP_AMP_GAIN_STAGE_TS80 (1 + (OP_AMP_Rf_TS80 / OP_AMP_Rin_TS80))
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
|
||||
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
||||
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
|
||||
#define POWER_LIMIT 30 // 30 watts default limit
|
||||
#define MAX_POWER_LIMIT 65 //
|
||||
#define POWER_LIMIT_STEPS 5 //
|
||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_TS80
|
||||
#define VOLTAGE_DIV 780 // Default divider from schematic
|
||||
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit
|
||||
#define CALIBRATION_OFFSET 900 // the adc offset in uV
|
||||
#define POWER_LIMIT 24 // 24 watts default power limit
|
||||
#define MAX_POWER_LIMIT 30 //
|
||||
#define POWER_LIMIT_STEPS 2
|
||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
|
||||
#endif
|
||||
|
||||
#ifdef MODEL_Pinecil
|
||||
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
|
||||
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
||||
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
|
||||
#define POWER_LIMIT 30 // 30 watts default limit
|
||||
#define MAX_POWER_LIMIT 65 //
|
||||
#define POWER_LIMIT_STEPS 5 //
|
||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
||||
#endif
|
||||
Reference in New Issue
Block a user