Error in the ADC definition

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
HjH
Posts: 108
Joined: Sat Jul 03, 2010 4:38 pm
Been thanked: 2 times
Contact:

Error in the ADC definition

Post by HjH »

Hallo,

the controler is a 16LF1939 with 16MHz tact.

I could not read the 13 ADC Channels with the Flowcode ADC-component. The results of measuring was wild numbers. After my correction of the codes the result was sent correct, but the result had the average deviation from 1.1 %. The maximum deviation of fraud 100%. After the correction the deviation is 0%.
You can the correction of the function "SampleADC" and " ReadAsInt" check in the sample
ADC_Test_2.fcf
(14.46 KiB) Downloaded 375 times

Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Error in the ADC definition

Post by Rosenbaum »

The results of measuring was wild numbers.
When the numbers jump from 64 - 128 - 192 in "ReadAsByte" and 256 - 512 - 768 in "ReadAsInt", I have the same problem with PIC16F1827 and PIC16F1936.Maybe the problem is the left-right justify or the new Bit's in ADCON0 and ADCON1.

Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Error in the ADC definition

Post by Rosenbaum »

I found a short and nice solution.
I looked at the "UserCode" from ReadAsInt ans ReadAsByte and changed the code from the 1827/1936-Code

Code: Select all

	short iRetVal;
	SampleADC();
	#ifdef _BOOSTC
		#ifdef ADRES
			iRetVal = (adres << 2);
		#else
			iRetVal = (adresh << 2);
			iRetVal = iRetVal | (adresl >> 6);
		#endif
	#endif
	#ifdef HI_TECH_C
		#ifdef adres
			iRetVal = (adres << 2);
		#else
			iRetVal = (adresh << 2);
			iRetVal = iRetVal | (adresl >> 6);
		#endif
	#endif
	return (iRetVal); 
to the "876A"-Code

Code: Select all

	short iRetVal;
	SampleADC();
	iRetVal = (adresh << 2);
	iRetVal = iRetVal | (adresl >> 6);
	return (iRetVal);

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in the ADC definition

Post by Benj »

Hello,

Yes it seems that on some of these newer devices both the "ADRES" and "ADRESH" registers are defined which is throwing off the code we use to detect which type is present. I will see if we can make this work correctly for the next release.

Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Error in the ADC definition

Post by Rosenbaum »

Jes, I think the problem start at
#define ADRES 0x009B
#define ADRESL 0x009B
#define ADRESH 0x009C
in ..\boostc\include\pic16F1xxx.h
It seems that ADRES should used as an integer for AdresL+AdresH, but Flowcode use only AdresL.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in the ADC definition

Post by Benj »

Hello,

Yes that makes sense, Hopefully there is an elegant solution to resolve the problem. I guess it depends mainly on whether BoostC have adopted this approach throughout the entire range of devices. We have already thought up a mechanism to allow Flowcode v5 to work much better with regards to component problems such as these by coding the appropriate registers for a device into the FCD device definition file.

Dmitry Maximenko
Flowcode V4 User
Posts: 36
Joined: Mon Sep 26, 2011 10:26 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Re: Error in the ADC definition

Post by Dmitry Maximenko »

HI,
OK, if I use 16f1827 what shall I do?
Do I need to add C code to solve that problem?
Please modifi my flow chart to get it work:-) then I have chans to anderstand.
Very grateful!
Attachments
Sampling and outputting to a LCD.fcf
16f1827 AD conversion problem
(7.5 KiB) Downloaded 359 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Error in the ADC definition

Post by Benj »

Hello,

You can use the method Rosenbaum suggested above.

Add an ADC component to your program, right click the ADC component and select custom code.

Click the read as byte function and click edit.

Change the code to this.

Code: Select all

SampleADC();
return adresh;
Then click OK and select the read as int function and click edit.

Change the code to this.

Code: Select all

short iRetVal;
SampleADC();
iRetVal = (adresh << 2);
iRetVal = iRetVal | (adresl >> 6);
return (iRetVal);
You will need to repeat this process for each ADC component you have included in your program.

Or you can find the appropriate C file in the Components directory and change the code there so the change becomes permanent.

Rosenbaum
Flowcode V4 User
Posts: 25
Joined: Thu Feb 22, 2007 3:20 pm
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: Error in the ADC definition

Post by Rosenbaum »

The file for pic16F1827 is "PIC_ADC_23.c" in the "Component" Folder.
I attached my file, which is changed to work.
Attachments
PIC_ADC_23.c
changed readasint and readasbyte macros
(8.1 KiB) Downloaded 357 times

Dmitry Maximenko
Flowcode V4 User
Posts: 36
Joined: Mon Sep 26, 2011 10:26 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Re: Error in the ADC definition

Post by Dmitry Maximenko »

Thank you VERY much!
Rosenbaum, It solved my problem! :D :D :D
I had the problem in three days to try solve it! Was getting frustrated.-((.

What about the internal voltage reference on 16f1827?
Can we use it in the flow code?

Very grateful for the help!

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Error in the ADC definition

Post by medelec35 »

16F1822, 16F1823, 16F1824, 16F1825, 16F1828 & 16F1829 are also affected. All use PIC_ADC_26.c . For example using 16F1824 AN2 ReadAsInt. With 0V at pin 11 Instead of reading 0 it was reading at 255
This is solved by placing attached PIC_ADC_26.c into Flowcode V4/components directiory, overwriting original file.
I would like to say thanks to Rosenbaum for solving this issue

Martin
Attachments
PIC_ADC_26.c
(8.13 KiB) Downloaded 300 times
Martin

Post Reply