Compare commits

...

19 Commits
v2.06 ... v2.07

Author SHA1 Message Date
Ben V. Brown
86d60da935 Merge pull request #542 from Ralim/drop-inline
Drop inline on QC as not required
2019-12-31 23:23:56 +11:00
Ben V. Brown
e1a4418599 Update hardware.cpp 2019-12-31 23:23:20 +11:00
Ben V. Brown
0402b7bd2f Merge pull request #541 from Ralim/v2.07
Update make_translation.py
2019-12-31 23:10:28 +11:00
Ben V. Brown
644a3e4349 Update make_translation.py 2019-12-31 23:09:51 +11:00
Ben V. Brown
76a3ec00d0 Merge pull request #540 from Ralim/Fix-dropped-zeros
Fix dropped zeros
2019-12-31 23:06:31 +11:00
Ben V. Brown
a4ccb3ae96 Merge pull request #539 from Ralim/lets-fix-qc
Fixing QC 12V
2019-12-31 23:04:39 +11:00
Ben V. Brown
0d713ae257 Dont suppress zeros 2019-12-31 22:59:04 +11:00
Ben V. Brown
26bf31ae64 Make zero suppression optional 2019-12-31 22:58:52 +11:00
Ben V. Brown
0672d637a4 Update hardware.cpp 2019-12-31 22:54:43 +11:00
Ben V. Brown
6b7567257b Update hardware.cpp 2019-12-31 22:46:23 +11:00
Ben V. Brown
554001a2d4 Cleanup QC 2019-12-31 22:45:00 +11:00
Ben V. Brown
d98b1aa76d Regin the rested voltage to be 9 or 12 2019-12-31 22:44:47 +11:00
Ben V. Brown
7683ad155d Merge pull request #538 from Ralim/fix-temp-symbol
Fix the temp symbol to be used in soldering mode
2019-12-29 16:46:40 +11:00
Ben V. Brown
832940353b Draw nicer temp sybols if current font allows 2019-12-29 16:35:41 +11:00
Ben V. Brown
e82c75258a Add readback for the current font 2019-12-29 16:35:29 +11:00
Ben V. Brown
3040bc5fa4 Merge pull request #523 from thomasgi1/powerPulses
generate power pulses also in soldering and sleep mode
2019-12-29 16:10:19 +11:00
Thomas Gimpel
00bf5357c1 Merge branch 'master' into powerPulses 2019-12-28 14:59:36 +01:00
Thomas Gimpel
902fa7f75b Merge branch 'master' into powerPulses 2019-12-24 10:10:24 +01:00
Thomas Gimpel
3f45e6a5af generate power pulses also in soldering and sleep mode 2019-11-24 11:50:51 +01:00
7 changed files with 257 additions and 227 deletions

View File

@@ -94,7 +94,7 @@ def getConstants():
consants.append(('SymbolVolts', 'V'))
consants.append(('SymbolDC', 'DC'))
consants.append(('SymbolCellCount', 'S'))
consants.append(('SymbolVersionNumber', 'V2.06'))
consants.append(('SymbolVersionNumber', 'V2.07'))
return consants

View File

