Analogue Input not working

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Analogue Input not working

Postby Lord Grezington » Fri Jun 22, 2018 4:32 pm

Hello all

I have a project using the 16F1786 and so far its not put a foot wrong, until it starts refusing to read AN10 (on portB).

So, datasheet says I need to select the pin as analogue, so I have the c-code anselb = 0x02;
It also says I now need to state that its an input, so the c-code I have is trisb = 0x02;

But it still seems the analogue values are not random, but just seem wrong... I don't really need much resolution so I started off just using bytes. But for some reason the values decrease before going back up. I have checked the analogue voltage is correct with a scope (it may be a little noisy but I'm sure I have got away with noisier signals in the past, the scope trace is below).

Analogue Signal.png
Analogue Signal.png (51.07 KiB) Viewed 933 times


I have then tried reading as int, but still getting strange values.

Anyone have any idea's?
Thanks

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Fri Jun 22, 2018 5:09 pm

Hi
Can you post your Flowchart I probably have 1786 in my lab and will try to run your FC with me .

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Sat Jun 23, 2018 7:38 am

Hello Qmesar

Nothing on the program now seems to work, I have some serious warnings on the compiler messages I am now trying to get rid of. I think I am going to revert back to a version that was working well and attempt to make small changes at a time before compiling. Even the analogue inputs on PortA have stopped now, I am a little anxious that I have somehow damaged the ADC on the IC... I have another board I can check this on as well though.

If I have tried all the above and still nothing, I will post the program - a simplified version as its a little long winded at the moment doing various other things.

Thanks

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Mon Jun 25, 2018 10:14 am

Hello Qmesar

Following my last post...

I have tried new hardware - there is no change
I have simplified the program as much as possible and withdrawn all serious warnings from compiler messages.

I do however need two Analogue inputs, one on AN10 (RB1) and the other on AN0 (RA0), neither of which is working as it should.

AN10 - this is the input I mentioned earlier - the values seem to start off around 0x80 (around 0V) then drop down to 0x00 (around 1.1V) before going back up again. Below is a scope trace with the UART value of the analogue input being read and the Voltage going into the pin (Red Channel below). (ignore the first byte for now).

AN10 - Weird Values (second byte).jpg
AN10 - Weird Values (second byte).jpg (50.1 KiB) Viewed 855 times


AN0 - The one for some reason just gives me 0x00 no matter what voltage is applied into the pin. The value is sent through UART on the fist byte and the Voltage can be seen in Red below.4


AN0 - Always 0x00 (first byte).jpg
AN0 - Always 0x00 (first byte).jpg (50.45 KiB) Viewed 855 times


I have also attached the simplified program (V6.1.4.0)

Thanks for your help...
Attachments
Analogue Issues.fcfx
(31.29 KiB) Downloaded 15 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Mon Jun 25, 2018 2:22 pm

Hi.
I am out of my lab this week ,I will give it ago when I am back.
just something I noticed
you have the oscon setting ar 0x7A for 16Mhz internal oscillator ,as far as I could remember in all my projects with a 16F17xx device at 16Mhz my OSCON where set at 0x78 .
make sure about this as it directly influence the TAD time of the ADC and that could cause strange behaviors

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Mon Jun 25, 2018 2:41 pm

Hello Qmesar

The second to last bit on the osccon register is the system clock select bits. the 1* which the 0x7A states I'm using the Internal oscillator block, where the 0x78 would use the FOSC<2:0> configuration words. I not sure it will make a difference but I will give it a go.

Thanks

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Mon Jun 25, 2018 8:54 pm

Hello Qmesar

Unfortunately changing the osccon register did not work, seems i will need to wait for you to return to the lab...

Thanks

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Tue Jun 26, 2018 7:23 am

Hi That is fine now we know :D
I will make a plan to run the adc on my setup will let you know

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Tue Jun 26, 2018 8:29 am

Hi.
I have just modified an old project of mine (sorry I am out of the lab,I have no time to analyse your Flowchart).
(1) I used the MATRIX ADC component set it to AN10 RB1
(2) Used the XT Oscillator on the EB006V9 and apply a varying Voltage at AN10 and Check the Results in the ICD
both returned values(int and Voltage ) is 100% correct
P1.jpg
P1.jpg (24.82 KiB) Viewed 800 times

P2.jpg
P2.jpg (23.86 KiB) Viewed 800 times


Then I switched to Internal Oscillator and output the ADC value on PORTA of the EB085 Combo board LED's it is working fine
I see no problem with the MATRIX ADC component for the PIC16F178x devices you should be able to use any ADC pin and get the correct values.
I attach my test project for you reference

