Skip to content

Commit

Permalink
Add ability to calibrate input DC voltage reading, V1.05
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
Ralim committed May 18, 2017
1 parent ddedd9a commit 1522c41
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 43 deletions.
2 changes: 1 addition & 1 deletion workspace/ts100/inc/Analog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ extern volatile uint16_t ADC1ConvertedValue[2];

uint16_t Get_ADC1Value(uint8_t i);
uint16_t readIronTemp(uint16_t calibration_temp, uint8_t read,uint16_t setPointTemp); //read the iron temp in C X10
uint16_t readDCVoltage();/*Get the system voltage X10*/
uint16_t readDCVoltage(uint16_t divFactor);/*Get the system voltage X10*/
#endif /* ANALOG_H_ */
21 changes: 11 additions & 10 deletions workspace/ts100/inc/Modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
#include "Settings.h"
#include "Analog.h"
enum {
STARTUP, //we are sitting on the prompt to push a button
SOLDERING,
TEMP_ADJ,
SETTINGS,
SLEEP,
COOLING,
UVLOWARN,
THERMOMETER,
DCINDISP,
TEMPCAL,
STARTUP, //we are sitting on the prompt to push a button
SOLDERING, //Normal operating mode
TEMP_ADJ, //Adjust the set temperature
SETTINGS, //Settings menu
SLEEP, //Iron is snoozing due to lack of use
COOLING, //Iron is cooling down -> Warning screen
UVLOWARN, //Unit tripped low voltage
THERMOMETER, //Read the tip temp
DCINDISP, //Disp the input voltage && Cal the DCin voltage divider
TEMPCAL, //Cal tip temp offset

} operatingMode;

