0
\$\begingroup\$

I'm trying to read in a value using a few analog pins on a PIC32 (MX775F512H), including RB12-- part of the JTAG pins on the device. The device the board is reading from works great, but the board itself can't read the pin in.

I'm able to set the pin high using this code:

    DDPCONbits.JTAGEN = 0;
    TRISBbits.TRISB12 = 1;
    AD1PCFGbits.PCFG12 = 0;

I'm intending there to disable JTAG and then write all the pins to high. RB0 through RB7 work as expected, but RB8 through RB15 float at a few millivolts.

How can I get my expected functionality out of these pins? Any searching on here and on Google hasn't led to much, and the documentation isn't clear on what to do other than to disable JTAG.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ LATB = 0xFF only sets bits 0-7 high, you need LATB = 0xFFFF to set bits 0-15 high. \$\endgroup\$
    – tcrosley
    Commented Apr 29, 2013 at 7:11
  • \$\begingroup\$ Gotcha. I can now turn on the pins using this code: DDPCONbits.JTAGEN = 0; TRISBbits.TRISB12 = 1; AD1PCFGbits.PCFG12 = 0; \$\endgroup\$
    – alextoombs
    Commented Apr 29, 2013 at 23:46

1 Answer 1

1
\$\begingroup\$

So I had to re-read through the ADC document and ask for some help, but I think I've found the way.

My previous iteration used a method of defining certain parameters, but I ended up just doing direct assignment to the registers eventually.

For anyone else with the same problem, the following is my code:

Configuration for analog:

DDPCONbits.JTAGEN = 0;
TRISB = 0x1111;

IFS1CLR = 2; //clear ADC conversion interrupt
IEC1SET = 2; //enable ADC interrupt
AD1PCFG = 0x0000; //Configure all input pins to Analog
AD1CON1 = 0b00000000000000001000000011100110; //Configure Sample clock source
AD1CON2 = 0b0000010000100000; //Configure ADC voltage reference

AD1CON3 = 0x0000; //Configure ADC conversion clock
AD1CON3bits.SAMC = 0b00001;    //auto sample at 2TAD
AD1CON3bits.ADCS = 0b00000001; //TAD = 4TPB
AD1CHS = 0x00000000; //Configure input channels- CH0+ input,

AD1CON2bits.CSCNA=1;
AD1CSSL = 0b0001001111111100;
AD1CON1SET = 0x8000; //Turn on the ADC module

Then, for acquisition, I call this method within an ISR on a timer of ~half a second:

void getAnalog() {
while( ! IFS1bits.AD1IF); //wait until buffers contain new samples
    AD1CON1bits.ASAM = 0;     //stop automatic sampling (shut down ADC basically)

    vt1 = ADC1BUF0*.003185;
    vt2 = ADC1BUF1*.003185;
    vt3 = ADC1BUF2*.003185;
    vt4 = ADC1BUF3*.003185;
    mosVolt = ADC1BUF4*.003185;
    Battery_volt = ADC1BUF5*.003185;
    vt5 = ADC1BUF6*.006125;
    vt6 = ADC1BUF7*.006125;
    Csensor_volt = ADC1BUF8*.006125;


    IFS1bits.AD1IF = 0;
    AD1CON1bits.ASAM = 1;  //restart ADC and sampling
}

Variable names and scalers on each may vary.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.