ソースを参照

Encoder update

Bartosz Jakubski 1 ヶ月 前
コミット
16883811f3

+ 1 - 1
OZE_Sensor/.cproject

@@ -37,7 +37,7 @@
 							</tool>
 							<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1014930278" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler">
 								<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.1138728485" name="Debug level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.debuglevel.value.g3" valueType="enumerated"/>
-								<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1368159996" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.ofast" valueType="enumerated"/>
+								<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1368159996" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
 								<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.496682559" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
 									<listOptionValue builtIn="false" value="DEBUG"/>
 									<listOptionValue builtIn="false" value="ARM_MATH_CM4"/>

+ 5 - 5
OZE_Sensor/Core/Inc/adc_buffers.h

@@ -24,16 +24,16 @@ enum _ADC1_DataInfo {
 	IL2Ref,
 	IL3Ref,
 	FanFB,
-	IIL1,
-	IIL2,
-	IIL3,
+//	IIL1,
+//	IIL2,
+//	IIL3,
     ADC1LastData,
 };
 typedef enum _ADC1_DataInfo ADC1_DataInfo;
 
 struct _ADC1_Data {
-    uint16_t adcDataBuffer[ADC1LastData];
-    uint16_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint16_t)) - ADC1LastData];
+    uint32_t adcDataBuffer[ADC1LastData];
+    uint32_t dummy[(__SCB_DCACHE_LINE_SIZE / sizeof (uint32_t)) - ADC1LastData];
 };
 
 enum _ADC2_DataInfo { IL1 = 0, IL2, IL3, ADC2LastData };

+ 4 - 4
OZE_Sensor/Core/Src/main.c

@@ -429,7 +429,7 @@ static void MX_ADC1_Init(void)
   hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
   hadc1.Init.Resolution = ADC_RESOLUTION_16B;
   hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
-  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
+  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
   hadc1.Init.LowPowerAutoWait = DISABLE;
   hadc1.Init.ContinuousConvMode = ENABLE;
   hadc1.Init.NbrOfConversion = 7;
@@ -555,7 +555,7 @@ static void MX_ADC2_Init(void)
   hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
   hadc2.Init.Resolution = ADC_RESOLUTION_16B;
   hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
-  hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
+  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
   hadc2.Init.LowPowerAutoWait = DISABLE;
   hadc2.Init.ContinuousConvMode = ENABLE;
   hadc2.Init.NbrOfConversion = 3;
@@ -1263,7 +1263,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
 		{
 			osMessageQueuePut(adc1MeasDataQueue, &adc1Data, 0, 0);
 		}
-		if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint16_t)) != HAL_OK)
+		if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint32_t)) != HAL_OK)
 		{
 			Error_Handler();
 		}
@@ -1310,7 +1310,7 @@ void StartDefaultTask(void *argument)
   {
 	  Error_Handler();
   }
-  if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint16_t)) != HAL_OK)
+  if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint32_t)) != HAL_OK)
   {
 	  Error_Handler();
   }

+ 12 - 10
OZE_Sensor/Core/Src/meas_tasks.c

