Hi,
Would be very thankful if someone could help me out with this.
I am working on a small project which uses a PIC32MX534F064H MCU, I am trying to make the ADC read a voltage level on one of the Analog pins, but haven't been able to make it work.
My reference is the Datasheet for the MCU in question Datasheet.
I been trough the Datasheet multiple times but I am missing something and don't know what.
I have set up the ADC to Auto convert Mode and in the program code I am comparing the ADC1BUF0 against a value of (Int 500) to turn an LED on, this is just to verify that the ADC Setup is working, but so far no success.
Below is the code I'm loading in to the MCU:
Thanks in Advance
Marvin
Would be very thankful if someone could help me out with this.
I am working on a small project which uses a PIC32MX534F064H MCU, I am trying to make the ADC read a voltage level on one of the Analog pins, but haven't been able to make it work.
My reference is the Datasheet for the MCU in question Datasheet.
I been trough the Datasheet multiple times but I am missing something and don't know what.
I have set up the ADC to Auto convert Mode and in the program code I am comparing the ADC1BUF0 against a value of (Int 500) to turn an LED on, this is just to verify that the ADC Setup is working, but so far no success.
Below is the code I'm loading in to the MCU:
Code:
// FUSE SETTINGS
// DEVCFG3
#pragma config USERID = 0xFFFF // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config FSRSSEL = PRIORITY_7 // SRS Select (SRS Priority 7)
#pragma config FCANIO = ON // CAN I/O Pin Select (Default CAN I/O)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled by Port Function)
// DEVCFG2
#pragma config FPLLIDIV = DIV_12 // PLL Input Divider (12x Divider)
#pragma config FPLLMUL = MUL_24 // PLL Multiplier (24x Multiplier)
#pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_256 // System PLL Output Clock Divider (PLL Divide by 256)
// DEVCFG1
#pragma config FNOSC = PRI // Oscillator Selection Bits (Primary Osc (XT,HS,EC))
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = OFF // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = EC // Primary Oscillator Configuration (External clock mode)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/8)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (ICE EMUC2/EMUD2 pins shared with PGC2/PGD2)
#pragma config PWP = OFF // Program Flash Write Protect (Disable)
#pragma config BWP = OFF // Boot Flash Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
// ADC Settings:
TRISB = 0x3000; //0011000000000000;
AD1CHS = 0xD0000; //00000000000011010000000000000000;
AD1CON1 = 0xE4; //0000000011100100
AD1CON2 = 0x0; //0000000000000000
AD1CON3 = 0x8200; //1000001000000000
AD1CON1 = 0x80E4; //1000000011100100
//LED Settings
TRISF = 0; //Data Direction Register (Tri State, Switch) "0 for Output" "1 For Input"
while (1)
{
if (ADC1BUF0 >= 50) {
LATF = 15; //Latch Register
}
else {
LATF = 0; //Latch Register
}
return (EXIT_SUCCESS);
}
}
Thanks in Advance
Marvin