enum {
Expand Down
3 changes: 2 additions & 1 deletion workspace/ts100/inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define SETTINGS_H_
#include <stdint.h>
#include "stm32f10x_flash.h"
#define SETTINGSVERSION 0x03 /*Change this if you change the struct below to prevent people getting out of sync*/
#define SETTINGSVERSION 0x04 /*Change this if you change the struct below to prevent people getting out of sync*/
#define SETTINGSOPTIONSCOUNT 6 /*Number of settings in the settings menu*/
#define MOTION_HIGH (0x00)
#define MOTION_MED (0x10)
Expand All @@ -30,6 +30,7 @@ struct {
uint8_t flipDisplay:1; //If true we want to invert the display for lefties
uint8_t sensitivity:7; //Sensitivity of accelerometer
uint16_t tempCalibration; //Temperature calibration value
uint16_t voltageDiv; //Voltage divisor factor
} systemSettings;

void saveSettings();
Expand Down
4 changes: 2 additions & 2 deletions workspace/ts100/src/Analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

//Reads the dc input and returns it as X10 voltage (ie 236 = 23.6V)
//Seems unstable below 9.5V input
uint16_t readDCVoltage() {
uint16_t readDCVoltage(uint16_t divFactor) {
uint16_t reading = 0;
for (u8 i = 0; i < 10; i++) {
reading += ADC_GetConversionValue(ADC2);
}
reading /= 144; //take the average and convert to X10 voltage
reading /= divFactor; //take the average and convert to X10 voltage
return reading; //return the read voltage
}

Expand Down
2 changes: 1 addition & 1 deletion workspace/ts100/src/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void setup() {
readIronTemp(systemSettings.tempCalibration, 0,0); //load the default calibration value
Init_Oled(systemSettings.flipDisplay); //Init the OLED display

OLED_DrawString("VER 1.04", 8); //
OLED_DrawString("VER 1.05", 8); //
delayMs(800); //Pause to show version number
Start_Watchdog(1000); //start the system watch dog as 1 second timeout
}
83 changes: 56 additions & 27 deletions workspace/ts100/src/Modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Author: Ralim <ralim@ralimtek.com>
*/
#include "Modes.h"
uint8_t tempCalStatus = 0;
uint8_t CalStatus = 0;
//This does the required processing and state changes
void ProcessUI() {
uint8_t Buttons = getButtons(); //read the buttons status
Expand Down Expand Up @@ -51,7 +51,7 @@ void ProcessUI() {
return;
}
}
uint16_t voltage = readDCVoltage(); //get X10 voltage
uint16_t voltage = readDCVoltage(systemSettings.voltageDiv); //get X10 voltage
if ((voltage / 10) < systemSettings.cutoutVoltage) {
operatingMode = UVLOWARN;
lastModeChange = millis();
Expand Down Expand Up @@ -180,9 +180,10 @@ void ProcessUI() {

if (Buttons == BUT_A) {
//Single button press, cycle over to the DC display
CalStatus = 0;
operatingMode = DCINDISP;
} else if (Buttons == BUT_B) {
tempCalStatus = 0;
CalStatus = 0;
operatingMode = TEMPCAL;
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
Expand All @@ -193,13 +194,37 @@ void ProcessUI() {
break;
case DCINDISP: {
//This lets the user check the input voltage

if (Buttons == BUT_A) {
//Single button press, cycle over to the temp display
operatingMode = THERMOMETER;
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
operatingMode = STARTUP;
if (CalStatus == 0) {
if (Buttons == BUT_A) {
//Single button press, cycle over to the temp display
operatingMode = THERMOMETER;
} else if (Buttons == BUT_B) {
//dc cal mode
CalStatus = 1;
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
operatingMode = STARTUP;
}
} else {
//User is calibrating the dc input
if (Buttons == BUT_A) {
if (!systemSettings.flipDisplay)
systemSettings.voltageDiv++;
else
systemSettings.voltageDiv--;
} else if (Buttons == BUT_B) {
if (!systemSettings.flipDisplay)
systemSettings.voltageDiv--;
else
systemSettings.voltageDiv++;
} else if (Buttons == (BUT_A | BUT_B)) {
CalStatus = 0;
saveSettings();
}
if (systemSettings.voltageDiv < 120)
systemSettings.voltageDiv = 160;
else if (systemSettings.voltageDiv > 160)
systemSettings.voltageDiv = 120;
}

}
Expand All @@ -210,13 +235,13 @@ void ProcessUI() {
operatingMode = THERMOMETER;
} else if (Buttons == BUT_A) {
//Try and calibrate
if (tempCalStatus == 0) {
if (CalStatus == 0) {
if ((readTipTemp() < 300) && (readSensorTemp() < 300)) {
tempCalStatus = 1;
CalStatus = 1;
systemSettings.tempCalibration = readTipTemp();
saveSettings();
} else {
tempCalStatus = 2;
CalStatus = 2;
}
}
} else if (Buttons == (BUT_A | BUT_B)) {
Expand All @@ -237,7 +262,7 @@ void drawTemp(uint16_t temp, uint8_t x) {
if (systemSettings.displayTempInF)
temp = (temp * 9 + 1600) / 5;/*Convert to F -> T*(9/5)+32*/
if (temp % 10 > 5)
temp += 10;//round up
temp += 10; //round up
OLED_DrawThreeNumber(temp / 10, x);
}

Expand Down Expand Up @@ -370,26 +395,30 @@ void DrawUI() {
drawTemp(temp, 5);
break;
case DCINDISP: {
uint16_t voltage = readDCVoltage(); //get X10 voltage
OLED_DrawString("IN", 2);
OLED_DrawChar((voltage / 100) % 10, 2);
voltage -= (voltage / 100) * 100;
OLED_DrawChar((voltage / 10) % 10, 3);
voltage -= (voltage / 10) * 10;
OLED_DrawChar('.', 4);
OLED_DrawChar(voltage % 10, 5);
OLED_DrawChar('V', 6);
OLED_DrawChar(' ', 7);
uint16_t voltage = readDCVoltage(systemSettings.voltageDiv); //get X10 voltage

if (CalStatus == 0 || ((millis() % 1000) > 500)) {
OLED_DrawString("IN", 2);
OLED_DrawChar((voltage / 100) % 10, 2);
voltage -= (voltage / 100) * 100;
OLED_DrawChar((voltage / 10) % 10, 3);
voltage -= (voltage / 10) * 10;
OLED_DrawChar('.', 4);
OLED_DrawChar(voltage % 10, 5);
OLED_DrawChar('V', 6);
OLED_DrawChar(' ', 7);
} else {
OLED_DrawString("IN ", 8);
}
}
break;
case TEMPCAL: {

if (tempCalStatus == 0) {
if (CalStatus == 0) {
OLED_DrawString("CAL TEMP", 8);
} else if (tempCalStatus == 1) {
} else if (CalStatus == 1) {
OLED_DrawString("CAL OK ", 8);
} else if (tempCalStatus == 2) {
} else if (CalStatus == 2) {
OLED_DrawString("CAL FAIL", 8);
}
}
Expand Down
2 changes: 1 addition & 1 deletion workspace/ts100/src/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ void resetSettings() {
systemSettings.flipDisplay=0; //Default to right handed mode
systemSettings.sensitivity=0x00; //Default high sensitivity
systemSettings.tempCalibration=239; //Default to their calibration value

systemSettings.voltageDiv=144; //Default divider from schematic
}

0 comments on commit 1522c41

Please sign in to comment.