ADC oddness on dsPIC33EP512GM710

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

Moderator: Benj

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

ADC oddness on dsPIC33EP512GM710

Postby lexicon » Fri Feb 16, 2018 3:40 pm

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 16 times

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Wed Feb 21, 2018 6:19 pm

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 15 times
These users thanked the author lexicon for the post:
Benj (Wed Feb 28, 2018 12:38 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby Benj » Wed Feb 28, 2018 12:45 pm

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 20 times


Let us know how you get on.
These users thanked the author Benj for the post:
lexicon (Thu Mar 01, 2018 5:09 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Thu Mar 01, 2018 2:52 pm

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
These users thanked the author lexicon for the post:
Benj (Thu Mar 01, 2018 3:56 pm)
Rating: 5.88%
 

User avatar
LeighM
Matrix Staff
Posts: 1324
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby LeighM » Thu Mar 01, 2018 3:16 pm

Thanks, please try this ...
Attachments
33EP512GM710.fcdx
(59.69 KiB) Downloaded 18 times
These users thanked the author LeighM for the post:
lexicon (Thu Mar 01, 2018 4:25 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Thu Mar 01, 2018 5:02 pm

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: 1324
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby LeighM » Fri Mar 02, 2018 9:45 am

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 16 times
These users thanked the author LeighM for the post:
lexicon (Mon Mar 05, 2018 11:15 am)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Mon Mar 05, 2018 11:18 am

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: 1324
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 329 times
Been thanked: 477 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby LeighM » Mon Mar 05, 2018 11:23 am

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: 25
Joined: Mon Apr 06, 2015 6:30 pm
Has thanked: 10 times
Been thanked: 6 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Thu Apr 05, 2018 4:47 pm

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 12 times
These users thanked the author lexicon for the post:
LeighM (Fri Apr 06, 2018 11:18 am)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Wed Apr 18, 2018 8:39 am

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: 12708
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3556 times
Been thanked: 3439 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby Benj » Wed Apr 18, 2018 12:22 pm

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: 12708
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3556 times
Been thanked: 3439 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby Benj » Wed Apr 18, 2018 12:44 pm

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 10 times


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

33EP512GM710.fcdx
(59.69 KiB) Downloaded 9 times


Finally restart Flowcode if you have it open.

Let us know how you get on.
These users thanked the author Benj for the post:
lexicon (Wed Apr 18, 2018 2:05 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Wed Apr 18, 2018 2:12 pm

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.
These users thanked the author lexicon for the post:
Benj (Wed Apr 18, 2018 4:22 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Wed Apr 18, 2018 3:51 pm

At least two other ADC channels are also working, so that looks good - thanks Ben.
These users thanked the author lexicon for the post:
Benj (Wed Apr 18, 2018 4:22 pm)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Mon Apr 30, 2018 12:15 pm

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: 12708
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 3556 times
Been thanked: 3439 times
Contact:

Re: ADC oddness on dsPIC33EP512GM710

Postby Benj » Mon Apr 30, 2018 5:30 pm

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.
These users thanked the author Benj for the post:
lexicon (Tue May 01, 2018 8:54 am)
Rating: 5.88%
 

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

Re: ADC oddness on dsPIC33EP512GM710

Postby lexicon » Tue May 01, 2018 8:54 am

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: