Skip to content

Commit c3394f8

Browse files
committed
Created seperate pair of pressure files
1 parent 896982b commit c3394f8

File tree

7 files changed

+86
-41
lines changed

7 files changed

+86
-41
lines changed

Common/Inc/config.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,39 @@
2020

2121
// BEGIN KELLY DEFS
2222
// FRAME 1
23-
const DataSegment DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_1, 1, 1};
24-
const DataSegment MOTOR_SPEED_K = {MOTOR_CONTROLLER_1, 2, 3};
25-
const DataSegment MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_1, 4, 4};
23+
const Data_Segment_t DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_1, 1, 1};
24+
const Data_Segment_t MOTOR_SPEED_K = {MOTOR_CONTROLLER_1, 2, 3};
25+
const Data_Segment_t MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_1, 4, 4};
2626
// FRAME 2
27-
const DataSegment BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_2, 1, 2};
28-
const DataSegment BATTERY_CURRENT_K = {MOTOR_CONTROLLER_2, 3, 4};
29-
const DataSegment MOTOR_TEMP_K = {MOTOR_CONTROLLER_2, 5, 6};
30-
const DataSegment MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_2, 7, 8};
27+
const Data_Segment_t BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_2, 1, 2};
28+
const Data_Segment_t BATTERY_CURRENT_K = {MOTOR_CONTROLLER_2, 3, 4};
29+
const Data_Segment_t MOTOR_TEMP_K = {MOTOR_CONTROLLER_2, 5, 6};
30+
const Data_Segment_t MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_2, 7, 8};
3131
// END KELLY DEFS
3232

3333
// BEGIN MOTOR CONTROLLER DEFS
34-
const DataSegment BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2};
35-
const DataSegment BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4};
36-
const DataSegment MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6};
37-
const DataSegment MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7};
38-
const DataSegment DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8};
39-
const DataSegment MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8};
34+
const Data_Segment_t BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2};
35+
const Data_Segment_t BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4};
36+
const Data_Segment_t MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6};
37+
const Data_Segment_t MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7};
38+
const Data_Segment_t DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8};
39+
const Data_Segment_t MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8};
4040
// END MOTOR CONTROLLER DEFS
4141

4242
// BEGIN BMS DEFS
43-
const DataSegment MUX1_TEMP = {BMS_BOARD, 1, 1};
44-
const DataSegment MUX2_TEMP = {BMS_BOARD, 2, 2};
45-
const DataSegment MUX3_TEMP = {BMS_BOARD, 3, 3};
46-
const DataSegment MUX4_TEMP = {BMS_BOARD, 4, 4};
47-
const DataSegment MUX5_TEMP = {BMS_BOARD, 5, 5};
48-
const DataSegment MUX6_TEMP = {BMS_BOARD, 6, 6};
49-
const DataSegment BMS_ERROR_CODE = {BMS_BOARD, 7, 7};
43+
const Data_Segment_t MUX1_TEMP = {BMS_BOARD, 1, 1};
44+
const Data_Segment_t MUX2_TEMP = {BMS_BOARD, 2, 2};
45+
const Data_Segment_t MUX3_TEMP = {BMS_BOARD, 3, 3};
46+
const Data_Segment_t MUX4_TEMP = {BMS_BOARD, 4, 4};
47+
const Data_Segment_t MUX5_TEMP = {BMS_BOARD, 5, 5};
48+
const Data_Segment_t MUX6_TEMP = {BMS_BOARD, 6, 6};
49+
const Data_Segment_t BMS_ERROR_CODE = {BMS_BOARD, 7, 7};
5050
// END BMS DEFS
5151

5252
// BEGIN SENSORS BOARD DEFS
53-
const DataSegment PRESSURE_SENSOR_DATA = {SENSOR_BOARD, 1, 1};
54-
const DataSegment IMU_DATA = {SENSOR_BOARD, 2, 3};
55-
const DataSegment LIM_ONE_TEMP = {SENSOR_BOARD, 4, 5};
56-
const DataSegment LIM_TWO_TEMP = {SENSOR_BOARD, 6, 7};
57-
const DataSegment SENSORS_ERROR_CODE = {SENSOR_BOARD, 8, 8};
53+
const Data_Segment_t PRESSURE_SENSOR_DATA = {SENSOR_BOARD, 1, 1};
54+
const Data_Segment_t IMU_DATA = {SENSOR_BOARD, 2, 3};
55+
const Data_Segment_t LIM_ONE_TEMP = {SENSOR_BOARD, 4, 5};
56+
const Data_Segment_t LIM_TWO_TEMP = {SENSOR_BOARD, 6, 7};
57+
const Data_Segment_t SENSORS_ERROR_CODE = {SENSOR_BOARD, 8, 8};
5858
// END SENSORS BOARD DEFS

Common/Src/can_driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "can_driver.h"
22

