ADC oddness on dsPIC33EP512GM710

An area to discuss 16-bit PIC specific problems and examples

Moderator: Benj

Post Reply
lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

ADC oddness on dsPIC33EP512GM710

Post 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.
Attachments
dsPIC33_test4.fcfx
(32.09 KiB) Downloaded 281 times

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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.
Attachments
Logic1_0.03_DEBUG2.fcfx
(16.31 KiB) Downloaded 286 times

User avatar
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: ADC oddness on dsPIC33EP512GM710

Post 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 271 times
Let us know how you get on.

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post by LeighM »

Thanks, please try this ...
Attachments
33EP512GM710.fcdx
(59.69 KiB) Downloaded 246 times

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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).

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post by LeighM »

Might be worth trying different values.
Latest FCD attached, as there was another bug in the previous ones.
Attachments
33EP512GM710.fcdx
(59.69 KiB) Downloaded 260 times

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post by LeighM »

What was the bug that the newest FCD fixed?
There was some wrong pin mapping info for RD14 and 15

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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).
Attachments
dsPIC33_test7.fcfx
(14.65 KiB) Downloaded 262 times

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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.

User avatar
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: ADC oddness on dsPIC33EP512GM710

Post 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.

User avatar
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: ADC oddness on dsPIC33EP512GM710

Post 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
(63.21 KiB) Downloaded 187 times
Then you need to copy this file into your "Flowcode 7/FCD/PIC16BIT" folder.
33EP512GM710.fcdx
(59.69 KiB) Downloaded 186 times
Finally restart Flowcode if you have it open.

Let us know how you get on.

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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.

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post by lexicon »

At least two other ADC channels are also working, so that looks good - thanks Ben.

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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.

User avatar
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: ADC oddness on dsPIC33EP512GM710

Post 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.

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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:

lexicon
Flowcode v5 User
Posts: 55
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 20 times
Been thanked: 22 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Post 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?

Post Reply