@@ -170,9 +170,9 @@ void ADC1MeasTask (void* arg) {
 				float voltage = voltageWave[i][samplesCounter % SAMPLE_BUFFER_LENGTH];
 				float current = currentWave[i][samplesCounter % SAMPLE_BUFFER_LENGTH];
 #else
-				float voltage = adcData.adcDataBuffer[UL1 + i] * deltaADC * U_CHANNEL_CONST * gainCorrection * U_MeasCorrectionData[i].gain + U_MeasCorrectionData[i].offset;
-				float ref = (float)adcData.adcDataBuffer[IL1Ref + i];
-				float adcVal = (float)adcData.adcDataBuffer[IIL1 + i];
+				float voltage = (adcData.adcDataBuffer[UL1 + i] & 0xFFFF) * deltaADC * U_CHANNEL_CONST * gainCorrection * U_MeasCorrectionData[i].gain + U_MeasCorrectionData[i].offset;
+				float ref = (float)(adcData.adcDataBuffer[IL1Ref + i] & 0xFFFF);
+				float adcVal = (float)(adcData.adcDataBuffer[UL1 + i] >> 16);
 				float current = (adcVal - ref) * deltaADC * I_CHANNEL_CONST * gainCorrection * I_MeasCorrectionData[i].gain + I_MeasCorrectionData[i].offset;
 #endif
 				voltageAcc[i] += voltage * voltage;
@@ -199,7 +199,7 @@ void ADC1MeasTask (void* arg) {
 				samplesCounter = 0;
 				DbgLEDToggle(DBG_LED3);
 			}
-			float fanFBVoltage = adcData.adcDataBuffer[FanFB] * deltaADC * -4.35 + 12;
+			float fanFBVoltage = (adcData.adcDataBuffer[FanFB] & 0xFFFF) * deltaADC * -4.35 + 12;
             sensorsInfo.fanVoltage = fanFBVoltage;
 
 			osMutexRelease (resMeasurementsMutex);
@@ -364,18 +364,20 @@ void EncoderTask (void* arg) {
         }
     }
     while (pdTRUE) {
-        float encoderValue = *encoderTaskArg->pvEncoder;
         osMessageQueueGet (encoderTaskArg->dataQueue, &pinStates, 0, osWaitForever);
+        float encoderValue = *encoderTaskArg->pvEncoder;
 		if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
 			if (encoderStates[(step + 1) % 4] == pinStates) {
 				step++;
-				encoderValue += 360.0 / ENCODER_X_IMP_PER_TURN;
+				encoderValue++;
+//				encoderValue += 360.0 / ENCODER_X_IMP_PER_TURN;
 //				printf ("Forward\n");
 			} else if (encoderStates[(step - 1) % 4] == pinStates) {
-				encoderValue -= 360.0 / ENCODER_X_IMP_PER_TURN;
-				if (encoderValue < 0) {
-					encoderValue = 360.0 + encoderValue;
-				}
+				encoderValue--;
+//				encoderValue -= 360.0 / ENCODER_X_IMP_PER_TURN;
+//				if (encoderValue < 0) {
+//					encoderValue = 360.0 + encoderValue;
+//				}
 //				printf ("Reverse\n");
 				step--;
 			} else {

+ 1 - 1
OZE_Sensor/Core/Src/position_task.c

@@ -99,9 +99,9 @@ void PositionControlTask (void* argument) {
                     printf ("Axe %c start phase\n", posCtrlTaskArg->axe);
 #endif
                 }
+                *(posCtrlTaskArg->positionSetting) = posCtrlData.positionSettingValue;
                 osMutexRelease (sensorsInfoMutex);
 //                if (osMutexAcquire (positionSettingMutex, osWaitForever) == osOK) {
-                    *positionXControlTaskInitArg.positionSetting = posCtrlData.positionSettingValue;
 //                    osMutexRelease (positionSettingMutex);
 //                }
             }

+ 2 - 0
OZE_Sensor/Core/Src/uart_tasks.c

@@ -446,6 +446,7 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
         ReadWordFromBufer (spFrameData->dataBuffer, &inputDataBufferPos, (uint32_t*)&enocoderXValue);
         if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
             sensorsInfo.pvEncoderX = enocoderXValue;
+            sensorsInfo.currentXPosition = 100 * enocoderXValue / MAX_X_AXE_ANGLE;
             osMutexRelease (sensorsInfoMutex);
             respStatus = spOK;
         } else {
@@ -457,6 +458,7 @@ void Uart1ReceivedDataProcessCallback (void* arg, SerialProtocolFrameData* spFra
         ReadWordFromBufer (spFrameData->dataBuffer, &inputDataBufferPos, (uint32_t*)&enocoderYValue);
         if (osMutexAcquire (sensorsInfoMutex, osWaitForever) == osOK) {
             sensorsInfo.pvEncoderY = enocoderYValue;
+            sensorsInfo.currentYPosition = 100 * enocoderYValue / MAX_X_AXE_ANGLE;
             osMutexRelease (sensorsInfoMutex);
             respStatus = spOK;
         } else {

ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Core/Src/subdir.mk


ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Drivers/STM32H7xx_HAL_Driver/Src/subdir.mk


ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/subdir.mk


ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/subdir.mk


ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/subdir.mk


ファイルの差分が大きいため隠しています
+ 1 - 1
OZE_Sensor/Debug/Middlewares/Third_Party/FreeRTOS/Source/subdir.mk


ファイルの差分が大きいため隠しています
+ 59664 - 34564
OZE_Sensor/Debug/OZE_Sensor.list


ファイルの差分が大きいため隠しています
+ 3418 - 3165
OZE_Sensor/Debug/OZE_Sensor.map


ファイルの差分が大きいため隠しています
+ 2 - 2
OZE_Sensor/OZE_Sensor.ioc