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.

[SOLVED] PIC16f886 adc checking problem

Status
Not open for further replies.

ragav4456

Full Member level 4
Full Member level 4
Joined
Aug 1, 2012
Messages
228
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,308
Visit site
Activity points
2,568
Hi

When i call the ReadADC() function, controller will restarted. what is the reason?

im using Hitech c compiler and MPLABX software.

Code:

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
#include<htc.h>
#include "adc.h"
 
 
__CONFIG(0x20A4);
__CONFIG(0X0700);
 
unsigned int ReadADC();
unsigned int ReadADC1();
void InitADC ();
 
 
unsigned char ucMenu_flag=0;
unsigned int uiHigh_volt=0,uilow_volt=0,uiDR_Amps=0,uiON_Time=0;
 
void main()
{
    unsigned int value, ivalue=0,Display=0;
 
    TRISA=0x03;
    PORTA=0x00;
    TRISB=0x00;
    PORTB=0x00;
    TRISC=0x01;
    PORTC=0x00;
 
    ANSEL = 0x03;       /* AN0,AN1 as analog pins */
    ANSELH = 0x00;
 
    OSCCON = 0b01101101;    /*Device runing External Osc*/
    OSCTUNE = 0x00;
 
     /* Initialize the ADC */
    InitADC(0);
 
    GIE=1;
    PEIE=1;
 
    while(1)
    {
        for(value=0;value<60000;value++);  //Delay
        ivalue = ReadADC(); 
 
        for(value=0;value<10000;value++);
        
        Display = ReadADC1();
 
        Lcd_Decimal(2,13,3,Display);
 
        for(value=0;value<20000;value++);
    }
}
 
unsigned int ReadADC()
{
 
      unsigned int ADC_VALUE=0;
//            ADCON1=0b10000000;
        ADCON0=0x43;
 
        ADIE        = 1;                                                    /* Masking the interrupt */
        ADIF        = 0;            /* Resetting the ADC interupt bit */
        ADRESL  = 0;            /* Resetting the ADRES value register */
        ADRESH  = 0;
 
        while(!ADIF);       /* Wait for conversion complete */
 
        ADC_VALUE = (ADRESH*256)+ADRESL;
 
    return (ADC_VALUE);     /* Return the value of the ADC process */
}
 
unsigned int ReadADC1()
{
 
      unsigned int ADC1_VALUE=0;
//            ADCON1=0b10000000;
        ADCON0=0x43;
 
        ADIE        = 1;                                                    /* Masking the interrupt */
        ADIF        = 0;            /* Resetting the ADC interupt bit */
        ADRESL  = 0;            /* Resetting the ADRES value register */
        ADRESH  = 0;
 
        while(!ADIF);       /* Wait for conversion complete */
 
        ADC1_VALUE = (ADRESH*256)+ADRESL;
 
    return (ADC1_VALUE);     /* Return the value of the ADC process */
}
 
void InitADC ()
{
        ADCON1=0b10000000;
}

 
Last edited by a moderator:

Hi,

I am not using PIC for some time ago so I do not remember it, but do you check the watchdog?

Thanks.
 

Check Configuration bits properly.Your clock mode is different than your code .You mentioned Internal Osc in Configuration bits and OSCCON = 0b01101101; /*Device runing External Osc*/ in your code
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top