Skip to content

Commit 2c8da81

Browse files
committedOct 24, 2022
add temperature label
1 parent e3cd90f commit 2c8da81

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed
 

‎Connect/connect.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def __init__(self):
3636
print('device not found!')
3737
serial.Serial.close()
3838
exit()
39+
else:
40+
time.sleep(.1)
3941
rxData = ''
4042
try:
4143
self.serialConn = serial.Serial(self.bldcPort, 115200, timeout=0, parity=serial.PARITY_EVEN, rtscts=1)
@@ -103,7 +105,10 @@ def readData(self):
103105

104106
def __del__(self):
105107
print("connection destruction")
106-
self.serialConn.close()
108+
try:
109+
self.serialConn.close()
110+
except AttributeError:
111+
print("port closed")
107112

108113
class Gui:
109114
def __init__(self):

‎Connect/web/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ <h1 id="myTitle">BLDC Driver connect</h1>
3737
.posFont {
3838
font: 8px Verdana;
3939
}
40+
.tempFont {
41+
font: 4px Verdana;
42+
fill: #2e2c2c;
43+
}
4044
</style>
4145
<circle cx="50%" cy="50%" r="49%" stroke="#909090" stroke-width="1" fill="#505050"/>
42-
<text id="bldcPosition" x="52%" y="65%" class="posFont">0</text>
4346
<line id="motorPosition" x1="50%" y1="50%" x2="50%" y2="1px" style="stroke:rgb(128, 128, 128); stroke-width:1";/>
4447
<line id="motorExpectedPosition" x1="50%" y1="50%" x2="50%" y2="1px" style="stroke:rgb(184, 58, 9); stroke-width:1";/>
48+
<text id="bldcPosition" x="52%" y="65%" class="posFont">0</text>
49+
<text id="temperature" x="20%" y="30%" class="tempFont">0</text>
4550
</svg>
4651

4752
<div id="modeSelect">

‎Connect/web/js/app.js

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ function call_Back(output){
5151

5252
actualPower = Math.round(partsArray[7]);
5353
document.getElementById("actualPower").style.transform = "scale(" + actualPower + "%, 100%)";
54+
55+
console.log(partsArray);
56+
document.getElementById("temperature").innerHTML = partsArray[8] + "°C";
57+
if(partsArray[8] > 30){
58+
document.getElementById("temperature").style.fill = "#992626";
59+
} else {
60+
document.getElementById("temperature").style.fill = "#162818";
61+
}
5462
}
5563

5664

‎Core/Src/main.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ uint8_t TXFlag = 0;
7575
PID_TypeDef PowerPID;
7676
double PowerPIDSetpoint = 0.0;
7777
//PID_TypeDef AccelerationPID;
78+
79+
7880
//OTHERS
79-
uint16_t testi = 0;
8081
extern uint8_t initPhase;
8182
uint16_t test_array[4095];
8283

@@ -85,6 +86,8 @@ extern uint16_t expectedDegree;
8586
extern uint16_t expectedPower;
8687

8788
extern uint8_t mode; //driver program 0-1pos / 1-switch
89+
90+
uint16_t temperature = 0;
8891
/* USER CODE END PV */
8992

9093
/* Private function prototypes -----------------------------------------------*/
@@ -282,9 +285,10 @@ int main(void)
282285
/* USER CODE BEGIN WHILE */
283286
while (1) {
284287
MessageLength = sprintf((char*) DataToSend,
285-
"#%i,%i,%lu,%lu,%lu,%i,%.0f,%.0f/\n\r", mode, bldcEncoder.calculatedAngle,
288+
"#%i,%i,%lu,%lu,%lu,%i,%.0f,%.0f,%i/\n\r", mode, bldcEncoder.calculatedAngle,
286289
bldcMotor.pwmU, bldcMotor.pwmV, bldcMotor.pwmW,
287-
bldcMotor.expectedPosition, bldcMotor.expectedPower, bldcMotor.actualPower);
290+
bldcMotor.expectedPosition, bldcMotor.expectedPower, bldcMotor.actualPower,
291+
temperature);
288292
CDC_Transmit_FS(DataToSend, MessageLength);
289293

290294
if(bldcMotor.expectedPower != (float)expectedPower){
@@ -295,14 +299,18 @@ int main(void)
295299
}
296300
PID_SetOutputLimits(&PowerPID, 12, bldcMotor.expectedPower);
297301
}
298-
HAL_Delay(50);
302+
299303
if(mode == 0){
300304
float newPos = expectedDegree * 1.1406;
301305
bldcMotor.expectedPosition = (uint16_t)newPos;
302306
} else if (mode == 1){
303307
uint16_t switchPos = expectedDegree * 1.1406;
304308
bldcHapticSwitch(0, switchPos);
305309
}
310+
311+
temperature = (0.04 * (uint16_t)adc_raw_table[4]) - 56;;
312+
313+
HAL_Delay(50);
306314
/* USER CODE END WHILE */
307315

308316
/* USER CODE BEGIN 3 */

‎Core/Src/stm32f1xx_hal_msp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
136136
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
137137
hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
138138
hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
139-
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
140-
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
139+
hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
140+
hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
141141
hdma_adc1.Init.Mode = DMA_CIRCULAR;
142142
hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
143143
if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)

‎STM32F103_BLDC_Driver.ioc

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ ADC1.SamplingTime-4\#ChannelRegularConversion=ADC_SAMPLETIME_41CYCLES_5
2121
ADC1.master=1
2222
Dma.ADC1.3.Direction=DMA_PERIPH_TO_MEMORY
2323
Dma.ADC1.3.Instance=DMA1_Channel1
24-
Dma.ADC1.3.MemDataAlignment=DMA_MDATAALIGN_HALFWORD
24+
Dma.ADC1.3.MemDataAlignment=DMA_MDATAALIGN_WORD
2525
Dma.ADC1.3.MemInc=DMA_MINC_ENABLE
2626
Dma.ADC1.3.Mode=DMA_CIRCULAR
27-
Dma.ADC1.3.PeriphDataAlignment=DMA_PDATAALIGN_HALFWORD
27+
Dma.ADC1.3.PeriphDataAlignment=DMA_PDATAALIGN_WORD
2828
Dma.ADC1.3.PeriphInc=DMA_PINC_DISABLE
2929
Dma.ADC1.3.Priority=DMA_PRIORITY_LOW
3030
Dma.ADC1.3.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority

0 commit comments

Comments
 (0)
Please sign in to comment.