PIC32MZ2048EFH100 ADC help

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

PIC32MZ2048EFH100 ADC help

#1 Post by yo2lio » 11 Dec 2016 17:03

Hi,

Can someone help me with PIC32MZ2048EFH100 ADC?

I tried to init the ADC, but software block when check for voltage reference to be stable...

Code: Select all

var ADCCON1_ : dword; absolute 0xBF84B000; volatile; sfr; atomic;
var ADCCON2_ : dword; absolute 0xBF84B004; volatile; sfr; atomic;
var ADCCON3_ : dword; absolute 0xBF84B008; volatile; sfr; atomic;

var ADCTRGMODE_ : dword; absolute 0xBF84B00C; volatile; sfr; atomic;

var ADCIMCON1_ : dword; absolute 0xBF84B010; volatile; sfr; atomic;
var ADCIMCON2_ : dword; absolute 0xBF84B014; volatile; sfr; atomic;
var ADCIMCON3_ : dword; absolute 0xBF84B018; volatile; sfr; atomic;

var ADCGIRQEN1_ : dword; absolute 0xBF84B020; volatile; sfr; atomic;
var ADCGIRQEN2_ : dword; absolute 0xBF84B024; volatile; sfr; atomic;

var ADCCSS1_ : dword; absolute 0xBF84B028; volatile; sfr; atomic;
var ADCCSS2_ : dword; absolute 0xBF84B02C; volatile; sfr; atomic;

var ADCDSTAT1_ : dword; absolute 0xBF84B030; volatile; sfr; atomic;
var ADCDSTAT2_ : dword; absolute 0xBF84B034; volatile; sfr; atomic;

var ADCFLTR1_ : dword; absolute 0xBF84B068; volatile; sfr; atomic;
var ADCFLTR2_ : dword; absolute 0xBF84B06C; volatile; sfr; atomic;
var ADCFLTR3_ : dword; absolute 0xBF84B070; volatile; sfr; atomic;
var ADCFLTR4_ : dword; absolute 0xBF84B074; volatile; sfr; atomic;
var ADCFLTR5_ : dword; absolute 0xBF84B078; volatile; sfr; atomic;
var ADCFLTR6_ : dword; absolute 0xBF84B07C; volatile; sfr; atomic;

var ADCTRG1_ : dword; absolute 0xBF84B080; volatile; sfr; atomic;
var ADCTRG2_ : dword; absolute 0xBF84B084; volatile; sfr; atomic;
var ADCTRG3_ : dword; absolute 0xBF84B088; volatile; sfr; atomic;

var ADCCMPCON1_ : dword; absolute 0xBF84B0A0; volatile; sfr; atomic;
var ADCCMPCON2_ : dword; absolute 0xBF84B0A4; volatile; sfr; atomic;
var ADCCMPCON3_ : dword; absolute 0xBF84B0A8; volatile; sfr; atomic;
var ADCCMPCON4_ : dword; absolute 0xBF84B0AC; volatile; sfr; atomic;
var ADCCMPCON5_ : dword; absolute 0xBF84B0B0; volatile; sfr; atomic;
var ADCCMPCON6_ : dword; absolute 0xBF84B0B4; volatile; sfr; atomic;

var ADC0TIME_ : dword; absolute 0xBF84B0D4; volatile; sfr; atomic;
var ADC1TIME_ : dword; absolute 0xBF84B0D8; volatile; sfr; atomic;
var ADC2TIME_ : dword; absolute 0xBF84B0DC; volatile; sfr; atomic;
var ADC3TIME_ : dword; absolute 0xBF84B0E0; volatile; sfr; atomic;
var ADC4TIME_ : dword; absolute 0xBF84B0E4; volatile; sfr; atomic;

var ADCEIEN1_ : dword; absolute 0xBF84B0F0; volatile; sfr; atomic;
var ADCEIEN2_ : dword; absolute 0xBF84B0F4; volatile; sfr; atomic;

