PIC32MZ2048EFM100 ADC problem.

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

Moderator: Benj

Lagoda
Posts: 141
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 60 times
Been thanked: 54 times
Contact:

PIC32MZ2048EFM100 ADC problem.

Postby Lagoda » Tue Jul 25, 2017 9:24 pm

Hi All,

I would like to use the AD Converter of the Curiosity PIC32MZ EF circuit board, but the attached program does not work in the target circuit.
Can I get some help?

Best Regards,

Lagoda
Attachments
PIC32MZ_test_ADC.fcfx
(10.16 KiB) Downloaded 83 times

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

Re: PIC32MZ2048EFM100 ADC problem.

Postby Benj » Wed Jul 26, 2017 10:48 am

Hello Lagoda,

Your SPI component properties appear to be missing a valid Prescale setting. Also if you are talking to an SPI device then you probably need to toggle the CS pin using an output icon in single bit mode, or at least pull the CS pin low before you start sending out SPI bytes.

Is there a LED on the board that you can flash, the 1 second flash program is a very good starting point.

https://www.matrixtsl.com/wikiv7/index. ... ED_flasher

If you can do this then you can maybe add PWM out to the LED and use the ADC to set the PWM duty to confirm the ADC is functioning.

I was going to buy one of the boards to chip in and help but they seem a bit expensive so we will try without for now.

Lagoda
Posts: 141
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 60 times
Been thanked: 54 times
Contact:

Re: PIC32MZ2048EFM100 ADC problem.

Postby Lagoda » Wed Jul 26, 2017 3:57 pm

Hi Ben,

Thanks for the quick response.
I set the prescale value in the SPI component.
To the SPI MOSI and SPI CLK output only the oscilloscope was connected to monitor the ADC Return Value.
Bus Settings:
Clock Polarity: Idle Low
Clock Phase:Leading Edge (actually is the Trailing Edge on the photo!)
Sample Point: Middle

I connected a 220Kohm potentiometer between 3.3V and GND.The AN13 pin was connected to the potentiometer's slider contact. But the SPI MOSI Data does not change. (I turned the potentiometer button right and left. :wink: )


Is ADC7 the default modul in the in the PIC32MZ? (When I use the Potentiometer Component.)
It is not necessary to the ADC inputs are simultaneously sampling in my project.

Best Regards,

Lagoda
Attachments
SPI_ADC_Return_Value.jpg
SPI_ADC_Return_Value.jpg (219 KiB) Viewed 3775 times
PIC32MZ_ADC.jpg
PIC32MZ_ADC.jpg (89.22 KiB) Viewed 3775 times

Lagoda
Posts: 141
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 60 times
Been thanked: 54 times
Contact:

Re: PIC32MZ2048EFM100 ADC problem.

Postby Lagoda » Mon Jul 31, 2017 9:53 am

Hi Ben,

I accepted your advice, and already I am able to flashing LEDs professionally. :wink:
But the ADC does not work properly.

The problem is that the Potentiometer component uses the ADC0 module.
ADC0 is only assigned to AN0 és A45 with an multiplexer which is connected the RB0(AN0) pin. (This pin connected to a LED on my circuitboard.)
Otherwise it seems ADC0 is working well.
Temporarily, the ADC7 would be a better choice because we can would to use the analog pins from AN7 to AN34.

What is your opinion?


Best Regards

Lagoda

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

Re: PIC32MZ2048EFM100 ADC problem.

Postby Benj » Tue Aug 01, 2017 1:15 pm

Hello Lagoda,

I think I have now made all the changes necessary to enable ADC7 rather than ADC0, though it's complicated so I'm not 100%.

Simply copy the attached file into your "Flowcode 7/CAL/PIC32BIT" folder and recompile your project.

We could do with a nicer way of dynamically switching between ADC modules depending on which channel you want to read.

PIC32BIT_CAL_ADC.c
(15.38 KiB) Downloaded 123 times


Let me know how you get on.
These users thanked the author Benj for the post:
Lagoda (Tue Aug 01, 2017 3:23 pm)
Rating: 5.56%
 

Lagoda
Posts: 141
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 60 times
Been thanked: 54 times
Contact:

Re: PIC32MZ2048EFM100 ADC problem.

Postby Lagoda » Tue Aug 01, 2017 3:23 pm

Hello Ben,

Unfortunately, it did not work.
I modified it a bit (ARDY7 and ADCDATA7 from ARDY0 and ADCDATA0) and now the AN7 input is active and the resolution is 6 bits.
Should be used in Class 2 or Class 3 mode.
The channel parameter is completely ineffective, and can not select the analogue input.

It's more complicated to setup than the other classical ADC-s. (I do not like this type of ADC.) :?

Best Regards,

Lagoda
Attachments
PIC32BIT_CAL_ADC_modification.jpg
PIC32BIT_CAL_ADC_modification.jpg (61.6 KiB) Viewed 3706 times

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

Re: PIC32MZ2048EFM100 ADC problem.

Postby Benj » Tue Aug 01, 2017 3:48 pm

I do not like this type of ADC


Agreed, Who knows what they were thinking when they came up with this design.

Let me know if you make any more progress.

Lagoda
Posts: 141
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 60 times
Been thanked: 54 times
Contact:

Re: PIC32MZ2048EFM100 ADC problem.

Postby Lagoda » Thu Aug 03, 2017 2:04 pm

Hi Ben,

I've made a version that tested in my Curiosity circuitboard and working.
I do not know how to program in C but "A blind man may perchance hit the mark."

The idea of the solution can be found in the PIC32 Family Reference Manual, ADC Scanning Multiple Inputs example.

The point is that all ADCs are initialized and turned on in scan mode, but only the selected ANx pin is scanned.
To solve this I needed a new variable (TEMP_CHANNEL) and a pointer (ANx_DATA).
Maybe starting to be good for the final version.

My experiences: ANx inputs related to ADC7 produce more noisy data results in this mode than inputs related to ADC0-ADC4.
Longer running time.
The chip temperature didn't drop either. :)

May need to review the port settings again too.

I hope I could help you with it.
I am interested in your opinion.

Best Regards,

Lagoda
Attachments
PIC32MZ_EF_test_AD_.fcfx
I tested with it.
(10.16 KiB) Downloaded 87 times
PIC32BIT_CAL_ADC_modified.c
(17.62 KiB) Downloaded 98 times
These users thanked the author Lagoda for the post:
Benj (Thu Aug 03, 2017 5:38 pm)
Rating: 5.56%