33
static uint32_t tx_mailbox;
4+
#define WARN_OFFSET 0xFF
45

56
CAN_Frame_t CAN_frame_init(CAN_HandleTypeDef* handler, uint32_t id) {
67
// default conditions

Sensors/.cproject

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</toolChain>
7676
</folderInfo>
7777
<sourceEntries>
78+
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Common"/>
7879
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
7980
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
8081
</sourceEntries>
@@ -174,5 +175,12 @@
174175
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
175176
</scannerConfigBuildInfo>
176177
</storageModule>
177-
<storageModule moduleId="refreshScope"/>
178+
<storageModule moduleId="refreshScope" versionNumber="2">
179+
<configuration configurationName="Debug">
180+
<resource resourceType="PROJECT" workspacePath="/Sensors"/>
181+
</configuration>
182+
<configuration configurationName="Release">
183+
<resource resourceType="PROJECT" workspacePath="/Sensors"/>
184+
</configuration>
185+
</storageModule>
178186
</cproject>

Sensors/.project

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@
2929
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
3030
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
3131
</natures>
32+
<linkedResources>
33+
<link>
34+
<name>Common</name>
35+
<type>2</type>
36+
<location>C:/Users/mahir/Desktop/Waterloop/G6-STM32/Common</location>
37+
</link>
38+
</linkedResources>
3239
</projectDescription>

Sensors/Core/Inc/pressure.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* pressure.h
3+
*
4+
* Created on: Apr 25, 2024
5+
* Author: mahesh, mahir
6+
*/
7+
8+
#ifndef INC_PRESSURE_H_
9+
#define INC_PRESSURE_H_
10+
11+
#include <stdint.h>
12+
#define MAX_ADC_VALUE 4095
13+
14+
uint8_t poll_pressure_sensor(void);
15+
16+
#endif /* INC_PRESSURE_H_ */

Sensors/Core/Src/main.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/* USER CODE BEGIN Includes */
2727
#include "can_driver.h"
2828
#include "config.h"
29+
#include "pressure.h"
2930
/* USER CODE END Includes */
3031

3132
/* Private typedef -----------------------------------------------------------*/
@@ -46,25 +47,13 @@
4647
/* Private variables ---------------------------------------------------------*/
4748

4849
/* USER CODE BEGIN PV */
49-
uint32_t rawPressureSensorValue;
50-
float fCalculatedVoltageFromRawPressureSensorVal;
50+
5151
/* USER CODE END PV */
5252

5353
/* Private function prototypes -----------------------------------------------*/
5454
void SystemClock_Config(void);
5555
/* USER CODE BEGIN PFP */
56-
uint8_t poll_Pressure_Sensor(void){
57-
HAL_ADC_PollForConversion(&hadc1,1000); // I haven't used HAL_MAX_DELAY here because we will be polling two more sensors after the pressure sensor, and waiting for an ADC conversion here indefinitely will result in the next two sensors not being read.
58-
rawPressureSensorValue = HAL_ADC_GetValue(&hadc1);
59-
//rawPressureSensorValue will be between 0 and 4095.
60-
fCalculatedVoltageFromRawPressureSensorVal = rawPressureSensorValue * (3.3/4095.0);
61-
//we now have a voltage between 0 and 3.3V
62-
HAL_Delay(200);
63-
//right now, I will configure this function to return the voltage itself
64-
//later on, we need to edit this to return the pressure
65-
//the pressure can be easily calculated from the voltage.
66-
return (uint8_t)fCalculatedVoltageFromRawPressureSensorVal;
67-
}
56+
6857
/* USER CODE END PFP */
6958

7059
/* Private user code ---------------------------------------------------------*/
@@ -120,7 +109,7 @@ int main(void)
120109
while (1)
121110
{
122111
//poll pressure sensor
123-
pressure = poll_Pressure_Sensor();
112+
pressure = poll_pressure_sensor();
124113
//poll IMU
125114
//poll thermistor MUX
126115

Sensors/Core/Src/pressure.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* pressure.c
3+
*
4+
* Created on: Apr 25, 2024
5+
* Author: mahesh, mahir
6+
*/
7+
8+
#include "pressure.h"
9+
#include "adc.h"
10+
11+
uint8_t poll_pressure_sensor(void){
12+
/*
13+
* I haven't used HAL_MAX_DELAY here because we will be polling
14+
* two more sensors after the pressure sensor, and waiting for an
15+
* ADC conversion here indefinitely will result in delays.
16+
*/
17+
HAL_ADC_PollForConversion(&hadc1,1000);
18+
uint32_t raw_pressure_sensor_value = HAL_ADC_GetValue(&hadc1);
19+
20+
//rawPressureSensorValue will be between 0 and 4095.
21+
uint8_t pressure = (raw_pressure_sensor_value/MAX_ADC_VALUE);
22+
23+
return pressure;
24+
}

0 commit comments

Comments
 (0)