Using MAX7651 to realize ADC conversion

Abstract: This article provides the source code and functions for using the MAX7651 EV kit to implement analog-to-digital conversion. It is one of the three application routines provided by the MAX7651 evaluation board and can perform simple programming functions such as writing, compiling, and downloading.

Please also refer to: Configuring Keil µVision IDE parameters for the MAX7651 evaluation board. Use the serial downloader of the MAX7651 evaluation board to load the program into the flash memory. This article uses the 8051 compatible microcontroller MAX7651 to implement analog-to-digital conversion, and the program code is given. It includes some key write operations, compilation and program download steps, supports MAX7651EVKIT for analog-to-digital conversion, and can read the conversion results. The program uses the 12-bit integrated ADC inside the MAX7651.

The source code of this example is created using Keil DK-51 IDE. You need to download and install Keil DK-51 demo software to simplify the use of routines. The Keil program contains the basic library files of MAX7651. Next, you should download the µVision2® project file and source code: AN3083_uVision2_Project_Files.zip.

This example uses MAX7651EVKIT. Of course, Keil µVision® IDE simulator can also be used to demonstrate these source codes if necessary, without using MAX7651EVKIT. For software installation, please refer to the MAX7651EVKIT Quick Start User Manual, which provides detailed information about Keil software installation.

Note: The routine provided here is the public source code given by Maxim, which can be copied for free and modified according to the specific application.

C program description In order to effectively use this routine, you need to be familiar with C language programming. The program consists of three parts: "ADC Test FuncTIon" main program (main ()) and two calling sub-functions: convert_all_channels () and convert_channel (). The main program first initializes the registers of MAX7651 and provides some standard library functions. Then configure MAX7651 to communicate with the PC's standard serial port.

The main program main () calls two sub-functions. The function convert_all_channels () sequentially converts 8 ADC input channels; the function convert_channel () enables the user to select the conversion channel and return the ADC conversion result.

