Skip to content

Commit

Permalink
extended gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Jana-Marie committed Mar 3, 2020
1 parent a0c2658 commit 66c50ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/*
firmware/build/*
firmware/Drivers/**
.mxproject
*.jdebug.user
*.stl
Expand Down
38 changes: 30 additions & 8 deletions firmware/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include "main.h"
#include "font.h"

#define ENABLESERIAL
// Enable serial printing via CDC, quite buggy
//#define ENABLESERIAL
// Enable Current display, shows up after a few millisecconds instead of temp-target
#define DISPLAYCURRENT

#define FILT(a, b, c) ((a) * (c) + (b) * ((1.0f) - (c)))
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
Expand Down Expand Up @@ -71,6 +74,9 @@ struct status_t{
float tref;
uint8_t writeFlash;
uint8_t button[2];
#ifdef DISPLAYCURRENT
uint8_t timeout;
#endif
}s = {.writeFlash = 0};

struct reg_t{
Expand Down Expand Up @@ -141,6 +147,9 @@ int main(void)
USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
HAL_TIM_Base_Start_IT(&htim3);
USBD_Start(&USBD_Device);
#endif
#ifdef DISPLAYCURRENT
s.timeout = 20;
#endif
}

Expand All @@ -161,18 +170,18 @@ int main(void)
if(s.button[0] == 1){
r.target -= 5;
s.writeFlash = 1;
HAL_Delay(50);
HAL_Delay(40);
}

if(s.button[1] == 1){
r.target += 5;
s.writeFlash = 1;
HAL_Delay(50);
HAL_Delay(40);
}

r.target = CLAMP(r.target, 20, 400);

if(s.writeFlash = 1){
if(s.writeFlash == 1){
HAL_FLASH_Unlock();
FLASH->CR |= FLASH_CR_PER;
FLASH->AR = 0x0800e400;
Expand All @@ -185,6 +194,9 @@ int main(void)
HAL_FLASH_Lock();
s.writeFlash = 0;
}
#ifdef DISPLAYCURRENT
s.timeout = 12;
#endif
}

#ifdef ENABLESERIAL
Expand All @@ -196,14 +208,23 @@ int main(void)
char str1[10] = " ";
char str2[10] = " ";
char str3[10] = " ";
sprintf(str1, "%d C", (uint16_t)r.target);
char str4[10] = " ";
sprintf(str1, "%d C ", (uint16_t)r.target);
sprintf(str2, "%d.%d C", (uint16_t)s.ttipavg,(uint16_t)((s.ttipavg-(uint16_t)s.ttipavg)*10.0f));
sprintf(str3, "%d.%d V", (uint16_t)s.uin,(uint16_t)((s.uin-(uint16_t)s.uin)*10.0f));
sprintf(str4, "%d.%d A", (uint16_t)s.iin,(uint16_t)((s.iin-(uint16_t)s.iin)*10.0f));

clear_screen();
draw_string(str1, 10, 1 ,1);
draw_string(str2, 10, 9 ,1);
draw_string(str3, 60, 1 ,1);
#ifdef DISPLAYCURRENT
if(s.timeout == 0){
draw_string(str4, 10, 1 ,1);
} else {
s.timeout--;
}
#endif

for(uint16_t i = 0; i <= CLAMP(r.error*3.0f,0,30); i++){
draw_v_line(60+i, 8, 8, 1);
Expand All @@ -219,7 +240,7 @@ void reg(void) {
s.tref = ((((float)ADC_raw[3]/4095.0)*3.3)-0.5)/0.01;
s.ttip = ((ADC_raw[1]-tipcal.offset)*tipcal.coefficient)/1000+s.tref;
s.uin = ((ADC_raw[2]/4095.0)*3.3)*6.6;
s.iin = ((ADC_raw[0]/4095.0)*3.3);
s.iin = FILT(s.iin, ((ADC_raw[0]/4095.0)*3.3*1.659)/(0.01*(2370/33)), TTIP_AVG_FILTER);

s.ttipavg = FILT(s.ttipavg, s.ttip, TTIP_AVG_FILTER);

Expand All @@ -244,6 +265,7 @@ void reg(void) {
r.duty = CLAMP(r.duty, MIN_DUTY, MAX_DUTY); // Clamp to duty cycle

__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, r.duty);
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_4, r.duty+3);
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) //send USB cdc data
Expand Down Expand Up @@ -422,7 +444,7 @@ static void MX_ADC_Init(void)

sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_13CYCLES_5;
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);

sConfig.Channel = ADC_CHANNEL_1;
Expand Down Expand Up @@ -548,7 +570,7 @@ static void MX_TIM1_Init(void)
HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1);

sConfigOC.OCMode = TIM_OCMODE_PWM2;
sConfigOC.Pulse = 4090;
sConfigOC.Pulse = 10;
HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4);

sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
Expand Down

0 comments on commit 66c50ed

Please sign in to comment.