P16F1786_ANALOG.rar
(82.14 KiB) Downloaded 15 times

I hope this helps :D
These users thanked the author QMESAR for the post (total 2):
LeighM (Tue Jun 26, 2018 8:41 am) • medelec35 (Tue Jun 26, 2018 8:49 am)
Rating: 11.76%
 

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Fri Jun 29, 2018 10:24 am

It's a little odd...

AN0 only works if I set the ADC components to AN1 (however analogue voltage is applied to AN0 or pin 2), but AN1 is also affected. So analogue voltages on both pins 1 & 2 change the value when read just AN1...

And if the c-code ansela = 0x01; & trisa = 0x01; is not applied the components still works but looks to be inverted.

I need ti try and figure out what happening with AN10 now... but if someone can look into why this issue may be occurring it would be very handy to get this fixed.

Thanks

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Sat Jun 30, 2018 11:15 am

Hi
I used the same Flowchart I posted above I just added the AN0 and AN1 they work fine with me .
as you can see here I have 5V on AN0 and 1.62Volt on AN1 and they respond as they should
c1.jpg
c1.jpg (30.27 KiB) Viewed 743 times


Lord Grezington wrote:And if the c-code ansela = 0x01; & trisa = 0x01; is not applied the components still works but looks to be inverted.

You do not need to set anything in C Code when using the MATRIX Component

Are you setting the ADC module parameters in the Properties
C2.jpg
C2.jpg (40.32 KiB) Viewed 743 times

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Mon Jul 09, 2018 2:51 pm

Hello QMESAR

Still having no luck. I cant use your code, is it completed on FC8?

All the module parameters are default.

There is definitely something wrong with this part though, I have used an entirely different hardware on a development board I designed and I am still getting strange readings....

If AN10 = 0V, and I adjust AN0, AN0 works perfectly.
If AN0 = 0V, and I adjust AN10, AN10 works perfectly.

But

If AN10 = 2.5V (127), and AN0 = 0, AN0 then also equals 2.5V (127)
As I increase AN0, the value decreases and hits 0 s AN0 hits 2.5V. Its as though they are either adding together or subtracting one from the other even though there is nothing like this in the code.

Please can you repeat the test using AN0 and AN10 (I am locked into these on the hardware)? Also preferably on FC6 (I have not updated in a while). I have attached the most simple program I could to show on hardware what is happening (using SPI to read the values).

Thanks
Attachments
Analogue Test.fcfx
(7.42 KiB) Downloaded 6 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Mon Jul 09, 2018 3:32 pm

Lord Grezington wrote:Please can you repeat the test using AN0 and AN10 (I am locked into these on the hardware)? Also preferably on FC6 (I have not updated in a while)


Well ok if you are using FC6 then I am sure its not working with you as there was a bug in the Analog component for the 16F17xx devices that got solved in late FC 7 just before FC 8

No use I test this for you with FC7 or 8 ask Ben /Matrix to look into the ADC component for 16F17xx devices in FC 6

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Tue Jul 10, 2018 10:00 am

Thanks QMESAR

Ben or anyone else from flowcode, please can you send be a bug fix for this?..

Thanks

Lord Grezington
Flowcode V4 User
Posts: 156
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 8 times
Been thanked: 14 times
Contact:

Re: Analogue Input not working

Postby Lord Grezington » Tue Jul 10, 2018 4:32 pm

I may be able to use a 16F1933 in the application. Are their any known bugs for this micro that I need to know about?

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 956
Joined: Sun Oct 05, 2014 3:20 pm
Has thanked: 304 times
Been thanked: 480 times
Contact:

Re: Analogue Input not working

Postby QMESAR » Thu Jul 12, 2018 3:03 pm

Lord Grezington wrote:I may be able to use a 16F1933 in the application. Are their any known bugs for this micro that I need to know about?


Hi
This is hard to give an answer as the FC world has move on it is at least 3-4 years since we used FC6 ,best would be you try a 16F1933 or move on to FC8

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

Re: Analogue Input not working

Postby Benj » Thu Jul 12, 2018 5:11 pm

Hello,

Here are some updated v6 files for you to try.

First of all this file needs to be placed into your "Flowcode 6/FCD/PIC" folder.

16F1786.fcdx
(18.77 KiB) Downloaded 5 times


Next this file needs to be placed into your "Flowcode 6/CAL/PIC" folder.

PIC_CAL_ADC.c
(106.42 KiB) Downloaded 6 times


Restart Flowcode and hopefully your ADC channels will now be working correctly.