liyi 1 рік тому
батько
коміт
dd568085b0

+ 4 - 4
F030/Core/Inc/main.h

@@ -9,14 +9,14 @@ extern "C" {
 
 
 #define 		VOLTAGE_CMD       								0xA5A5
-#define     ADC_CONVERT_COUNT    							(3000)
+#define     ADC_CONVERT_COUNT    							(1000)
 
 #define     Vref															(33)
 
 #define     COUNT_BASE												(4096)
 
-#define 		ALL_RES														(201000)
-#define 		GATHER_RES												(1000)
+#define 		ALL_RES														(500500)
+#define 		GATHER_RES												(500)
 
 #include "stm32f0xx_hal.h"
 
@@ -28,7 +28,7 @@ typedef union{
 
 typedef union{
 	uint8_t 	u8_tx[4];
-	float     f_data;
+	uint32_t     f_data;
 }Tx_Data;
 void Error_Handler(void);
 

+ 4 - 4
F030/Core/Src/adc.c

@@ -64,7 +64,7 @@ void MX_ADC_Init(void)
 
   /** Configure for the selected ADC regular channel to be converted.
   */
-  sConfig.Channel = ADC_CHANNEL_0;
+  sConfig.Channel = ADC_CHANNEL_1;
   sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
   sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
   if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
@@ -74,7 +74,7 @@ void MX_ADC_Init(void)
 
   /** Configure for the selected ADC regular channel to be converted.
   */
-//  sConfig.Channel = ADC_CHANNEL_4;
+//  sConfig.Channel = ADC_CHANNEL_2;
 //  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
 //  {
 //    Error_Handler();
@@ -102,7 +102,7 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
     PA3     ------> ADC_IN3
     PA4     ------> ADC_IN4
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
+    GPIO_InitStruct.Pin = GPIO_PIN_1;
     GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
@@ -145,7 +145,7 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
     PA3     ------> ADC_IN3
     PA4     ------> ADC_IN4
     */
-    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_4);
+    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2);
 
     /* ADC1 DMA DeInit */
     HAL_DMA_DeInit(adcHandle->DMA_Handle);

+ 9 - 5
F030/Core/Src/main.c

@@ -23,6 +23,7 @@
 #include "iwdg.h"
 #include "usart.h"
 #include "gpio.h"
+#include "math.h"
 
 
 
@@ -31,7 +32,7 @@
 extern ADC_HandleTypeDef hadc;
 
 
-
+extern IWDG_HandleTypeDef hiwdg;
 
 Data da={0};
 Tx_Data tx_voltage={0};
@@ -48,8 +49,8 @@ static void get_adc_val()
 	float temp = 0.0;
 	for(int i = 0 ;i < ADC_CONVERT_COUNT;i++)
 	{
-		HAL_ADC_Start_DMA(&hadc,(uint32_t*)adc_buff,2);
-		value += (adc_buff[0]);
+		HAL_ADC_Start_DMA(&hadc,(uint32_t*)adc_buff,1);
+			value += (adc_buff[0]);
 		//adc_val[i] = adc_buff[0];
 		HAL_Delay(1);
 	}
@@ -63,8 +64,10 @@ static void get_adc_val()
 	temp *=	ALL_RES;
 	temp /=	GATHER_RES;
 	temp /= 10.0;
-	temp /= 1000.0;
+	if(temp > 50)
+		temp+=(1.3*1000);
 	tx_voltage.f_data = temp;
+
 }
 
 
@@ -79,7 +82,7 @@ int main(void)
   MX_DMA_Init();
   MX_ADC_Init();
   MX_USART1_UART_Init();
-  //MX_IWDG_Init();
+  MX_IWDG_Init();
 	
 	HAL_ADCEx_Calibration_Start(&hadc);
 	
@@ -88,6 +91,7 @@ int main(void)
   while (1)
   {
 		//HAL_UART_Transmit(&huart1,(uint8_t*)(&tx_voltage.u8_tx),sizeof(tx_voltage),0xffff);
+		HAL_IWDG_Refresh(&hiwdg);
 		get_adc_val();
 		HAL_Delay(100);
   }

Різницю між файлами не показано, бо вона завелика
+ 10464 - 87
F030/MDK-ARM/JLinkLog.txt


Різницю між файлами не показано, бо вона завелика
+ 137 - 92
F030/MDK-ARM/adc_voltage.uvguix.Gowon


+ 15 - 6
F030/MDK-ARM/adc_voltage.uvoptx

@@ -117,6 +117,10 @@
         <pMon>Segger\JL2CM3.dll</pMon>
       </DebugOpt>
       <TargetDriverDllRegistry>
+        <SetRegEntry>
+          <Number>0</Number>
+          <Key>DLGUARM</Key>
+        </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Key>ARMRTXEVENTFLAGS</Key>
@@ -132,11 +136,6 @@
           <Key>ARMDBGFLAGS</Key>
           <Name></Name>
         </SetRegEntry>
-        <SetRegEntry>
-          <Number>0</Number>
-          <Key>DLGUARM</Key>
-          <Name>L</Name>
-        </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
@@ -175,6 +174,16 @@
           <WinNumber>1</WinNumber>
           <ItemText>adc_val</ItemText>
         </Ww>
+        <Ww>
+          <count>4</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>adc_val</ItemText>
+        </Ww>
+        <Ww>
+          <count>5</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>huart1</ItemText>
+        </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
@@ -190,7 +199,7 @@
       <DebugFlag>
         <trace>0</trace>
         <periodic>1</periodic>
-        <aLwin>0</aLwin>
+        <aLwin>1</aLwin>
         <aCover>0</aCover>
         <aSer1>0</aSer1>
         <aSer2>0</aSer2>