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;
while ADCCON2_.31 = 0 do nop; // Wait until the reference voltage is ready
// software block here and wdt reset...
Thank you.