Analog input not working on PIC32MZ2048ecg100

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

On the program with a PIC32MZ2048ecg100 a have a little problem.

If I insert potentiometer (slider) and get an int or get a string, the program is frezzing....
I tried AN22 and AN28

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by kersing »

Simulation or on hardware?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

on my own hardware

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I tried potentiometer slider and potentiometer panel. It's compieling and the program is running until I GetString or GetInt. It stops on this command.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

The program in the PIC will hang on the part of the Analog Input GetString or GetInt.
where does the problem come from? From the Component or PIC32mz definition?
Or am I doing something wrong?

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

Hello,

Please can you try calling the following ADC functions to help see specifically which call is causing the lock up.

Print LCD ("ADC-")
RawEnable()
Print LCD ("En")
RawSampleInt()
Print LCD ("Int")
RawDisable()
Print LCD ("Dis")

Both the enable and sample functions contain a while loop so I'm guessing one of these is causing the issue.

Attaching a simple program that demonstrates the problem might also be useful so we can look at your configuration settings etc.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

Enable/Disable are ok but Rawsample not.
Print LCD ("ADC-")
RawEnable()
OK
Print LCD ("En")
RawSampleInt()
Frezz

Print LCD ("Int")
RawDisable()
Print LCD ("Dis")
OK

I trie to make a small program for the AD and post it

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

Here the program for the AD Converter.

I need the AN22 on Pin 6 Port C1

Fc8_ecg4matrix_reduced_ad_converter.fcfx
(48.52 KiB) Downloaded 262 times

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I tried with FC8.1 but the analog Input is still not working..

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I found in the PIC32BIT_CAL_ADC.c some infos.
But nothing about the command.
FCD_0d101_Akku1__RawSampleByte();

/* ADC Type 2 Supported Devices ************************************************************
PIC32MZ2048ECG100 Family
*******************************************************************************************/

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

Hello,

You can find the source code for the RawSampleByte function here.

"C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC32BIT\PIC32BIT_CAL_ADC.c"

The PIC32MZ2048ecg100 device uses ADC type 2 which starts on line 147.

The CAL file basically defines three functions.

FC_CAL_ADC_Enable
FC_CAL_ADC_Sample
FC_CAL_ADC_Disable

The function FCD_0d101_Akku1__RawSampleByte will be defined in your Flowcode project C file and will directly call the three CAL functions.

If you need me to dig in and try and find the problem then I can do but I may need hardware to do it properly.

Also have you checked the Microchip site, specifically the Errata document for the device to make sure it's not a known silicone problem. If it's a known problem then they will often provide a workaround you can employ.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I looked at the code PIC32BIT_CAL_ADC for a while. There is a line to start the conversation as a comment. How then is the conversion started?

Yes I would like to send you a hardware, but I should have it back at the end of January.

MX_UINT16 FC_CAL_ADC_Sample (MX_UINT8 Sample_Mode)
{
MX_UINT16 iRetVal;

_SFR_WRITE(&AD1CON3,((_SFR_READ(&AD1CON3)&0xBFFFFFFF)|0x40000000));
//AD1CON3bits.GSWTRG = 1;
/* Wait the conversions to complete */
while (_SFR_BIT_READ(&AD1DSTAT1,MX_Current_Channel) == 0);

/* fetch the result */
if (Sample_Mode)
{
iRetVal = _SFR_READ(&AD1DATA0 + MX_Current_Channel);
}
else
iRetVal = (_SFR_READ(&AD1DATA0 + MX_Current_Channel) >> 2); //8-bit ADC

delay_us(1); //Required or processor locks up using Raw functions

return (iRetVal);
}

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

Can you give me an idea what do to that the analog input is working.
regards

Stefan

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I suspect the problem is somehow here.....

Code: Select all

_SFR_WRITE(&AD1CON3,((_SFR_READ(&AD1CON3)&0xBFFFFFFF)|0x40000000));
 //AD1CON3bits.GSWTRG = 1;
 /* Wait the conversions to complete */
 while (_SFR_BIT_READ(&AD1DSTAT1,MX_Current_Channel) == 0);

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

Hello,

Sorry for the delay. Let me see if I can replicate the problem here for you and see if I can get it working.

I'll bring my PIC32MZ board in tomorrow.

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

Hello,

Right I'm testing the ADC on the PIC32MZ2048EFG100 and this is not hanging but doesn't seem to be giving me the correct value at the moment.

I'll investigate and see if I can get this working and then compare with the ECG device.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

This old ECG Type PIC PIC32MZ2048ECG is on the old chipKIT Wi-FIRE! Revision B

https://reference.digilentinc.com/chipk ... 1507019925

The newer EFG Type PIC32MZ2048EFG100 microcontroller is on the newer chipKIT Wi-FIRE

https://store.digilentinc.com/wi-fire-w ... ler-board/

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

I do happen to have a ChipKit WiFire board here in my collection but it's the newer version :( Same as the board you sent.

I got excited for a minute there :roll:

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

How is the AD with the PIC32MZ2048efg going on?
Maybe with the PIC32MZ2048ecg it will not work.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

Now Im using the newer PIC32MZ2048efg100

If I use the analog input its not crashing but it don't give me a correct value back.
I put 2.2 volt on the input and it shows like 0.00324 but sometimes a little more or less.
If I remove the 2.2volt it's always shows the same values..
The progam use the AN22. I config to AN21 and AN23 but the same value even there is no 2.2volt

regards

Stefan

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

You wrote me a while ago about the AD from the PIC. Is there a way to fix it?
regards

Stefan
Right I'm testing the ADC on the PIC32MZ2048EFG100 and this is not hanging but doesn't seem to be giving me the correct value at the moment.

I'll investigate and see if I can get this working and then compare with the ECG device.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I use a simple programloop to test the AD converter in the PIC Pin6 AN22.
I send the result to the Computer. It shows just numbers like 1,2,0,1,0,1
On the hardwarepin it's the correct voltage of 1.9Volt.(litium akku divided by 2)
There is a problem somewhere ...
Analog-input.PNG
(15.32 KiB) Downloaded 1352 times

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

I found a problem.
If I use the slider_plastic component and choose AN0 (port B0) the AD is working fine with the signal on B0.

When I change the slider_plastic component to:
AN1 (port B1) the AD is showing me the signal on B0.
AN22 (port C1) the AD is showing me the signal on B0.
I'ts shows always the signal on AN0 (port B0)

regards

Stefan

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: Analog input not working on PIC32MZ2048ecg100

Post by Benj »

Hi Stefan,

Thanks for letting us know. I've pushed a change that hopefully will make a difference. If not then let me know and I'll investigate further for you.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ2048ecg100

Post by stefan.erni »

Hi Ben

It's still the same. No change.

Post Reply