To start a conversion, simply call the function convert_all_channels () or convert_channel (). The function performs the conversion operation by writing the required conversion channel to the ADCON register of the MAX7651, and then terminates the conversion by looping through the ADCON register. After the conversion, return the conversion result to the calling function. The main program main () displays the result on the display through the serial port by calling the printf () function in stdio.h.
/ * ------------------------------------------------ ------------------------- ADC Test FuncTIon (main.c) Copyright: Maxim Integrated Products Target: MAX7651 Date: Feb 26, 2004 Author: Maxim Integrated Products DescripTIon: This program will convert 8 channels using the MAX7651 and send the results to Serial Port 0 ----------------------------- --------------------------------------------- * / #include // include MAX7651 register definiTIons #include // Standard I / O, Print () function. #Define NUMBER_OF_CHANNELS 8 // Convert 8 channels void convert_all_channels (int * buffer); // Function declaration int convert_channel (int adc_ch); // Function declaration void main (void) / / Begin Main () {int Adc_Results [NUMBER_OF_CHANNELS]; // Array to store conversion result int i; // for loop counter convert_all_channels (Adc_Results); // Convert all channels, Store results in Adc_Results #ifndef MONITOR51 // Setup Serial Port if not using Keil Monitor SCON = 0x50; // 9600 Baud, 8N1, Xon, Xoff TMOD | = 0x20; TH1 = 0xFA; TR1 = 1; TI = 1; PCON | = 0x80; #endif for (i = 0; i <NUMBER_OF_CHANNELS; i ++) // Display contents to Adc_Results {printf ("CH% d:% x", i, Adc_Results [i]); // print the hex} printf ("channel 0% x", convert_channel (0) ); // Convert a single channel and display printf ("channel 1% x", convert_channel (1)); printf ("channel 2% x", convert_channel (2)); printf ("channel 3% x", convert_channel (3)); printf ("channel 4% x", convert_channel (4)); printf ("chan nel 5% x ", convert_channel (5)); printf (" channel 6% x ", convert_channel (6)); printf (" channel 7% x ", convert_channel (7)); while (1); // End Program, Start infinite loop since there is no OS} / * ------------------------------------- ------------------------------------ Function: convert_all_channels Copyright: Maxim Integrated Products Target: MAX7651 Date: Feb 26, 2004 Author: Maxim Integrated Products Usage: The function will return 8 conversion results to an array. Parameters: p_buffer, pointer to an 8 location array stores the conversion results Return: Values ​​are returned to the calling function using the function parameters / * -------------------------------------------------- ----------------------- Setup ADC in the MAX7651 ---------------------- -------------------------------------------------- -* / sfr ADCON = 0xC5; // Define address of MAX7651 ADCON sfr ADDAT1 = 0xC3; // Define address of MAX7651 ADDAT1 (8MSBs) sfr ADDAT0 = 0xC2; // Define address of MAX7651 ADDAT0 (4LSBs) void convert _all_channels (int * buffer); ------------------------------------------- ------------------------------- * / #define NUMBER_OF_CHANNELS 8 void convert_all_channels (int * p_buffer) // pointer Buffer to return {int adc_ch; int conv_val; / * ----------------------------------------- ------ Convert all ADC channels ---------------------------------------- ------- * / for (adc_ch = 0; adc_ch <NUMBER_OF_CHANNELS; adc_ch ++) // for ADC channels 1 to 7 {/ * ------------------ ----------------------------- Start a conversion and wait for it to complete. ----------- ------------------------------------ * / ADCON = adc_ch; // Start conversion and select channel while ((ADCON & 0x80) == 0); // wait for conversion to complete conv_val = (ADDAT0 >> 4) | (ADDAT1 << 4); // Format the data in 12 bit format * (p_buffer + adc_ch) = conv_val; // Write result back to calling function} // End For} // End function convert_all_channels () / * ------------------------- ------------------------------------------------ Function: convert_ch annel Copyright: Maxim Integrated Products Target: MAX7651 Date: Feb 26, 2004 Author: Maxim Integrated Products Usage: The function will convert and return the result of a Channel. Parameters: adc_ch, Select ADC channel to be converted. Channels 0-7 = single ended channel 0-7. Channels 8-11 = differential channel pairs {CH0,1}, {CH2,3}, {CH4,5}, {CH6,7} Channel 12 = differential reference measurement {REF +, REF-} Return: Function returns Integer with the conversion result Function Declaration: int convert_channel (int adc_ch); ------------------------------- ------------------------------------------- * / / * --- -------------------------------------------------- -------------------- Setup ADC in the MAX7651 ------------------------- ------------------------------------------------- * / sfr ADCON = 0xC5; // Define address of MAX7651 ADCON sfr ADDAT1 = 0xC3; // Define address of MAX7651 ADDAT1 (8MSBs) sfr ADDAT0 = 0xC2; // Define address of MAX7651 ADDAT0 (4LSBs) int convert_channel (int adc_ch) { int conv_val; if (ADCON <0 || ADCON> 12) {// Check for valid channel return (-2048); // Using -FS for the error code} ADCON = adc_ch; // Select channel and Start conversion while (( ADCON & 0x80) == 0); // Wait for the conversion to complete conv_val = (ADDAT0 >> 4) | (ADDAT1 << 4); // Format the data in 12 bit format return (conv_val); // Return result back to calling function} // End function convert_chan

Traditionally, stabilizer is heavy and too big to take. Fashion stabilizer can solve all these problems. It`s small and light.

handheld gimbal
 

Fashion gimbal stabilizer are designed as pocket size, portable and easy to take. You can carry it as easy as smartphone!

 various accessories

Wewow focusing on handheld stabilizer is a technology company which does R & D independently. With Wenpod series product released, the company achieved the industry's praise and quickly became the leader of the smart stabilizer industry.
Our service

1. Reply to you within 24 hours.

2. Already sample: within 1-2days.

3. Shipping date: within 24 hours once get the payment.

4. 12 months warranty.

5. After-sales service, solve within 3 working dates.

If you have any questions, please contact with us directly.

Wewow appreciates domestic and international business relationship!

Fashion Stabilizer

Fashion Stabilizer,Fashion Stabilize Regulator,Professional Fashion Stabilizer,Voltage Stabilizer

GUANGZHOU WEWOW ELECTRONIC CO., LTD. , https://www.stabilizers.pl