CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Unknown include header files

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
avaumbn



Joined: 02 Jul 2022
Posts: 4

View user's profile Send private message

Unknown include header files
PostPosted: Sat Jul 02, 2022 6:11 am     Reply with quote

In PIC CCS compiler, does it have a header file like this?

#include <regulator_ccs.h>
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 02, 2022 6:48 am     Reply with quote

You probably got that from here, which you should have said:
https://www.scirp.org/pdf/cs_2018021115384766.pdf

The regulator_ccs.h file is created by the CCS IDE. Based on the schematic
on page 9 of the pdf, they are probably using a 455 KHz resonator.
I'm going to ignore that and put in statements for a 4 MHz crystal below.
The following code will work as the regulator_ccs.h file
Code:
#include <16F877A.h>
#fuses  XT, PUT, BROWNOUT, NOWDT, NOLVP
#use delay(clock=4MHz)


Using that header, I was able to get the code in the pdf to compile.
However, I had to fix several typos. Example:
Currentt_bat should be Current_bat, etc.
avaumbn



Joined: 02 Jul 2022
Posts: 4

View user's profile Send private message

issues by simulation
PostPosted: Mon Jul 04, 2022 7:25 am     Reply with quote

You are very right.
I also fixed it but only two of the four ADC channels there are working, i.e. IPV and UPV both.
Others show that Ibat and Ubat are at a certain level
(Ubat =13.6 and Ibat =26.1) and cannot deviate from the 10k pot.
I have tried simulating it in Proteus. Everything else is showing well.
Do you have something to say?

Thanks for reply Sir
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 04, 2022 4:39 pm     Reply with quote

I assume you're using a 16F877A as shown in his schematic on page 9.
https://www.scirp.org/pdf/cs_2018021115384766.pdf

Ubat is measured on pin AN2 (RA2). His circuit looks really weird.
He has the V1 12v battery in the lower right quadrant. It feeds a voltage
divider made from 10Meg resistors that reduce the voltage to 2v. It puts
the 12v through five 10Meg resistors. So the input impedance to the PIC
is 50 MegOhms. He does the same thing with the uPV voltage.

This is a bad design. The maximum recommended input impedance to the
A/D in the PIC is 2.5K ohms, not 50 Meg.

See the parameter A30 on page 194 of the 16F877A data sheet:
https://ww1.microchip.com/downloads/aemDocuments/documents/MCU08/ProductDocuments/DataSheets/39582C.pdf

------------------------------------
He displays Voltage_bat as Ubat in the DisplayFormat() function on pg. 15:
Code:

lcd_gotoxy(1,2);
printf(lcd_putc, "Ubat = %f V", Voltage_bat);


He's got serious problems in the following code which reads the ADC
to get and calculate Voltage_bat. He reads the voltage on the AN2 input
but then it never gets saved after the math, because of a typo.
Then he over-writes it again in the ADC ch. 3 section by mistake.
This is crap code.
Quote:

void Mesure(void)
{
set_adc_channel(2);
Delay_ms(10);
Voltage_bat = read_adc();
Delay_ms(10);
Vomtage_bat = (Voltage_bat/1023)*5*6; // *** Typo

set_adc_channel(0);
Delay_ms(10);
Voltage_pv = read_adc();
Delay_ms(10);
Voltage_pv = (Voltage_pv/1023)*5*4;

// The following block of code is wrong. He is re-reading the ADC and
// putting the result into Voltage_bat. He really meant to put it into
// Current_bat
.
set_adc_channel(3);
Delay_ms(10);
Voltage_bat = read_adc(); // Over-writes Voltage_bat by mistake
Delay_ms(10);
Currentt_bat = (Currentt_bat/1023)*5; // *** Typos
Currentt_bat = 10*Currentt_bat-25; // *** Typos


set_adc_channel(1);
Delay_ms(10);
Current_pv = read_adc();
Delay_ms(10);
Currentt_pv = (Currentt_pv/1023)*5; // *** Typo
Currentt_pv = 10*Currentt_pv-25; // *** Typo

set_adc_channel(4);
Delay_ms(10);
Temperature = read_adc();
Delay_ms(10);
Temperature = (Temperature/1023)*5;
Temperature = Temperature*12.5;
Voltage_absorption = (14.5-0.03*(Temperature-25))*choice_bat;
Voltage_float = (13.6-0.03*(Temperature-25))*choice_bat;
Current_ch = Current_pv - Current_bat;
}


My opinion is this is fake project designed to schmooze his instructor.
It can't work. I advise you don't try to use it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Tue Jul 05, 2022 6:13 am     Reply with quote

Ouch...

As a further comment on the input impedance. The data sheet also gives
the internal leakage current of the ADC as +/-500nA. So can be anywhere
over this range. The impedance of the divider is 'only' 5MR (the pull down
resistor is effectively in parallel with the ones feeding this), but still at
500nA, this gives a voltage from the leakage of 2.5v!...
So the result is never going to be even remotely accurate. Almost wonder
(assuming the circuit ever was built), if the resistors were actually in Kohms,
rather the Mohms, and the circuit was a misprint.
avaumbn



Joined: 02 Jul 2022
Posts: 4

View user's profile Send private message

solved
PostPosted: Tue Jul 05, 2022 11:41 am     Reply with quote

But after some tweaking the software section is working properly,
let's see if the hardware switching section will work. Like you said
it looks like a project made to exploit someone.
But the concept is good.

Thanks for your valuable reply. Razz
avaumbn



Joined: 02 Jul 2022
Posts: 4

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 9:03 am     Reply with quote

Ttelmah wrote:
Ouch...

As a further comment on the input impedance. The data sheet also gives
the internal leakage current of the ADC as +/-500nA. So can be anywhere
over this range. The impedance of the divider is 'only' 5MR (the pull down
resistor is effectively in parallel with the ones feeding this), but still at
500nA, this gives a voltage from the leakage of 2.5v!...
So the result is never going to be even remotely accurate. Almost wonder
(assuming the circuit ever was built), if the resistors were actually in Kohms,
rather the Mohms, and the circuit was a misprint.


"The main difference between Resistance and Impedance is that resistance opposes the flow of DC & AC current whereas Impedance only opposes the flow of AC current. Impedance is having meaning only in AC circuit. It does not have any meaning in DC circuit."
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Jul 07, 2022 10:32 am     Reply with quote

\yes, which is why in terms of impeance the resistors forming the upper
part of the potential divider are in parallel with the one forming the lower
part. So the source impedance is not the 50MR that PCM quotes.
Still hundreds of times what is required, but not quite as bad.

Now the data sheet calla s the leakage DC, but in fact it is modulated DC,
so for the AC part of this signal you have to use the impedance as opposed
to the DC resiatance. It modulates through the ADC sampling cycle and
as the processor performs other operations.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group