Explorar o código

小电表。显示

liyi hai 1 ano
pai
achega
3dcb816e7d

+ 55 - 0
control/voltmeter/ADC/adc.c

@@ -196,3 +196,58 @@ void adc_channel_sample(uint16_t arr[])
 	//return (adc_regular_data_read();
 
 }
+
+uint16_t adc_channel_sample_V_P()
+{
+		adc_regular_channel_config(0U, ADC_CHANNEL_3, ADC_SAMPLETIME_1POINT5);
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+
+    /* wait the end of conversion flag */
+    while(!adc_flag_get(ADC_FLAG_EOC));
+    /* clear the end of conversion flag */
+    adc_flag_clear(ADC_FLAG_EOC);
+    /* return regular channel sample value */
+    return adc_regular_data_read();
+}
+uint16_t adc_channel_sample_V_S()
+{
+		adc_regular_channel_config(0U, ADC_CHANNEL_4, ADC_SAMPLETIME_1POINT5);
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+
+    /* wait the end of conversion flag */
+    while(!adc_flag_get(ADC_FLAG_EOC));
+    /* clear the end of conversion flag */
+    adc_flag_clear(ADC_FLAG_EOC);
+    /* return regular channel sample value */
+    return adc_regular_data_read();
+}
+
+
+uint16_t adc_channel_sample_I_P()
+{
+		adc_regular_channel_config(0U, ADC_CHANNEL_5, ADC_SAMPLETIME_1POINT5);
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+
+    /* wait the end of conversion flag */
+    while(!adc_flag_get(ADC_FLAG_EOC));
+    /* clear the end of conversion flag */
+    adc_flag_clear(ADC_FLAG_EOC);
+    /* return regular channel sample value */
+    return adc_regular_data_read();
+}
+uint16_t adc_channel_sample_I_S()
+{
+		adc_regular_channel_config(0U, ADC_CHANNEL_6, ADC_SAMPLETIME_1POINT5);
+    /* ADC software trigger enable */
+    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
+
+    /* wait the end of conversion flag */
+    while(!adc_flag_get(ADC_FLAG_EOC));
+    /* clear the end of conversion flag */
+    adc_flag_clear(ADC_FLAG_EOC);
+    /* return regular channel sample value */
+    return adc_regular_data_read();
+}

+ 6 - 1
control/voltmeter/ADC/adc.h

@@ -3,7 +3,7 @@
 
 
 
-
+#include "stdint.h"
 
 
 
@@ -19,5 +19,10 @@ float read_current(void);
 
 void adc_channel_sample(unsigned short arr[]);
 
+void AdcInit_old(void);
+uint16_t adc_channel_sample_V_P();
+uint16_t adc_channel_sample_I_S();
+uint16_t adc_channel_sample_V_S();
+uint16_t adc_channel_sample_I_P();
 #endif
 

+ 1 - 0
control/voltmeter/DISPLAY/display.c

@@ -328,6 +328,7 @@ void display_voltage(float num_f,float num_i)
 		{
 			if(channel[i] == 0)
 				show_num(i,num[i]);
+			for(int j = 0; j <4000;j++);
 		}
 //	}
 }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1851 - 1820
control/voltmeter/JLinkLog.txt


+ 18 - 2
control/voltmeter/TIMER/timer.c

@@ -73,6 +73,12 @@ extern uint16_t adc_original_value[4];
 
 
 
+
+
+
+
+
+
 void TIMER14_IRQHandler(void)
 {  
 	static int index = 0;
@@ -80,8 +86,18 @@ void TIMER14_IRQHandler(void)
   {
     timer_interrupt_flag_clear(TIMER14, TIMER_INT_FLAG_UP);       //清除定时器更新中断标志
   }
-	voltage_s[index] = abs(adc_original_value[0] - adc_original_value[1]-4);
-	current_s[index++] = abs(adc_original_value[2] - adc_original_value[3]-2);
+//	adc_original_value[0] = adc_channel_sample_V_P();
+//	adc_original_value[1] = adc_channel_sample_V_S();
+//	adc_original_value[2] = adc_channel_sample_I_P();
+//	adc_original_value[3] = adc_channel_sample_I_S();
+	if(adc_original_value[0]>0x20 )
+		voltage_s[index] = adc_original_value[0] -5;
+	else
+		voltage_s[index] = 0;
+	if(adc_original_value[2] > 0x10 )
+		current_s[index++] = adc_original_value[2]-4;
+	else
+		current_s[index++] = 0;
 	if(index == 200)
 	{
 		index = 0;

+ 23 - 2
control/voltmeter/USER/main.c

@@ -42,7 +42,7 @@ float read_voltage_I(uint16_t val)
 		value /= 10.0;
 		value /= 100.0;
 		value /= 1000.0;
-		value /= 1.414;
+		value /= 1.414213;
 	return value;
 }
 
@@ -69,6 +69,25 @@ void filter(uint16_t arr[],uint32_t lenth,float arr_o[])
 	}
 
 }