var ADCANCON_ : dword; absolute 0xBF84B100; volatile; sfr; atomic;

var ADC0CFG_ : dword; absolute 0xBF84B180; volatile; sfr;
var ADC1CFG_ : dword; absolute 0xBF84B184; volatile; sfr;
var ADC2CFG_ : dword; absolute 0xBF84B188; volatile; sfr;
var ADC3CFG_ : dword; absolute 0xBF84B18C; volatile; sfr;
var ADC4CFG_ : dword; absolute 0xBF84B190; volatile; sfr;
var ADC7CFG_ : dword; absolute 0xBF84B19C; volatile; sfr;

var ADCDATA2_ : dword; absolute 0xBF84B208; volatile; sfr;
var ADCDATA3_ : dword; absolute 0xBF84B20C; volatile; sfr;  // AN48
var ADCDATA4_ : dword; absolute 0xBF84B210; volatile; sfr;  // AN49
var ADCDATA5_ : dword; absolute 0xBF84B214; volatile; sfr;
var ADCDATA15_ : dword; absolute 0xBF84B23C; volatile; sfr;
var ADCDATA16_ : dword; absolute 0xBF84B240; volatile; sfr;
var ADCDATA27_ : dword; absolute 0xBF84B26C; volatile; sfr;
var ADCDATA28_ : dword; absolute 0xBF84B270; volatile; sfr;

var DEVADC0_ : dword; absolute 0xBFC54000; volatile; sfr;
var DEVADC1_ : dword; absolute 0xBFC54004; volatile; sfr;
var DEVADC2_ : dword; absolute 0xBFC54008; volatile; sfr;
var DEVADC3_ : dword; absolute 0xBFC5400C; volatile; sfr;
var DEVADC4_ : dword; absolute 0xBFC54010; volatile; sfr;
var DEVADC7_ : dword; absolute 0xBFC5401C; volatile; sfr;

procedure init_adc;
begin
  ADC7CFG_ := DEVADC7_;

//* Configure ADCCON1 */
  ADCCON1_ := 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo,
  ADCCON1_.22 := 1; // ADC7 resolution is 12 bits
  ADCCON1_.21 := 1; // ADC7 resolution is 12 bits
  
//* Configure ADCCON2 */
  ADCCON2_ := 0;
  ADCCON2_.18 := 1; // ADC7 sampling time = 5 * TAD7
  ADCCON2_.16 := 1; // ADC7 sampling time = 5 * TAD7
  ADCCON2_.0 := 1; // ADC7 clock freq is half of control clock = TAD7
  
//* Initialize warm up time register */
  ADCANCON_ := 0;
  ADCANCON_.26 := 1; // Wakeup exponent = 32 * TADx
  ADCANCON_.24 := 1; // Wakeup exponent = 32 * TADx
  
//* Clock setting */
  ADCCON3_ := 0;
  ADCCON3_.24 := 1; // Control clock frequency is half of input clock

//* Select analog input for ADC modules, no presync trigger, not sync sampling */
  ADCTRGMODE_ := 0;

//* Select ADC input mode */
  ADCIMCON1_ := 0; // unsigned data format

//* Configure ADCGIRQENx */
  ADCGIRQEN1_ := 0; // No interrupts are used.
  ADCGIRQEN2_ := 0;

//* Configure ADCCSSx */
  ADCCSS1_ := 0; // Clear all bits
  ADCCSS2_ := 0;

//* Configure ADCCMPCONx */
  ADCCMPCON1_ := 0; // No digital comparators are used. Setting the ADCCMPCONx
  ADCCMPCON2_ := 0; // register to '0' ensures that the comparator is disabled.
  ADCCMPCON3_ := 0; // Other registers are ‘don't care’.
  ADCCMPCON4_ := 0;
  ADCCMPCON5_ := 0;
  ADCCMPCON6_ := 0;

