I built a device using a 16F18313 with a pot connected to AN5 (RA.5) and it didn't seem to work.
I've built a simple test circuit on breadboard to pulse the LED based on the ADC reading and it doesn't work, the LED flashes ramdomly. I tried both AN5 and ANA5 to refer to the ADC but it made not difference.
If I connect the pot to AN4 (RA.4) everything works as expected.
I tried the same code on a 16F18326 (same family) and got the same results. On this device I also connected the pot to ANC2 and ANC5 and they both worked as expected.
Is there a problem using ANA5 in GCB with this family of PICs?
Interesting. I read your post and just happened to have the 16F18326 hooked up and running a version of the Microchip Reversible Chaselight Demo. I switched the analog input from RA4 to RA5 as a test and although it still works the adjustable speed range is much smaller than it was on RA4.
Conclusion: It is reading analogue on RA5 but something is wrong with the magnitude of the reading.
More investigation is needed but certainly an interesting problem.
I will have a closer look over the weekend.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I (we Hugh and I) are working on the ADC methods. We know of some issues. Let me know what you find as we know we have to make changes to fix the known issues.
Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods.
When you find more. Let us know.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When I had the pot on. ANA5, it was like the pin was floating rather than getting any kind reading. I was wondering if it wasn't being initialised properly?
On the built up circuit i tried using adread instead of adread10 but that didn't work as expected, however I try again on the test circuit over the weekend.
I didn't see anything in the datasheet regarding ANA5 working differently but I'll have another look.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've done some testing on a 16F18326 - code and logs attached.
I've read the values for ANA4, ANA5 and ANC5 while adjusting the potentiometer. Values for ANA2 and ANC5 are fine, ANA5 hardly change.
I also tried ANA4 with the ANA2 and ANA4 and ANC5 tied to 0V, and the same again but connecting Vref+ and Vref- to Vdd and 0V respectively.
The values of ANA5 seem to vary more when it is left floating and one of the other ADC channels is being used!
"Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods."
I also did some test this morning and my results were as follows:
Observed befaviour of ANA4 vs ANA5 Using ReadAD()
10K Potentiometer and 5V supply.
min < mid > max
ANA4 0 < 121 > 255
ANA5 0 < 121 > 255
Observed befaviour of ANA4 vs ANA5 Using ReadAD10()
10K Potentiometer and 5V supply.
min < mid > max
ANA4 3 < 502 > 1023
ANA5 408 < 573 > 725
Observed befaviour of ANA4 vs ANA5 Using ReadAD12()
10K Potentiometer and 5V supply.
min < mid > max
ANA4 4 < 514 > 1023
ANA5 3 < 512 > 1023
So using ANAx as my Pin Naming I am only seeing issues with ReadAD10() not reading the full range of ANA5 but working fine on ANA4.
I didn't try different naming conventions.
My test code is attached
I see no need to differentiate between 10 and 12 bit ADC read functions as the both return a word value but there are obvious coding differances that are manifesting as a hardware error in this case.
Certanly strange bahaviour and I would sugest using ReadAD12() for all ADC reads untill this is resolved.
You get to different results for ANA5 the First being way off andresembeling my result with ReadAD10() the Second being similer to ANA4, is that correct?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
New Test code and new results but rather than clarify anything I think it further muddies the waters.
Power was cycled between each block of tests then 3 readings each on two pins connected to the same POT were taken.
Test one is with RA5 Connected and RA4 Floating:
I get the same results as you for test 2 but different results for the others. AN5 appears dead.
I replaced the PIC for another one and got the same result. Connecting AN5 to 0V still gives a reading of 130 (with ReadAD10).
It is interesting that with Pot on AN4, AN5 floating, AN5 looks like it is
following AN4.
Did you power off between each test to allow the ADC to discharge?
I repeated my tests with another 18326 and got the same results, ANA5 is
working in my setup.
in your case it looks like it is floating.
I am using the Microchip Low Pin Count Board for my tests.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did not power down between those tests, I just pulled MCLR low.
My circuit is built on a breadboard powered from the USB, however the circuit with the 16F18313 where I first identified the problem is built on Veroboard powered by a wall adaptor @ 5v.
I just tried pulling out the power and waiting about 20 seconds and I get a slightly larger range on AN5 but it's still not correct:
Let Hugh and I sort the core issues we nred to sort which will resolve one root cause of these issues. We need to do this first. There is little point in trying to resolve thsee issues when I know we need to add a new capability to the compiler.
I will get to Hugh as soon as possible.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you tell your Great Cow Basic build please? Date of compiler? And, can you confirm that this is a vanilla build with no custom moving of files/.h file etc?
I have you code operating. I see no errors.
I have updated the a-d.h. A lot. Get the file from the URL. unzip, replace in your build and test.
And, if you want to optimise the code.... use the #define(s) in the code below. The code is optmised to support only channels (by direct port addressing) 4,5 and 21.
Enjoy.
#chip 16F18326
#define USE_AD0 FALSE
#define USE_AD1 FALSE
#define USE_AD2 FALSE
#define USE_AD2 FALSE
#define USE_AD3 FALSE
#define USE_AD4 TRUE
#define USE_AD5 TRUE
#define USE_AD6 FALSE
#define USE_AD7 FALSE
#define USE_AD8 FALSE
#define USE_AD9 FALSE
#define USE_AD10 FALSE
#define USE_AD11 FALSE
#define USE_AD12 FALSE
#define USE_AD13 FALSE
#define USE_AD14 FALSE
#define USE_AD15 FALSE
#define USE_AD16 FALSE
#define USE_AD17 FALSE
#define USE_AD18 FALSE
#define USE_AD19 FALSE
#define USE_AD20 FALSE
#define USE_AD21 TRUE
#define USE_AD22 FALSE
#define USE_AD23 FALSE
#define USE_AD24 FALSE
#define USE_AD25 FALSE
#define USE_AD26 FALSE
#define USE_AD27 FALSE
#define USE_AD28 FALSE
#define USE_AD29 FALSE
#define USE_AD30 FALSE
#define USE_AD31 FALSE
#define USE_AD32 FALSE
#define USE_AD33 FALSE
#define USE_AD34 FALSE
#define LED PORTC.2
dir LED Out
#define Pot1 ANA5
dir PORTA.5 In
#define Pot2 ANA4
dir PORTA.4 In
#define Pot3 ANC5
dir PORTC.5 In
#define serTx PORTA.0
Dir serTx Out
#define serRx PORTA.1
Dir serRx out
#define USART_BAUD_RATE 19200
#define USART_TX_BLOCKING
'Initial startup delay
Wait 500 ms
'Pulse the LED so we know the PIC is running
Repeat 5
Pulseout LED, 100 ms
Wait 100 ms
End Repeat
Wait 2 s
counter = 0
Repeat 2
hserprint "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
HSerPrintCRLF
End Repeat
'Setup
hserprint "PIC16F18326"
HSerPrintCRLF
hserprint "ANA4 - 0V"
HSerPrintCRLF
hserprint "ANA5 - 10K pot"
HSerPrintCRLF
hserprint "ANC5 - 0V"
HSerPrintCRLF
hserprint "RA2 - 0V"
HSerPrintCRLF
hserprint "RA1 - Vdd"
HSerPrintCRLF
'Read ADC value and send to the serial port
Do Forever
hserprint counter
hserprint " ANA5: "
hserprint readad10(Pot1)
hserprint " ANA4: "
hserprint readad10(Pot2)
hserprint " ANC5: "
hserprint readad10(Pot3)
HSerPrintCRLF
counter++
'Delay so the terminal screen isn't flooded!
Wait 1 s
Loop
Last edit: Anobium 2016-10-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I swapped my a-d.h for the one that you posted and no change: ANA5 followed ANA4 when it was floating and varied between 4 and 8 when connected to the pot.
I can run all the tests again if you want but given that you and Chris can get it working i think it must be an electrical problem at my end.
Compiler version is 0.95.009 2016-08-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry - tired. I ran Chris' test code with the revised a-d.h. I've run your code above, just adding in the PPS settings, turning MCLRE On and changing the information text to reflect how it's connected.
With the pot on ANA5, virtually no change in the ADC values. With the pot on ANA4 or ANC5 (and ANA5 grounded) the value read from ANA5 varies with the value from the pin that is connected to the pot.
The chips (16F18313 and 16F18326) both came from RS components. The device ID revision of the 16F18326 is 2001 - I'm not sure if there is a different version out there.
Yes it is connected, the picture is incorrect. I'm taking power. (and 0v) from the USB to serial device. There are a pair of wires from the rails to Vcc and Vss on the ISCP header.
Edit: Updated breadboard layout attached.
Edit2: Updated breadboard layout that doesn't have both sides of the pot on +5v
Everything that is Vss/0V/GND is connected to GND on the USB to serial device. This includes Vss on the ISCP header (diconnecting the PicKit3 doesn't make a difference to the problem though).
There's no external power applied, all the power is taken from the USB to serial converter.
When the potentiometer is connected to pin 3 (ANA4) then ANA4 works, if the wire is connected to pin 2 (ANA5) then ANA5 doesn't work. Nothing else gets changed.
I moved the PIC along a few holes on the breadboard in case it was a bad connection - didn't make a difference.
I'm wondering if I've somehow got a bad batch of PICs as I am getting the same problem with 2x16F18326 on breadboard and 2x16F18313 on stripboard whereas yourself and Chris are having no problems at all.
I am planning to order some stuff from Microchip Direct, so I can buy a new one direct from them and see if the same issue occurs.
Last edit: Peter 2016-10-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will try and give the new a-d.h a go this evening.
I have a vanilla build apart from a modified glcd.h (with the smaller buffer for low memory devices). I think my GBC is v.0.95.009 but I will check and report back.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I built a device using a 16F18313 with a pot connected to AN5 (RA.5) and it didn't seem to work.
I've built a simple test circuit on breadboard to pulse the LED based on the ADC reading and it doesn't work, the LED flashes ramdomly. I tried both AN5 and ANA5 to refer to the ADC but it made not difference.
If I connect the pot to AN4 (RA.4) everything works as expected.
I tried the same code on a 16F18326 (same family) and got the same results. On this device I also connected the pot to ANC2 and ANC5 and they both worked as expected.
Is there a problem using ANA5 in GCB with this family of PICs?
Last edit: Peter 2016-10-07
Interesting. I read your post and just happened to have the 16F18326 hooked up and running a version of the Microchip Reversible Chaselight Demo. I switched the analog input from RA4 to RA5 as a test and although it still works the adjustable speed range is much smaller than it was on RA4.
Conclusion: It is reading analogue on RA5 but something is wrong with the magnitude of the reading.
More investigation is needed but certainly an interesting problem.
I will have a closer look over the weekend.
Cheers
Chris
I (we Hugh and I) are working on the ADC methods. We know of some issues. Let me know what you find as we know we have to make changes to fix the known issues.
Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods.
When you find more. Let us know.
I found it odd that ANC5 worked but ANA5 did not.
When I had the pot on. ANA5, it was like the pin was floating rather than getting any kind reading. I was wondering if it wasn't being initialised properly?
On the built up circuit i tried using adread instead of adread10 but that didn't work as expected, however I try again on the test circuit over the weekend.
I didn't see anything in the datasheet regarding ANA5 working differently but I'll have another look.
I've done some testing on a 16F18326 - code and logs attached.
I've read the values for ANA4, ANA5 and ANC5 while adjusting the potentiometer. Values for ANA2 and ANC5 are fine, ANA5 hardly change.
I also tried ANA4 with the ANA2 and ANA4 and ANC5 tied to 0V, and the same again but connecting Vref+ and Vref- to Vdd and 0V respectively.
The values of ANA5 seem to vary more when it is left floating and one of the other ADC channels is being used!
Based on Evan's comment:
"Known issues: backward compatibility wth adc10 and we cannot create overloaded adc methods."
I also did some test this morning and my results were as follows:
So using ANAx as my Pin Naming I am only seeing issues with ReadAD10() not reading the full range of ANA5 but working fine on ANA4.
I didn't try different naming conventions.
My test code is attached
I see no need to differentiate between 10 and 12 bit ADC read functions as the both return a word value but there are obvious coding differances that are manifesting as a hardware error in this case.
Certanly strange bahaviour and I would sugest using ReadAD12() for all ADC reads untill this is resolved.
Cheers
Chris
Last edit: Chris Roper 2016-10-08
I've changed my code to use ReadAD12() and it didn't help.
I tried your code and got the following results:
ANA5: 123 < 168 > 183
ANA4: 2 < 498 > 1023
ANC5: 2 < 505 > 1023 (not ANA5!)
Last edit: Peter 2016-10-08
You get to different results for ANA5 the First being way off andresembeling my result with ReadAD10() the Second being similer to ANA4, is that correct?
SORRY that's a typo. It should be ANA5, ANA4 and ANC5.
ANA5 still gives an incorrect reading on my setup.
New Test code and new results but rather than clarify anything I think it further muddies the waters.
Power was cycled between each block of tests then 3 readings each on two pins connected to the same POT were taken.
Test one is with RA5 Connected and RA4 Floating:
Test two is with RA4 Connected and RA5 Floating:
Test Three has both RA4 and RA5 simultaniously connected to the same POT.
Test four, a control test, is with both RA4 and RA5 Flaoting.
Whereas the origional code showed errors with ReadADC10() this set of readings is getting expected results on all 3 ReadADC methods.
Code is attached to see if you can recreate my results.
Cheers
Chris
Last edit: Chris Roper 2016-10-08
I've run your code and the only modifications I made were:
I get the same results as you for test 2 but different results for the others. AN5 appears dead.
I replaced the PIC for another one and got the same result. Connecting AN5 to 0V still gives a reading of 130 (with ReadAD10).
Results
Pot on AN5, AN4 floating:
Pot on AN4, AN5 floating:
Same pot on AN4 and AN5:
AN4 and AN5 floating:
It is interesting that with Pot on AN4, AN5 floating, AN5 looks like it is
following AN4.
Did you power off between each test to allow the ADC to discharge?
I repeated my tests with another 18326 and got the same results, ANA5 is
working in my setup.
in your case it looks like it is floating.
I am using the Microchip Low Pin Count Board for my tests.
I did not power down between those tests, I just pulled MCLR low.
My circuit is built on a breadboard powered from the USB, however the circuit with the 16F18313 where I first identified the problem is built on Veroboard powered by a wall adaptor @ 5v.
I just tried pulling out the power and waiting about 20 seconds and I get a slightly larger range on AN5 but it's still not correct:
Pot on AN5, AN4 floating:
And the same thing with AN5 following AN4 even after a power down.
Pot on AN4, AN5 floating:
Last edit: Peter 2016-10-08
It's been a worthwhile day though - I've figured out PPS (to a lmited extent) and managed to get HWSPI working!
Great test results. Very good information.
Let Hugh and I sort the core issues we nred to sort which will resolve one root cause of these issues. We need to do this first. There is little point in trying to resolve thsee issues when I know we need to add a new capability to the compiler.
I will get to Hugh as soon as possible.
@Peter,
Can you tell your Great Cow Basic build please? Date of compiler? And, can you confirm that this is a vanilla build with no custom moving of files/.h file etc?
I have you code operating. I see no errors.
I have updated the a-d.h. A lot. Get the file from the URL. unzip, replace in your build and test.
Let us know the results please.
Download here
Last edit: Anobium 2016-10-10
And, if you want to optimise the code.... use the #define(s) in the code below. The code is optmised to support only channels (by direct port addressing) 4,5 and 21.
Enjoy.
Last edit: Anobium 2016-10-10
I swapped my a-d.h for the one that you posted and no change: ANA5 followed ANA4 when it was floating and varied between 4 and 8 when connected to the pot.
I can run all the tests again if you want but given that you and Chris can get it working i think it must be an electrical problem at my end.
Compiler version is 0.95.009 2016-08-09
Did you try the code above? I removed software serial and removed a few other odd things.
Post your code as an attachment. We can review again.
I cannot be 100% certain regarding your electrical layout. Can you post a drawing?
Where did you get the chip from?
But, it does work here. :-(
Sorry - tired. I ran Chris' test code with the revised a-d.h. I've run your code above, just adding in the PPS settings, turning MCLRE On and changing the information text to reflect how it's connected.
With the pot on ANA5, virtually no change in the ADC values. With the pot on ANA4 or ANC5 (and ANA5 grounded) the value read from ANA5 varies with the value from the pin that is connected to the pot.
The chips (16F18313 and 16F18326) both came from RS components. The device ID revision of the 16F18326 is 2001 - I'm not sure if there is a different version out there.
Last edit: Peter 2016-10-11
Do check this but looks like your 0v is not connected. The layout looks incorrect and so does the breakboard.
CHeck the datasheet 0v is on 14 pin/VSS.
Yes it is connected, the picture is incorrect. I'm taking power. (and 0v) from the USB to serial device. There are a pair of wires from the rails to Vcc and Vss on the ISCP header.
Edit: Updated breadboard layout attached.
Edit2: Updated breadboard layout that doesn't have both sides of the pot on +5v
Last edit: Peter 2016-10-11
Common 0v? Make sure 0v is common. I will test again tomorrow to confirm I am not making a error at my end.
Everything that is Vss/0V/GND is connected to GND on the USB to serial device. This includes Vss on the ISCP header (diconnecting the PicKit3 doesn't make a difference to the problem though).
There's no external power applied, all the power is taken from the USB to serial converter.
When the potentiometer is connected to pin 3 (ANA4) then ANA4 works, if the wire is connected to pin 2 (ANA5) then ANA5 doesn't work. Nothing else gets changed.
I moved the PIC along a few holes on the breadboard in case it was a bad connection - didn't make a difference.
I'm wondering if I've somehow got a bad batch of PICs as I am getting the same problem with 2x16F18326 on breadboard and 2x16F18313 on stripboard whereas yourself and Chris are having no problems at all.
I am planning to order some stuff from Microchip Direct, so I can buy a new one direct from them and see if the same issue occurs.
Last edit: Peter 2016-10-11
I will try and give the new a-d.h a go this evening.
I have a vanilla build apart from a modified glcd.h (with the smaller buffer for low memory devices). I think my GBC is v.0.95.009 but I will check and report back.