+#define VALUE_A (0xD0)
+
+void filter_kk(uint16_t arr[])
+{
+	uint16_t value_1 = arr[0];
+	for(int i = 1;i < 200;i++)
+	{
+		if((arr[i]-value_1) > VALUE_A)
+		{
+			arr[i] = value_1;
+		}else if((value_1 - arr[i])> VALUE_A)
+		{
+			arr[i] = value_1;
+		}
+		value_1 = arr[i]; 
+	}
+}
+
+
 float V_max[100] = {0};
 float I_max[100] = {0};
 
@@ -99,6 +118,8 @@ int main()
 			read_flag = 0;
 			float v_max = 0;
 			float i_max = 0;
+			filter_kk(voltage_s);
+			filter_kk(current_s);
 			filter(voltage_s,200,value_v);
 			filter(current_s,200,value_i);
 			for(int i = 0; i < 200;i++)
@@ -129,7 +150,7 @@ int main()
 				//	cureent += read_voltage_I(I_max[i]);
 				}
 				
-				show_val_1 = voltage/100;
+				show_val_1 = (voltage/100)-3.0;
 				show_val_2 = cureent/100;
 				voltage = 0.0;
 				cureent = 0.0;

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 185 - 185
control/voltmeter/volmeter.uvguix.Gowon


+ 37 - 24
control/voltmeter/volmeter.uvoptx

@@ -120,7 +120,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>DLGUARM</Key>
-          <Name>`</Name>
+          <Name>?</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -143,7 +143,40 @@
           <Name>UL2V8M(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0GD32E23x -FS08000000 -FL010000 -FP0($$Device:GD32E230C8$Flash\GD32E23x.FLM))</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
-      <Breakpoint/>
+      <Breakpoint>
+        <Bp>
+          <Number>0</Number>
+          <Type>0</Type>
+          <LineNumber>88</LineNumber>
+          <EnabledFlag>1</EnabledFlag>
+          <Address>0</Address>
+          <ByteObject>0</ByteObject>
+          <HtxType>0</HtxType>
+          <ManyObjects>0</ManyObjects>
+          <SizeOfObject>0</SizeOfObject>
+          <BreakByAccess>0</BreakByAccess>
+          <BreakIfRCount>0</BreakIfRCount>
+          <Filename>.\TIMER\timer.c</Filename>
+          <ExecCommand></ExecCommand>
+          <Expression></Expression>
+        </Bp>
+        <Bp>
+          <Number>1</Number>
+          <Type>0</Type>
+          <LineNumber>194</LineNumber>
+          <EnabledFlag>1</EnabledFlag>
+          <Address>134221644</Address>
+          <ByteObject>0</ByteObject>
+          <HtxType>0</HtxType>
+          <ManyObjects>0</ManyObjects>
+          <SizeOfObject>0</SizeOfObject>
+          <BreakByAccess>0</BreakByAccess>
+          <BreakIfRCount>1</BreakIfRCount>
+          <Filename>.\TIMER\timer.c</Filename>
+          <ExecCommand></ExecCommand>
+          <Expression>\\volmeter\TIMER/timer.c\194</Expression>
+        </Bp>
+      </Breakpoint>
       <WatchWindow1>
         <Ww>
           <count>0</count>
@@ -153,36 +186,16 @@
         <Ww>
           <count>1</count>
           <WinNumber>1</WinNumber>
-          <ItemText>out_V</ItemText>
+          <ItemText>vol_tage</ItemText>
         </Ww>
         <Ww>
           <count>2</count>
           <WinNumber>1</WinNumber>
-          <ItemText>out_I</ItemText>
+          <ItemText>max_index</ItemText>
         </Ww>
         <Ww>
           <count>3</count>
           <WinNumber>1</WinNumber>
-          <ItemText>V_max</ItemText>
-        </Ww>
-        <Ww>
-          <count>4</count>
-          <WinNumber>1</WinNumber>
-          <ItemText>value_v</ItemText>
-        </Ww>
-        <Ww>
-          <count>5</count>
-          <WinNumber>1</WinNumber>
-          <ItemText>voltage_s</ItemText>
-        </Ww>
-        <Ww>
-          <count>6</count>
-          <WinNumber>1</WinNumber>
-          <ItemText>value_v</ItemText>
-        </Ww>
-        <Ww>
-          <count>7</count>
-          <WinNumber>1</WinNumber>
           <ItemText>voltage_s</ItemText>
         </Ww>
       </WatchWindow1>