//* Configure ADCFLTRx */
  ADCFLTR1_ := 0; // No oversampling filters are used.
  ADCFLTR2_ := 0;
  ADCFLTR3_ := 0;
  ADCFLTR4_ := 0;
  ADCFLTR5_ := 0;
  ADCFLTR6_ := 0;

//* Set up the trigger sources */
  ADCTRG1_ := 0;
  ADCTRG2_ := 0;
  ADCTRG1_.24 := 1; // Set AN24 (Class 2) to trigger from scan source
  ADCTRG1_.25 := 1; // Set AN25 (Class 2) to trigger from scan source

// AN40 (Class 3) always uses scan trigger source
//* Early interrupt */
  ADCEIEN1_ := 0; // No early interrupt
  ADCEIEN2_ := 0;

//* Turn the ADC on */
  ADCCON1_.15 := 1;

//* Wait for voltage reference to be stable */
  while ADCCON2_.31 = 0 do nop;  // Wait until the reference voltage is ready
// software block here and wdt reset...
end;
//* Wait for voltage reference to be stable */
while ADCCON2_.31 = 0 do nop; // Wait until the reference voltage is ready
// software block here and wdt reset...

Thank you.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ2048EFH100 ADC help

#2 Post by yo2lio » 14 Dec 2016 15:56

Mikroe team, any help from your side?
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PIC32MZ2048EFH100 ADC help

#3 Post by uros.cvetinovic » 14 Dec 2016 18:48

Hi,

Unfortunately, we still didn't support PIC32MZ EF series in our compilers, so we didn't test it, nor we have any examples for this.

PIC32MZ EF series will be supported in the next release so then you can expect library functions for ADC in our compilers for PIC32.

Best regards,

Uros

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ2048EFH100 ADC help

#4 Post by yo2lio » 14 Dec 2016 19:10

uros.cvetinovic wrote: Unfortunately, we still didn't support PIC32MZ EF series in our compilers, so we didn't test it, nor we have any examples for this.

PIC32MZ EF series will be supported in the next release so then you can expect library functions for ADC in our compilers for PIC32.
I know that MZ EF are not supported by compiler, but I thought maybe now working on new compiler and can give me any idea ...

I can't wait more 2-3 months for a new release... thanks anyway.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ2048EFH100 ADC help

#5 Post by yo2lio » 14 Dec 2016 19:31

BTW: I use PIC32MZ2048EFH100 in my application. I don't use FPU from MCU.

I use to compile the code, PIC32MZ2048ECH100 with some small modification in mlk file, I added the code protect bit...

In application I use:

DMA for MemCpy and Ethernet CRC calculation, works
Ethernet (my own library), works
TFTP Ethernet bootloader located in boot sector, works
Usart 1,2,3,4,5,6 with interrupts, mikroe library, works
I2C 1,2 and software I2C for I2C 3, mikroe library, works
SPI 2,3,4, mikroe library, works
Internal flash, mikroe library, works
External flash, M25P32, mikroe library, works

What missing from here, is the ADC routines, where I tried to use microchip app note... without success...
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

MicroMark
Posts: 181
Joined: 11 Feb 2011 17:22

Re: PIC32MZ2048EFH100 ADC help

#6 Post by MicroMark » 15 Dec 2016 16:43

Have you tried asking on the Microchip forum?

http://www.microchip.com/forums/

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PIC32MZ2048EFH100 ADC help

#7 Post by uros.cvetinovic » 16 Dec 2016 17:55

Hi Florin,

Can you please submit a ticket on our helpdesk on this subject?
http://helpdesk.mikroe.com/

I will try to find some suitable hardware and help you out as much as I can.

Best regards,

Uros

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

Re: PIC32MZ2048EFH100 ADC help, solved

#8 Post by yo2lio » 17 Dec 2016 15:40

Hi,

Solved!

I removed atomic declaration from declaration registers and works!
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Post Reply

Return to “mikroPascal PRO for PIC32 General”