Still is not good, with AD_REF_AVCC and "true" at 3.3V is 1023, but in the vicinity of low voltages when the ADC reaches 0, continue turning the ADC potentiometer indicates above 65000. I use Curiosity nano, maybe is hardware problem...
You also need to Dimension your user variable - where the a2d result goes, like this.
Dim adcKP as Integer ' for Forced 10 bit adc, and the function reads
Function KPD '
adcKP = ReadAD10(ANC7,TRUE ) ' Forced 10 bit conversion
etc
This worked for for me.
BTW I never use PPS during R&D, It adds a layer of complexity you can do without. At power-on reset the original pinouts are valid !!
Cheers,
Geoffrey Younger
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I use integer variable to read AD10 , then I receive -500 to 1300 ADC, if I use AD 8bit, then is correct 0-255 , at reading AD12 I have 0-4095 ADC.
It is certain that something is not working in AD10.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would be guessing until I get onto some real silicon. Which will be next Monday.
OK to wait till then?
The issue could be in the ADC library but even that is a guess. I will do a root cause analysis and resolve for you and future users.
Please help me by producing a program that has the bare minimum to show the error. The program should have the correct chip, pps for that chip, serial setup, variable definition, adc reading and serial display of the adc results. Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey, that is good.... at least I have code that does not work!
There is nothing obvious from the ASM file. The first thing I look for is variables being created that look like Register names but there are none that meet this criteria ( I know this needs some experience but if something like ADCxxxxx would be an obvious bug... )
Till next week... unless someone else can resolve!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This may be a red herring and I didn't try to track this down, but looking at the asm output with GC v1.01061, as part of ReadAD10 I noticed there are two writes to the ADFM0 bit but none to the ADFM1 bit:
The range returned by pot1 = ReadAD10( AN2) is correct as per the compiler specification. ReadAD10 will always return the specific range for the specific chip. In this case it is a 12-bit Differential ADC and the range returned is 0 to 4095 which is correct.
I want to use ADC 10bit 0-1023, but in my listing ADC read 0-4095 why ?
Use READ10( AN2, TRUE )
The Help explains the second parameter.
Still is not good, with AD_REF_AVCC and "true" at 3.3V is 1023, but in the vicinity of low voltages when the ADC reaches 0, continue turning the ADC potentiometer indicates above 65000. I use Curiosity nano, maybe is hardware problem...
Last edit: Boguslaw 2024-01-18
You also need to Dimension your user variable - where the a2d result goes, like this.
Dim adcKP as Integer ' for Forced 10 bit adc, and the function reads
Function KPD '
adcKP = ReadAD10(ANC7,TRUE ) ' Forced 10 bit conversion
etc
This worked for for me.
BTW I never use PPS during R&D, It adds a layer of complexity you can do without. At power-on reset the original pinouts are valid !!
Cheers,
Geoffrey Younger
When I use integer variable to read AD10 , then I receive -500 to 1300 ADC, if I use AD 8bit, then is correct 0-255 , at reading AD12 I have 0-4095 ADC.
It is certain that something is not working in AD10.
ReadAD10 requires a WORD variable. What happens then?
I will be able to try this on real silicon next Monday. So, until then I will try to assist.
Word gives the numbers 65535 when the voltage is low
I would be guessing until I get onto some real silicon. Which will be next Monday.
OK to wait till then?
The issue could be in the ADC library but even that is a guess. I will do a root cause analysis and resolve for you and future users.
Please help me by producing a program that has the bare minimum to show the error. The program should have the correct chip, pps for that chip, serial setup, variable definition, adc reading and serial display of the adc results. Thank you.
OK I will wait, below is my listing
I have one more problem with this PIC, it doesn't work #define AD_REF_SOURCE AD_REF_2048
always is enabled AD_REF_AVCC.
I had already removed this from the test program below.
Let us fix one thing at the time.
I have cleaned up your program to create this baseline.
Please test to ensure this shows incorrect results. Share a revised program if you have to change and confirm this does shows the incorrect result
Last edit: Anobium 2024-01-19
Your code works similarly to mine, i.e. wrong
Hey, that is good.... at least I have code that does not work!
There is nothing obvious from the ASM file. The first thing I look for is variables being created that look like Register names but there are none that meet this criteria ( I know this needs some experience but if something like ADCxxxxx would be an obvious bug... )
Till next week... unless someone else can resolve!
This may be a red herring and I didn't try to track this down, but looking at the asm output with GC v1.01061, as part of ReadAD10 I noticed there are two writes to the ADFM0 bit but none to the ADFM1 bit:
I have a real chip on the bench now.
The range returned by
pot1 = ReadAD10( AN2)
is correct as per the compiler specification.ReadAD10
will always return the specific range for the specific chip. In this case it is a 12-bit Differential ADC and the range returned is 0 to 4095 which is correct.Using the following program segment.
As we now know from the datasheet that the ADC is a 12-bit we know we have to use the 12bit routines to properly use the ADC.
Using the following program segment.
So, before proceeding ... what is the requirement for 0-1023 ( 10bit value ) ?
If you need to a true 10bit ADC and not a calculated 10bit value then you need to change the chip.
So, the compiler is returning a 12bit when using ReadAD12( AN2 ) which is correct as this is a 12Bit ADC.
Let me know what you thoughts are.
Last edit: Anobium 2024-01-22
Ok, thank you for informations. I will use 12bit
Good luck.