Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] AC parameters reading by ADC & serial comunication using pic16F877A & micro c

Status
Not open for further replies.

vir_paksh@yahoo.co.in

Newbie level 6
Joined
Apr 8, 2013
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,444
Can any body help me? both in software & hard ware changes
to read ac parameters like voltage & current. Now my program & hardware reads DC parameters fantastically but I need to read ac parameters. And I need modification to my program i.e. 1.port D have to switched to high(FF), when ADC_Read(0)>265 and ADC_Read(0)<215. 2.port D have to switched to high(FF) when ADC_Read(0) to ADC_Read(4) >265 and 3.port D must be 0 for 215<ADC_Read(0)<265. And port D must be 0 for ADC_Read(0) to ADC_Read(4) <265. Program & proteus attached.

My program is as below:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
char message9[] = "VIRUPAKSHA SB";
char message10[] = "V";
char message11[] = "A";
char message12[] = "'C";
 
char message1[] = "IN PP:";
   char message2[] = "OUT PP:";
  char message3[] = "R-PH CNT:";                //
   char message4[] = "Y-PH CNT:";
  char message5[] = "B-PH CNT:";
  char message6[] = "DC VOLT:";
   char message7[] = "BAT CH CNT:";
    char message8[] = "HEAT:";
 char *temp = "0000";
 unsigned int ADC_Value;
 void main() {
  //ANSEL = 0b00000000; // RA2/AN2 is analog input
  ADCON0 = 0b00001000; // Analog channel select @ AN2
   ADCON1 = 0b10000000;
 // CMCON0 = 0x07 ; // Disbale comparators
  TRISC = 0b00000000; // PORTC All Outputs
  TRISA = 0b11111111; // PORTA All Outputs, Except RA3 and RA2
   UART1_Init(9600); // baud rate at 9600bps
 delay_ms(100);
 
  UART1_Write_Text(message9);
  UART1_Write('\r');
 
 Delay_ms(2000);
 
  do {
 
   adc_value = ADC_Read(0);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message1);
  UART1_Write_Text(temp);
  UART1_Write_Text(message10);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(1);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message2);
  UART1_Write_Text(temp);
 UART1_Write_Text(message10);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(2);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message3);
  UART1_Write_Text(temp);
  UART1_Write_Text(message11);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(3);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message4);
  UART1_Write_Text(temp);
  UART1_Write_Text(message11);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(4);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message5);
  UART1_Write_Text(temp);
  UART1_Write_Text(message11);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(5);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message6);
  UART1_Write_Text(temp);
 UART1_Write_Text(message10);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(6);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message7);
  UART1_Write_Text(temp);
  UART1_Write_Text(message11);
  UART1_Write('\r');
   Delay_ms(2000);
   adc_value = ADC_Read(7);
   temp[0] = adc_value/1000 + 48; // Add 48 to get the ASCII character value
   temp[1] = (adc_value/100)%10 + 48;
   temp[2] = (adc_value/10)%10 + 48;
   temp[3] = adc_value%10 + 48;
 UART1_Write_Text(message8);
  UART1_Write_Text(temp);
  UART1_Write_Text(message12);
  UART1_Write('\r');
   Delay_ms(2000);
  } while(1);
 }

 

Attachments

  • adc serial comunication.rar
    27.4 KB · Views: 93
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top