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] Stuck in pic18f4520 project for charging controller

Status
Not open for further replies.

PIYUSH SONI

Newbie level 2
Newbie level 2
Joined
Nov 16, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
13
Hi,
I am PIYUSH. I am working on a project to control the charger using pic microcontroller. I am using pic 18f4520 MCU and easy pic5 development board. I have taken 2 ADC channel and displaying the equivalent voltage on 4*16 LCD. Actually i want to display the difference of both channel in percentage.Help me so that i can solve my problem. I am also attaching my program code:-

Code:
sbit LCD_RS at RB5_bit;
 sbit LCD_EN at RB4_bit;
 sbit LCD_D4 at RB3_bit;
 sbit LCD_D5 at RB2_bit;
 sbit LCD_D6 at RB1_bit;
 sbit LCD_D7 at RB0_bit;
 sbit LCD_RS_Direction at TRISB5_bit;
 sbit LCD_EN_Direction at TRISB4_bit;
 sbit LCD_D4_Direction at TRISB3_bit;
 sbit LCD_D5_Direction at TRISB2_bit;
 sbit LCD_D6_Direction at TRISB1_bit;
 sbit LCD_D7_Direction at TRISB0_bit;

 char message1[] = "SPG SYSTEMS";
 char message2[] = "-----------";
 char message3[] = "DEVELOPED BY:-";
 char message4[] = "SPG INFOTECH LTD";
 char message5[] = "CH1=      VOLTS";
 char message6[] = "CH2=      VOLTS";
 char message7[] = "CHARGER OFF";
 char message8[] = "CHARGER ON";


 sbit Relay  at RA5_bit;
 sbit Buzzer at RA4_bit;
 char *temp = "00000";
 char *temps = "00000";
 unsigned int adc_value;
 unsigned int adc_valueV;
 unsigned int adc_values;
 unsigned int adc_valueVs;
 unsigned char VOLTS;

 void main()
  {
  OSCCON = 0b01111110;
  ANSEL =  0b00000011;
  ADCON0 = 0b00001000;
  ADCON1 = 0b00000000;
  CMCON = 7 ;
  TRISA = 0b00000011;
  TRISB = 0b00000000;
  Lcd_Init();

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,3,message1);
  Lcd_Out(2,3,message2);
  Lcd_Out(3,-3,message3);
  Lcd_Out(4,-3,message4);

  Delay_ms(3000);
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1,message5);
  Lcd_Out(2,1,message6);
  Lcd_Out(4,1,message7);
  Lcd_Out(4,1,message8);

  do
 {
    Delay_ms(1);
    Lcd_Out(1,1,message5);
    Lcd_Out(2,1,message6);
    adc_value = ADC_READ(1);
    Delay_ms(25);
    adc_valueV = adc_value*4.89;
    temp[0] = adc_valueV/1000 + 48;
    temp[1] = '.';
    temp[2] = (adc_valueV/100)%10 + 48;
    temp[3] = (adc_valueV/10)%10 + 48;
    temp[4] = adc_valueV%10 + 48;
    Lcd_Out(1,5,temp);


    adc_values = ADC_READ(0);
    Delay_ms(25);
    adc_valueVs  = adc_values*4.89 ;
    temps[0] = adc_valueVs/1000 + 48;
    temps[1] = '.';
    temps[2] = (adc_valueVs/100)%10 + 48;
    temps[3] = (adc_valueVs/10)%10 + 48;
    temps[4] = adc_valueVs%10 + 48;
    Lcd_Out(2,5,temps);
    Delay_ms(500);

   if((adc_valueV/666 >2.0) || (adc_valueVs/666 >2.0))
    {
     Relay = 0;

     Lcd_Out(4,0,message7);
     Lcd_Cmd(_LCD_CLEAR);
     Lcd_Out(4,0,message7);

     Buzzer =1 ;

     }
    else
    {
     Relay = 1;

     Lcd_Out(4,0,message8);
      Lcd_Cmd(_LCD_CLEAR);
     Lcd_Out(4,0,message8);
     Buzzer =0 ;
     }
    }while(1);

   } /*
Plz help me to display the difference b/w adc channel .
 
Last edited by a moderator:

To find difference you just take the difference of adc_val and adc_values.


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
sbit LCD_RS at LATB5_bit;
sbit LCD_EN at LATB4_bit;
sbit LCD_D4 at LATB3_bit;
sbit LCD_D5 at LATB2_bit;
sbit LCD_D6 at LATB1_bit;
sbit LCD_D7 at LATB0_bit;
 
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
 
sbit Relay  at RA5_bit;
sbit Buzzer at RA4_bit;
 
char message1[] = "SPG SYSTEMS";
char message2[] = "-----------";
char message3[] = "DEVELOPED BY:-";
char message4[] = "SPG INFOTECH LTD";
char message5[] = "CH1=      VOLTS";
char message6[] = "CH2=      VOLTS";
char message7[] = "CHARGER OFF";
char message8[] = "CHARGER ON";
 
char temp[23];
char temps[23];
float adc_value;
float adc_valueV;
float adc_values;
float adc_valueVs;
unsigned char VOLTS;
 
void main(){
 
  OSCCON = 0b01111110;
  ANSEL =  0b00000011;
  ADCON0 = 0b00001000;
  ADCON1 = 0b00000000;
  CMCON = 7 ;
  TRISA = 0b00000011;
  TRISB = 0b00000000;
 
  Lcd_Init();
 
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Cmd(_LCD_CURSOR_OFF);
  Lcd_Out(1,3,message1);
  Lcd_Out(2,3,message2);
  Lcd_Out(3,3,message3);
  Lcd_Out(4,3,message4);
 
  Delay_ms(3000);
 
  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1,message5);
  Lcd_Out(2,1,message6);
  Lcd_Out(4,1,message7);
  Lcd_Out(4,1,message8);
 
  do{
 
        Delay_ms(1);
        Lcd_Out(1,1,message5);
        Lcd_Out(2,1,message6);
        adc_value = ADC_READ(1) * 4.89;
        FloatToStr(adc_value, temp);
        Lcd_Out(1,5,temp);
 
 
        adc_values = ADC_READ(0) * 4.89;
        FloatToStr(adc_values, temps);
    
        Lcd_Out(2,5,temps);
    
 
        if(((adc_value / 666) > 2.0) || ((adc_values / 666) > 2.0))
        {
            Relay = 0;
 
            Lcd_Out(4,0,message7);
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_Out(4,0,message7);
 
            Buzzer = 1 ;
 
        }
        else
        {
            Relay = 1;
 
            Lcd_Out(4,0,message8);
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_Out(4,0,message8);
            Buzzer = 0 ;
        }
 
    }while(1);
 
   }

 
@ jayanth :-Thanx for the help , I will try with this and let you know later.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top