Hi,
I'm struggling trying to get the analog input module on my dsPIC30F4011
properly configured. Eventually I need to be able to sample two channels
simultaneously at 100Hz, continuously. But right now I'd be very happy with
getting *anything* working.
The configuration code I have so far is posted below. I'm stuck on how to
calculate the ADCS & SAMC registers correctly. I've been trying to calculate
these for quite some time, but for some reason just can't get it right! I'm
running my PIC at 10MHz, with no PLL. If anyone could provide me with some
insight, on how to calculate ADCS and SAMC, I'd really appreciate it.
ADCON1bits.ADON = 0; // Turn OFF A/D module
// B4 (pin 6) - Accelerometer
ADPCFGbits.PCFG4 = 0; // Set pin B4 to analog mode
TRISBbits.TRISB4 = 1; // Set pin B4 as INPUT
ADCON1bits.FORM = 0; // Buffer output = Integer
ADCON1bits.ADSIDL = 1; // Stop module in idle mode
ADCON1bits.SIMSAM = 1; // Sample CH0 .. CH3 Simultaneously
ADCON1bits.ASAM = 1; // Auto sample after convert
ADCON1bits.SSRC = 7; // Internal counter ends sampling and starts
conversion (auto convert)
ADCON2bits.VCFG = 0; // Voltage reference is AVdd and AVss (internal)
ADCON2bits.CHPS = 2; // Converts CH0 .. CH3 (inputs are actually only
on 2 & 3)
ADCON2bits.ALTS = 0; // Use MUX A configuration
ADCON2bits.BUFM = 0; // Use single buffer, 16 word
ADCON3bits.ADRC = 0; // Use system clock
//ADCON3bits.ADCS = // Conversion clock. 4011 data sheet example
20-1
//ADCON3bits.SAMC = // Time between start of sample, and start of
conversion
ADCHSbits.CH123SA = 1; // Positive input for CH1 is AN3, CH2 is AN4,
CH3 is AN5
ADCHSbits.CH123NA = 0; // Negative input for CH1, CH2, and CH3 is Vref-
ADCSSLbits.CSSL4 = 1; // Include AN4 in scan
ADCON1bits.ADON = 1; // Turn ON A/D module
Thanks!
Nathan
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist