Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[PIC] Issues with PIC16F688 code

Status
Not open for further replies.

sachsoni

Newbie level 4
Joined
Aug 2, 2014
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
50
We wrote the code for PIC 16F688 and this is using for controlling DC/AC load as per WattHour consumption. We try to restrict the usage of load energy from battery. We sense the solar/battery voltage and solar/battery current and try to restrict the energy usage as per our requirement.

In this code the IC 16F688 will not detect the analog calculation and not providing corresponding output. We are using Pin no. 13 & 12as a analog i/p for solar and battery voltage sense and 11 & 3 as a analog i/p for solar and battery current by hall sensor. Output is taken from pin no. 5.

I attached the complete code for this project. Kindly go through it and resolve why the IC will not able to read the analog input and pls send if any error found in coding.


Thank you,
 

Attachments


betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,368
Helped
4,727
Reputation
9,469
Reaction score
4,495
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,600
You are using the wrong bit to detect the end of ADC conversion. You are checking the enable bit 'ADON', you should be checking the conversion in progress bit 'GO_DONE'.

Brian.
 

sachsoni

Newbie level 4
Joined
Aug 2, 2014
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
50
Kindly provide us the info. in which line of program the changes will require to run code properly.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,368
Helped
4,727
Reputation
9,469
Reaction score
4,495
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,600
All the lines like this:
Code:
while(ADCON0bits.ADON == 1);
should be
Code:
while(ADCON0bits.GO_DONE == 1);
The ADON bit is used to enable or disable the ADC module, it should always be '1' when you are using the ADC.
The GO_DONE bit is set to '1' to start the measurement process and the PIC resets it to '0' when the measuring is complete. This is what I think your code is intended to do.

Brian.
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,368
Helped
4,727
Reputation
9,469
Reaction score
4,495
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,600
While clearing out my downloads, I spotted another possible problem:
Code:
            AnalogData = (unsigned int)(ADRESH&0x03);
            AnalogData = AnalogData<<8;
will only return a partial result, did you mean:
Code:
            AnalogData = (unsigned int)(ADRESH&0x03) << 8;
            AnalogData += ADRESL;
so you get a full 10 bit result?

Brian.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top