Error in the ADC definition
Moderator: Benj
Error in the ADC definition
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
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
-
- Flowcode V4 User
- Posts: 25
- Joined: Thu Feb 22, 2007 3:20 pm
- Has thanked: 1 time
- Been thanked: 5 times
Re: Error in the ADC definition
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.The results of measuring was wild numbers.
-
- Flowcode V4 User
- Posts: 25
- Joined: Thu Feb 22, 2007 3:20 pm
- Has thanked: 1 time
- Been thanked: 5 times
Re: Error in the ADC definition
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
to the "876A"-Code
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);
Code: Select all
short iRetVal;
SampleADC();
iRetVal = (adresh << 2);
iRetVal = iRetVal | (adresl >> 6);
return (iRetVal);
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode V4 User
- Posts: 25
- Joined: Thu Feb 22, 2007 3:20 pm
- Has thanked: 1 time
- Been thanked: 5 times
Re: Error in the ADC definition
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.
#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.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode V4 User
- Posts: 36
- Joined: Mon Sep 26, 2011 10:26 pm
- Has thanked: 9 times
- Been thanked: 2 times
Re: Error in the ADC definition
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!
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 395 times
- 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
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.
Then click OK and select the read as int function and click edit.
Change the code to this.
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.
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;
Change the code to this.
Code: Select all
short iRetVal;
SampleADC();
iRetVal = (adresh << 2);
iRetVal = iRetVal | (adresl >> 6);
return (iRetVal);
Or you can find the appropriate C file in the Components directory and change the code there so the change becomes permanent.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode V4 User
- Posts: 25
- Joined: Thu Feb 22, 2007 3:20 pm
- Has thanked: 1 time
- Been thanked: 5 times
Re: Error in the ADC definition
The file for pic16F1827 is "PIC_ADC_23.c" in the "Component" Folder.
I attached my file, which is changed to work.
I attached my file, which is changed to work.
- Attachments
-
- PIC_ADC_23.c
- changed readasint and readasbyte macros
- (8.1 KiB) Downloaded 400 times
-
- Flowcode V4 User
- Posts: 36
- Joined: Mon Sep 26, 2011 10:26 pm
- Has thanked: 9 times
- Been thanked: 2 times
Re: Error in the ADC definition
Thank you VERY much!
Rosenbaum, It solved my problem!
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!
Rosenbaum, It solved my problem!



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!
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Error in the ADC definition
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
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 345 times
Martin