Page 1 of 1

ADC oddness on dsPIC33EP512GM710

Posted: Fri Feb 16, 2018 3:40 pm
by lexicon
Hi,
I've been working on a project using the dsPIC33EP512GM710.
All has been going reasonably well until I try to use some ADC inputs.
When reading from AN2 or AN3 (the only ones I'm currently using) I always seem to get 0.
I've stripped down my program to a simple test that reads AN3 and outputs the value directly to some bits (not all are available) of Port D Low and, in inverted form, Port B Low.
This works perfectly in simulation, but in hardware, although the included heartbeat output works, I see no change when varying the voltage at pin 25.

Another curiosity, that I have not tried to replicate here, is that Port B8 would remain high regardless of what it was actively set to until I read from either AN2 or AN3 when it would revert to its set condition.
I got around this by explicitly reading one of these at the start of my program, but I wonder if there is some underlying common issue.

Any thoughts welcome.

My test program is attached.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Feb 21, 2018 6:19 pm
by lexicon
I've been doing a bit more investigation on the incorrect B8 output.
It seems it's not the output to port B8 but reading from E13, this always presents a low state until I do an ADC read, then it works correctly.

The attached program works fine in sim - operating the input switch E13 selects the output state of B8.
Pressing Read_ADC (G6) reads the ADC channel but has no apparent other effect as you'd expect.

In hardware however, the input E13 always reads low, resulting in output B8 being permanently high.
That is, until G6 is taken high and the ADC read takes place, and then E13 reads correctly and the output corresponds accordingly.

At least, I think that's what is happening.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Feb 28, 2018 12:45 pm
by Benj
Many thanks for letting us know. I believe I have found the cause of the problem and resolved it now. Port E was being left in analogue mode on start up which forces digital reads to read low. After the ADC read it was correctly switching the Port E pins back to digital mode.

Simply copy the attached file to your "Flowcode 7/FCD/PIC16" folder and restart Flowcode and hopefully the problem will now be fixed.

33EP512GM710.fcdx
(59.49 KiB) Downloaded 39 times


Let us know how you get on.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Thu Mar 01, 2018 2:52 pm
by lexicon
Hi Ben,

I now get the following error:
C:\Program Files (x86)\Flowcode 7\CAL\/PIC16BIT\PIC16BIT_CAL_CAN.c:43:3: error: #error "Internal CAN not supported on this device"

I think you might have started with an old version as per this thread?
viewtopic.php?f=64&t=19490

Re: ADC oddness on dsPIC33EP512GM710

Posted: Thu Mar 01, 2018 3:16 pm
by LeighM
Thanks, please try this ...

Re: ADC oddness on dsPIC33EP512GM710

Posted: Thu Mar 01, 2018 5:02 pm
by lexicon
Thanks Leigh & Ben - yes, that seems to have fixed the port E initialisation.

Can you offer any suggestions regarding my ADC read seemingly always returning 0 as per my opening post?
I've tried a couple of different channels (namely, AN2,3 & 8 as I can easily attach a pot to those on the board) and I'm sweeping the voltage but never see any change.
I have not changed the acquisition timing, as suggested by another forum member, because the defaults have always worked in the past (albeit 8 bit PIC on Flowcode 5).

Re: ADC oddness on dsPIC33EP512GM710

Posted: Fri Mar 02, 2018 9:45 am
by LeighM
Might be worth trying different values.
Latest FCD attached, as there was another bug in the previous ones.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Mon Mar 05, 2018 11:18 am
by lexicon
OK Leigh, thanks.
I've tried some different timings but didn't make any difference - I'll have to look into it more closely, that will probably be in a few days.

What was the bug that the newest FCD fixed?

Re: ADC oddness on dsPIC33EP512GM710

Posted: Mon Mar 05, 2018 11:23 am
by LeighM
What was the bug that the newest FCD fixed?

There was some wrong pin mapping info for RD14 and 15

Re: ADC oddness on dsPIC33EP512GM710

Posted: Thu Apr 05, 2018 4:47 pm
by lexicon
So I finally got around to looking a bit deeper into my ADC issue.
I couldn't seem to get anywhere playing with timings etc within Flowcode, so I cobbled together some C code in MPLAB and I was able to flash a LED at a variable rate set by a pot - at least I know the hardware works.
I've imported that into the attached Flowcode and replaced delays, loops and output with FC instructions, hopefully just leaving the 'relevant' C code.
I have a section for ADC setup - I can't get the ADC to work without this, but I haven't experimented to see which instructions are critical.
There's a choice of value-read instructions, using C or FC macro - the C code works, but if I disable that and enable the FC macro instead then the result is always zero (I think, it doesn't vary anyway).

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Apr 18, 2018 8:39 am
by lexicon
Hi Leigh,

Have you any thoughts on why I can't get the ADC to work directly in Flowcode?
Ultimately I need to have quite a few ADC channels working and I'd much rather not have to code it in C.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Apr 18, 2018 12:22 pm
by Benj
Hello,

I think I have found the problems for you, the code is assuming that AN8 is on pin RB8 but on your device this is not the case, it's pin C2.

I'm working on a fix for this now.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Apr 18, 2018 12:44 pm
by Benj
Hello,

Right hopefully this should solve the problems you're having.

First you need to copy this file into your "Flowcode 7/CAL/PIC16BIT" folder.

PIC16BIT_CAL_ADC.c
(66.08 KiB) Downloaded 25 times


Then you need to copy this file into your "Flowcode 7/FCD/PIC16BIT" folder.

33EP512GM710.fcdx
(59.69 KiB) Downloaded 27 times


Finally restart Flowcode if you have it open.

Let us know how you get on.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Apr 18, 2018 2:12 pm
by lexicon
Thanks Ben, first impressions are good, it certainly works with the test code.
I'll try it out on my actual project as soon as I can.

Regards,
Martin.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Apr 18, 2018 3:51 pm
by lexicon
At least two other ADC channels are also working, so that looks good - thanks Ben.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Mon Apr 30, 2018 12:15 pm
by lexicon
One thing I've noticed is that, although the ADC supports 10 or 12 bit conversion, the bit depth is fixed at 12 in the Properties selector.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Mon Apr 30, 2018 5:30 pm
by Benj
Hello,

Currently we default to the highest ADC conversion bit depth. Would a 10-bit conversion be useful for you? Maybe we could add this as an optional parameter.

Re: ADC oddness on dsPIC33EP512GM710

Posted: Tue May 01, 2018 8:54 am
by lexicon
Hi Ben,

To be honest, no, I don't think it would be beneficial to me - I don't need the faster sample time or anything like that.
I was just curious as to whether it should be selectable.
Having looked at the help page it does say it will be the maximum the device supports, but I hadn't read that before..... :oops:

Re: ADC oddness on dsPIC33EP512GM710

Posted: Wed Mar 27, 2019 12:14 pm
by lexicon
It's been a while since I had the ADC issue, but I recently started a new project based on the same device and it appears that AN46 and AN47 do not work - I always seem to get a zero output.
I've had a look at the config file but they appear to be mapped to the correct pins (A14 & 15).
I'm using 7 other ADC inputs (AN0,1,9,10, 24, 28 & 30) without any issue.

Any thoughts?