@@ -1,112 +1,113 @@
/*
* OLED.hpp
*
* Created on: 20Jan.,2017
* Author: Ben V. Brown <Ralim>
* Designed for the SSD1307
* Cleared for release for TS100 2017/08/20
*/
#ifndef OLED_HPP_
#define OLED_HPP_
#include <hardware.h>
#include "stm32f1xx_hal.h"
#include <stdbool.h>
#include <string.h>
#include "FRToSI2C.hpp"
#include "Font.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#ifdef __cplusplus
}
#endif
#define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96
#define FRAMEBUFFER_START 17
class OLED {
public:
enum DisplayState : bool {
OFF = false,
ON = true
};
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
// Draw the buffer out to the LCD using the DMA Channel
static void refresh() {
FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer,
FRAMEBUFFER_START + (OLED_WIDTH * 2));
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
//or we need to goto double buffering
}
static void setDisplayState(DisplayState state) {
displayState = state;
screenBuffer[1] = (state == ON) ? 0xAF : 0xAE;
}
static void setRotation(bool leftHanded); // Set the rotation for the screen
// Get the current rotation of the LCD
static bool getRotation() {
return inLeftHandedMode;
}
static int16_t getCursorX() {
return cursor_x;
}
static void print(const char* string);// Draw a string to the current location, with current font
// Set the cursor location by pixels
static void setCursor(int16_t x, int16_t y) {
cursor_x = x;
cursor_y = y;
}
//Set cursor location by chars in current font
static void setCharCursor(int16_t x, int16_t y) {
cursor_x = x * fontWidth;
cursor_y = y * fontHeight;
}
static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
drawArea(x, 0, width, 16, buffer);
}
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
static void printNumber(uint16_t number, uint8_t places);
// Draws a number at the current cursor location
// Clears the buffer
static void clearScreen() {
memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2);
}
// Draws the battery level symbol
static void drawBattery(uint8_t state) {
drawSymbol(3 + (state > 10 ? 10 : state));
}
// Draws a checkbox
static void drawCheckbox(bool state) {
drawSymbol((state) ? 16 : 17);
}
static void debugNumber(int32_t val);
static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
bool clear);
static void drawHeatSymbol(uint8_t state);
private:
static void drawChar(char c); // Draw a character to a specific location
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
static uint8_t* secondStripPtr; //Pointers to the strips
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
static DisplayState displayState;
static uint8_t fontWidth, fontHeight;
static int16_t cursor_x, cursor_y;
static uint8_t displayOffset;
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
};
#endif /* OLED_HPP_ */
/*
* OLED.hpp
*
* Created on: 20Jan.,2017
* Author: Ben V. Brown <Ralim>
* Designed for the SSD1307
* Cleared for release for TS100 2017/08/20
*/
#ifndef OLED_HPP_
#define OLED_HPP_
#include <hardware.h>
#include "stm32f1xx_hal.h"
#include <stdbool.h>
#include <string.h>
#include "FRToSI2C.hpp"
#include "Font.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#ifdef __cplusplus
}
#endif
#define DEVICEADDR_OLED (0x3c<<1)
#define OLED_WIDTH 96
#define FRAMEBUFFER_START 17
class OLED {
public:
enum DisplayState : bool {
OFF = false,
ON = true
};
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
// Draw the buffer out to the LCD using the DMA Channel
static void refresh() {
FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer,
FRAMEBUFFER_START + (OLED_WIDTH * 2));
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
//or we need to goto double buffering
}
static void setDisplayState(DisplayState state) {
displayState = state;
screenBuffer[1] = (state == ON) ? 0xAF : 0xAE;
}
static void setRotation(bool leftHanded); // Set the rotation for the screen
// Get the current rotation of the LCD
static bool getRotation() {
return inLeftHandedMode;
}
static int16_t getCursorX() {
return cursor_x;
}
static void print(const char* string);// Draw a string to the current location, with current font
// Set the cursor location by pixels
static void setCursor(int16_t x, int16_t y) {
cursor_x = x;
cursor_y = y;
}
//Set cursor location by chars in current font
static void setCharCursor(int16_t x, int16_t y) {
cursor_x = x * fontWidth;
cursor_y = y * fontHeight;
}
static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
static uint8_t getFont();
static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
drawArea(x, 0, width, 16, buffer);
}
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
static void printNumber(uint16_t number, uint8_t places,bool noLeaderZeros=true);
// Draws a number at the current cursor location
// Clears the buffer
static void clearScreen() {
memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2);
}
// Draws the battery level symbol
static void drawBattery(uint8_t state) {
drawSymbol(3 + (state > 10 ? 10 : state));
}
// Draws a checkbox
static void drawCheckbox(bool state) {
drawSymbol((state) ? 16 : 17);
}
static void debugNumber(int32_t val);
static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
bool clear);
static void drawHeatSymbol(uint8_t state);
private:
static void drawChar(char c); // Draw a character to a specific location
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
static uint8_t* secondStripPtr; //Pointers to the strips
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
static DisplayState displayState;
static uint8_t fontWidth, fontHeight;
static int16_t cursor_x, cursor_y;
static uint8_t displayOffset;
static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer
};
#endif /* OLED_HPP_ */

View File

