View previous topic :: View next topic |
Author |
Message |
baghrir
Joined: 28 Dec 2004 Posts: 2
|
external adc problem |
Posted: Sun Apr 24, 2005 4:37 am |
|
|
Hello,
I want to use a PIC16F877 with an external adc (ADC700) using the PSP mode. I don't know how to use this device. do the microcontroller start the conversion automatically at the PSP interrupt, or I must do it by programming. My English is very bad, but.... Thank you very much. |
|
![](templates/subSilver/images/spacer.gif) |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sun Apr 24, 2005 8:19 am |
|
|
1. I assume your difficulty with the ADC700 is understanding the English in the data sheet?
2. I also assume that you are using the ADC700 for some of its special features and no other device meets your needs? (Maybe an I2C or some other part that already has a CCS driver written?) Have you checked on the availability, it appears that it may be hard to find?
First quick reading of the data sheet indicates that you will need to write a driver for it.
Quote: |
A conversion is started by asserting CS and WR Low.
|
The datasheet appears to be pretty clear about the requirements. You should find someone that can help you with the translation to your native language.
Good Luck |
|
![](templates/subSilver/images/spacer.gif) |
bfemmel
Joined: 18 Jul 2004 Posts: 40 Location: San Carlos, CA.
|
ADC Setup |
Posted: Tue Apr 26, 2005 11:40 am |
|
|
baghrir,
The very fancy ADC you are using has a serial output on it so you could try to use that instead of the PSP port but if not here is a method I have used for parallel interfacing.
I just attach the ADC output bits to a port on the PIC. I am using an 18F6520 and I selected port F but you can use anything you want. then you need to use three other pins to control the ADC, one is to get the ADC to start a conversion, one to sense the conversion is done and one to select either high or low byte. See the code below as to how I control the chip. I use an LTC1605 which may operate somwhat differently than your ADC700 but you'll get the idea and be able to adapt the routine.
This particular algorithim is for oversampling. Usually we look at anywhere between 16 and 64 consecutive samples to filter out gaussian noise but the same routine will work for one ample. The routine is passed the number of samples to send back so the return value is a signed 32 bit integer as it will contain the sum of multiple 16 bit values.
Please note the disabling of global interrupts around the conversion start output commands. This is because many ADC converters will throw fits if you hold that line down too long and then give you bogus readings so it is important that you not get interrupted in that short time it takes to toggle the bit.
Code: |
#device PIC18F6520
#define ADC_BUSY PIN_B0 // pin on ADC that shows conversion is complete
#define ADC_BYTE PIN_E7 // pin on ADC that selects high or low byte.
#define ADC_RC PIN_C2 // pin on ADC to start conversion
#define ADC_PORT input_f() // port hooks to 8 bit wide data on ADC
signed int32 GetADC32(unsigned int8 n_samples) {
unsigned int8 i; // loop counter
unsigned int8 ADC_LSB; // lower byte of reading
unsigned int8 ADC_MSB; // upper byte of reading
signed int32 sumValue; // sum of all the readings taken in one pass of the GetADC32 routine.
disable_interrupts(global); // Disable interrupts so that the R/C is not low for an extended time
output_low(ADC_RC); // Start conversion before anything else to use the setup time
output_high (ADC_RC); // Toggling the bit starts the external A to D
enable_interrupts(global); // Turn interrupts back on after R/C is raised
sumValue = 0; // Clear the sumValue
for (i=0; i < n_samples; i++) { // Take as many samples as calling routine requested
while (!input(ADC_BUSY)); // Wait while conversion is in progress (max 8uS)
// Since PIC is reading with an 8 bit bus we need to shift the data
output_low(ADC_BYTE); // to read both bytes, so start by putting low byte in place to read
ADC_LSB = ADC_PORT; // Read low byte
output_high (ADC_BYTE); // Put high byte in place to read
ADC_MSB = ADC_PORT; // Read High byte
disable_interrupts(global); // Disable interrupts so that the R/C is not low for an extended time
output_low(ADC_RC); // Start conversion before anything else to use the setup time
output_high (ADC_RC); // Toggling the bit starts the external A to D
enable_interrupts(global); // Turn interrupts back on after R/C is raised
sumValue += (signed int32) ( (signed int16) MAKE16(ADC_MSB,ADC_LSB) ); // Add the recent value to the sum
} /* end for loop */
return(sumValue); // return the sum of values
} /* end of GetADC() */
|
Good Luck
- Bruce |
|
![](templates/subSilver/images/spacer.gif) |
baghrir
Joined: 28 Dec 2004 Posts: 2
|
|
Posted: Fri Sep 23, 2005 11:28 am |
|
|
Good day to all members,
I'm sory, I did a long time to reply
Thank you very much for your help
Regard
Baghrir |
|
![](templates/subSilver/images/spacer.gif) |
|