@@ -63,10 +63,19 @@ void gui_drawTipTemp(bool symbol) {
OLED::printNumber(Temp, 3); // Draw the tip temp out finally
if (symbol) {
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
else
OLED::print(SymbolDegC);
if (OLED::getFont() == 0) {
//Big font, can draw nice symbols
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
OLED::drawSymbol(1);
} else {
//Otherwise fall back to chars
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
else
OLED::print(SymbolDegC);
}
}
}
ButtonState getButtonState() {

View File

@@ -155,6 +155,14 @@ void OLED::setFont(uint8_t fontNumber) {
fontWidth = 12;
}
}
uint8_t OLED::getFont() {
if (currentFont == USER_FONT_6x8)
return 1;
else if (currentFont == ExtraFontChars)
return 2;
else
return 0;
}
inline void stripLeaderZeros(char *buffer) {
//Removing the leading zero's by swapping them to SymbolSpace
// Stop 1 short so that we dont blank entire number if its zero
@@ -167,7 +175,7 @@ inline void stripLeaderZeros(char *buffer) {
}
}
// maximum places is 5
void OLED::printNumber(uint16_t number, uint8_t places) {
void OLED::printNumber(uint16_t number, uint8_t places, bool noLeaderZeros) {
char buffer[7] = { 0 };
if (places >= 5) {
@@ -195,7 +203,8 @@ void OLED::printNumber(uint16_t number, uint8_t places) {
}
buffer[0] = 2 + number % 10;
stripLeaderZeros(buffer);
if (noLeaderZeros)
stripLeaderZeros(buffer);
print(buffer);
}

View File

@@ -96,14 +96,14 @@ static void settings_enterAdvancedMenu(void);
*
*/
const menuitem rootSettingsMenu[] {
/*
* Power Source
* Soldering Menu
* Power Saving Menu
* UI Menu
* Advanced Menu
* Exit
*/
/*
* Power Source
* Soldering Menu
* Power Saving Menu
* UI Menu
* Advanced Menu
* Exit
*/
#ifdef MODEL_TS100
{ (const char*) SettingsDescriptions[0], { settings_setInputVRange }, {
settings_displayInputVRange } }, /*Voltage input*/
@@ -418,7 +418,7 @@ static void settings_setSensitivity(void) {
static void settings_displaySensitivity(void) {
printShortDescription(4, 7);
OLED::printNumber(systemSettings.sensitivity, 1);
OLED::printNumber(systemSettings.sensitivity, 1, false);
}
static void settings_setAdvancedSolderingScreens(void) {
@@ -613,7 +613,7 @@ static void settings_setCalibrateVIN(void) {
2);
OLED::print(SymbolDot);
OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv, 0) % 10,
1);
1, false);
OLED::print(SymbolVolts);
ButtonState buttons = getButtonState();

View File

@@ -49,7 +49,7 @@ uint16_t getTipInstantTemperature() {
}
//2 second filter (ADC is PID_TIM_HZ Hz)
history<uint16_t, PID_TIM_HZ > rawTempFilter = { { 0 }, 0, 0 };
history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
uint16_t getTipRawTemp(uint8_t refresh) {
if (refresh) {
@@ -66,7 +66,12 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
// Therefore we can divide down from there
// Multiplying ADC max by 4 for additional calibration options,
// ideal term is 467
#ifdef MODEL_TS100
#define BATTFILTERDEPTH 32
#else
#define BATTFILTERDEPTH 8
#endif
static uint8_t preFillneeded = 10;
static uint32_t samples[BATTFILTERDEPTH];
static uint8_t index = 0;
@@ -88,6 +93,51 @@ uint16_t getInputVoltageX10(uint16_t divisor, uint8_t sample) {
return sum * 4 / divisor;
}
#ifdef MODEL_TS80
void DPlusZero_Six() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
}
void DNegZero_Six() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
}
void DPlusThree_Three() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); // pull up D+
}
void DNegThree_Three() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
}
void QC_Seek9V() {
DNegZero_Six();
DPlusThree_Three();
}
void QC_Seek12V() {
DNegZero_Six();
DPlusZero_Six();
}
void QC_Seek20V() {
DNegThree_Three();
DPlusThree_Three();
}
void QC_SeekContMode() {
DNegThree_Three();
DPlusZero_Six();
}
void QC_SeekContPlus() {
QC_SeekContMode();
vTaskDelay(3);
QC_Seek20V();
vTaskDelay(1);
QC_SeekContMode();
}
void QC_SeekContNeg() {
QC_SeekContMode();
vTaskDelay(3);
QC_Seek12V();
vTaskDelay(1);
QC_SeekContMode();
}
uint8_t QCMode = 0;
uint8_t QCTries = 0;
void seekQC(int16_t Vx10, uint16_t divisor) {
@@ -98,142 +148,108 @@ void seekQC(int16_t Vx10, uint16_t divisor) {
if (Vx10 < 45)
return;
if (xTaskGetTickCount() < 100)
return;
if (Vx10 > 130)
Vx10 = 130; //Cap max value at 13V
// Seek the QC to the Voltage given if this adapter supports continuous mode
// try and step towards the wanted value
// 1. Measure current voltage
int16_t vStart = getInputVoltageX10(divisor, 0);
int16_t vStart = getInputVoltageX10(divisor, 1);
int difference = Vx10 - vStart;
// 2. calculate ideal steps (0.2V changes)
int steps = difference / 2;
if (QCMode == 3) {
if (steps > -2 && steps < 2)
return; // dont bother with small steps
while (steps < 0) {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); //D+0.6
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); //D-3.3V
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); // D-3.3Vs
QC_SeekContNeg();
vTaskDelay(3);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); //-0.6V
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
HAL_Delay(1);
steps++;
}
while (steps > 0) {
// step once up
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
QC_SeekContPlus();
vTaskDelay(3);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_Delay(1);
steps--;
}
vTaskDelay(10);
}
#ifdef ENABLE_QC2
// Re-measure
/* Disabled due to nothing to test and code space of around 1k*/
#ifdef QC2_ROUND_DOWN
steps = vStart - getInputVoltageX10(195);
if (steps < 0) steps = -steps;
if (steps > (difference / 2)) {
steps = vStart - getInputVoltageX10(divisor, 1);
if (steps < 0)
steps = -steps;
if (steps > 4) {
// No continuous mode, so QC2
QCMode = 2;
// Goto nearest
if (Vx10 > 10.5) {
if (Vx10 > 110) {
// request 12V
// D- = 0.6V, D+ = 0.6V
// Clamp PB3
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull down D+
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
QC_Seek12V();
} else {
// request 9V
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
QC_Seek9V();
}
}
#endif
}
// Must be called after FreeRToS Starts
void startQC(uint16_t divisor) {
// Pre check that the input could be >5V already, and if so, dont both
// negotiating as someone is feeding in hv
uint16_t vin = getInputVoltageX10(divisor, 1);
if (vin > 100) {
QCMode = 1; // ALready at ~12V
QCMode = 1; // Already at 12V, user has probably over-ridden this
return;
}
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
//Turn off output mode on pins that we can
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// Tries to negotiate QC for 9V
// This is a multiple step process.
// 1. Set around 0.6V on D+ for 1.25 Seconds or so
// 2. After this It should un-short D+->D- and instead add a 20k pulldown on
// D-
// 3. Now set D+ to 3.3V and D- to 0.6V to request 9V
// OR both at 0.6V for 12V request (if the adapter can do it).
// If 12V is implimented then should fallback to 9V after validation
// Step 1. We want to pull D+ to 0.6V
// Pull PB3 donwn to ground
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
DPlusZero_Six();
// Delay 1.25 seconds
uint8_t enteredQC = 0;
for (uint16_t i = 0; i < 130 && enteredQC == 0; i++) {
// HAL_Delay(10);
vTaskDelay(1);
}
vTaskDelay(125);
// Check if D- is low to spot a QC charger
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET)
enteredQC = 1;
if (enteredQC) {
// We have a QC capable charger
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
QC_Seek9V();
GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_8;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
QC_Seek9V();
// Wait for frontend ADC to stabilise
QCMode = 4;
for (uint8_t i = 0; i < 10; i++) {
if (getInputVoltageX10(divisor, 1) > 80) {
// yay we have at least QC2.0 or QC3.0
QCMode = 3; // We have at least QC2, pray for 3
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
return;
}
vTaskDelay(10); // 100mS
@@ -245,7 +261,6 @@ void startQC(uint16_t divisor) {
} else {
// no QC
QCMode = 0;
}
if (QCTries > 10)
QCMode = 0;

View File

@@ -16,7 +16,7 @@ uint8_t PCBVersion = 0;
// File local variables
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
uint32_t lastMovementTime = 0;
int16_t idealQCVoltage = 0;
bool settingsWereReset = false;
// FreeRTOS variables
@@ -41,6 +41,10 @@ void startPIDTask(void const *argument);
void startMOVTask(void const *argument);
// End FreeRTOS
static const int maxPowerIdleTicks = 1000;
static const int powerPulseTicks = 50;
static const int x10PowerPulseWatts = 3;
// Main sets up the hardware then hands over to the FreeRTOS kernel
int main(void) {
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
@@ -108,9 +112,6 @@ void startPIDTask(void const *argument __unused) {
* control PWM.
*/
setTipX10Watts(0); // disable the output driver if the output is set to be off
#ifdef MODEL_TS80
idealQCVoltage = calculateMaxVoltage(systemSettings.cutoutSetting);
#endif
#ifdef MODEL_TS80
//Set power management code to the tip resistance in ohms * 10
@@ -127,6 +128,7 @@ void startPIDTask(void const *argument __unused) {
if (ulTaskNotifyTake(pdTRUE, 2000)) {
// This is a call to block this thread until the ADC does its samples
int32_t x10WattsOut = 0;
// Do the reading here to keep the temp calculations churning along
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
@@ -148,7 +150,6 @@ void startPIDTask(void const *argument __unused) {
tempError.update(tError);
// Now for the PID!
int32_t x10WattsOut = 0;
// P term - total power needed to hit target temp next cycle.
// thermal mass = 1690 milliJ/*C for my tip.
@@ -175,25 +176,20 @@ void startPIDTask(void const *argument __unused) {
// basically: temp - lastTemp
// Unfortunately, our temp signal is too noisy to really help.
setTipX10Watts(x10WattsOut);
} else {
#ifdef MODEL_TS80
//If its a TS80, we want to have the option of using an occasional pulse to keep the power bank on
// This is purely guesswork :'( as everyone implements stuff differently
if (xTaskGetTickCount() - lastPowerPulse < 10) {
// for the first 100mS turn on for a bit
setTipX10Watts(25); // typically its around 5W to hold the current temp, so this wont raise temp much
} else
setTipX10Watts(0);
//Then wait until the next 0.5 seconds
if (xTaskGetTickCount() - lastPowerPulse > 50) {
lastPowerPulse = xTaskGetTickCount();
}
#else
setTipX10Watts(0);
#endif
}
#ifdef MODEL_TS80
//If its a TS80, we want to have the option of using an occasional pulse to keep the power bank on
if (((xTaskGetTickCount() - lastPowerPulse) > maxPowerIdleTicks)
&& (x10WattsOut < x10PowerPulseWatts)) {
x10WattsOut = x10PowerPulseWatts;
}
if (((xTaskGetTickCount() - lastPowerPulse)
> (maxPowerIdleTicks + powerPulseTicks))
&& (x10WattsOut >= x10PowerPulseWatts)) {
lastPowerPulse = xTaskGetTickCount();
}
#endif
setTipX10Watts(x10WattsOut);
HAL_IWDG_Refresh(&hiwdg);
} else {
@@ -214,7 +210,8 @@ void startMOVTask(void const *argument __unused) {
while (pidTaskNotification == 0)
osDelay(30); // To ensure we return after idealQCVoltage/tip resistance
seekQC(idealQCVoltage, systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // this will move the QC output to the preferred voltage to start with
#else
osDelay(250); // wait for accelerometer to stabilize
@@ -277,9 +274,8 @@ void startMOVTask(void const *argument __unused) {
osDelay(100); // Slow down update rate
#ifdef MODEL_TS80
// if (currentlyActiveTemperatureTarget) {
// seekQC(idealQCVoltage, systemSettings.voltageDiv); // Run the QC seek again to try and compensate for cable V drop
// }
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // Run the QC seek again if we have drifted too much
#endif
}
}