S3C2440 AD Converter

Publisher:SparklingSunLatest update time:2016-04-18 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
       The 10-bit CMOS ADC (Analog/Digital Converter) is an 8-channel analog input recirculation type device. It converts the analog input signal into a 10-bit binary

The A/D converter supports on-chip sample-and-hold functions and power-down
mode operation.

 

The touch screen will be in the next article. ADC conversion is relatively simple. Here is a code

[cpp]  view plain  copy
 
  1. #include "2440addr.h"  
  2. #include "2440lib.h"  
  3. #include "def.h"  
  4.   
  5. //================================================ =====================  
  6. // Name: ADC_Select(int ch, U32 preScaler)  
  7. //Function: Select the conversion channel and set the converter pre-scaling value  
  8. //Parameters: ch: conversion channel preScaler: pre-scaling value  
  9. //Return value: None  
  10. //================================================ =======================  
  11.   
  12. void ADC_Select(int ch, U32 preScaler)  
  13. {  
  14.     rADCCON=(1<<14)|(preScaler<<6)|(ch<<3);     
  15. }  
  16. //================================================ =======================  
  17. // Name: AD_ENABLE()  
  18. //Function: Start AD conversion by setting enable  
  19. //Parameters: None  
  20. //Return value: converted value  
  21. //================================================ =======================  
  22. int AD_ENABLE(void)  
  23. {  
  24.     int i;  
  25.     int val=0;  
  26.       
  27.     for(i=0;i<16;i++)  
  28.     {  
  29.         rADCCON |= 0x1; // Enable ADC conversion  
  30.           
  31.         while(rADCCON & 0x1); // Check if ADC conversion is enabled and cleared  
  32.           
  33.         while(!(rADCCON &0x8000)); //Wait for the conversion to end  
  34.           
  35.         val +=(rADCDAT0 & 0x3ff); //Read the value converted by ADC  
  36.           
  37.     }  
  38.     val = val/16; //Calculate ADC conversion value  
  39.       
  40.     return val;  
  41. }  
  42.   
  43. //================================================ =======================  
  44. // Name: AD_READ()  
  45. //Function: Start AD conversion by reading controller  
  46. //Parameters: None  
  47. //Return value: converted value  
  48. //================================================ =======================  
  49. int AD_READ(void)  
  50. {  
  51.     int i;  
  52.     int temp,val=0;  
  53.       
  54.     rADCCON |= 0x2; //ADC conversion is started by reading operation  
  55.     temp = rADCDAT0 & 0x3ff; //Start ADC  
  56.       
  57.     for(i=0;i<16;i++)  
  58.     {  
  59.         rADCCON |= 0x1; // Enable ADC conversion  
  60.           
  61.         while(rADCCON & 0x1); // Check if ADC conversion is enabled and cleared  
  62.           
  63.         while(!(rADCCON &0x8000)); //Wait for the conversion to end  
  64.           
  65.         val +=(rADCDAT0 & 0x3ff); //Read the value converted by ADC  
  66.           
  67.     }  
  68.     val = val>>4; //Calculate ADC conversion value  
  69.       
  70.     return val;  
  71. }  
  72.       
  73.   
  74. void Main(void)  
  75. {  
  76.     int temp_val;  
  77.     U8 mode;  
  78.     SelectFclk(2); //Set the system clock to 400M       
  79.     ChangeClockDivider(2, 1); //Set the frequency division to 1:4:8  
  80.     CalcBusClk(); //Calculate bus frequency  
  81.       
  82.     rGPHCON &=~((3<<4)|(3<<6));     
  83.     rGPHCON |=(2<<4)|(2<<6); //GPH2--TXD[0];GPH3--RXD[0]     
  84.         
  85.     rGPHUP=0x00; //Enable pull-up function  
  86.           
  87.     Uart_Init(0,115200);  
  88.     Uart_Select(0);  
  89.       
  90.     while(1)  
  91.     {  
  92.         ADC_Select(2, 49);  
  93.         Uart_Printf("Select ADC Mode: 1.Enable 2.Read\n");  
  94.         mode=Uart_Getch();  
  95.         Uart_Printf("\n%c\n\n", mode);  
  96.       
  97.         if (mode != '1' && mode != '2')  
  98.         {  
  99.             Uart_Printf("you select wrong model!\n");  
  100.             return;  
  101.         }  
  102.       
  103.         switch(mode)  
  104.         {  
  105.             case '1':  
  106.                 Uart_Printf("ADC Enable-Convert Mode\n");  
  107.                 temp_val=AD_ENABLE();  
  108.                 break;  
  109.             case '2':  
  110.                 Uart_Printf("ADC Read-Convert Mode\n");  
  111.                 temp_val=AD_READ();  
  112.                 break;  
  113.         }  
  114.         Uart_Printf("ADC val = %d\n", temp_val); //Send to the serial port for display  
  115.     }  
  116. }  
  117.               


 

Keywords:S3C2440 Reference address:S3C2440 AD Converter

Previous article:S3C2440 LCD Character Display
Next article:S3C2440 drives 4.3-inch TFT screen program

Recommended ReadingLatest update time:2024-11-15 16:21

About S3C2440 u-boot supports nand hw ecc
https://blog.csdn.net/hurry_liu/article/details/8741565 ---This article (article 1) explains it in detail. http://www.xuebuyuan.com/zh-hant/916448.html ----This article (Article 2) says something similar. The descriptions of Article 1 and Article 2 are the same, but the code content is different. At first, I saw arti
[Microcontroller]
About S3C2440 u-boot supports nand hw ecc
s3c2440 bare metal-I2c programming-3.i2c program framework
1. Functions of iiC devices Obviously, the IIC controller provides the ability to transmit data. As for the meaning of the data, the IIC controller does not know. The meaning of the data is an external i2c slave device. We need to read the chip manual to know what kind of data the IIC controller should send. data. The
[Microcontroller]
s3c2440 bare metal-I2c programming-3.i2c program framework
s3c2440 startup code study notes
Startup code: Set the interrupt vector in the following order: RESET UDEF SWI PREFETCHUDEF DATAABT NOP //Reserved address IRQ FIQ A total of seven interrupt vectors After the machine is powered on, it executes instructions from address 0x00000000 and initial
[Microcontroller]
s3c2440 migration u-boot-2016.03 Part 5 supports dm9000 recognition
  1. By looking at /drivers/net/Makefile, I found that if I want to compile, I need to add #define CONFIG_DRIVER_DM9000 #define CONFIG_DM9000_BASE 0x20000000 #define DM9000_IO CONFIG_DM9000_BASE #define DM9000_DATA (CONFIG_DM) in /include/configs/smdk2440.h 9000_BASE+4) #define CONFIG_NETMASK 255.255.255.0 #define CO
[Microcontroller]
s3c2440 migration u-boot-2016.03 Part 5 supports dm9000 recognition
s3c2440 NAND and NOR boot methods detailed explanation + personal verification
1: Allocation of address space 1: s3c2440 is 32-bit, so it can address 4GB of space. Memory (SDRAM), ports (special registers), and ROM are all mapped to the same 4G space. 2: Development boards generally use SDRAM as memory flash (nor, nand) as ROM. Among them, nand flash has no address line, and at least one page (5
[Microcontroller]
s3c2440 NAND and NOR boot methods detailed explanation + personal verification
Initialization of application execution environment in S3C2440 startup code
1. Basic knowledge           The source file (.c or .s) we wrote is compiled by the ARM compiler to generate an ELF format target file (with the suffix .o). The target file is connected by the ARM connector to generate an ELF format image file (with the suffix .axf). At this time, the image file also contains some d
[Microcontroller]
Initialization of application execution environment in S3C2440 startup code
Application of s3c2440 timer interrupt
In the previous articles, whenever the program needs a delay, we use loop statements to implement it. The delay of this method is simple, but not very accurate, that is, it is impossible to get an exact delay of a period of time. Therefore, when an accurate delay is required, this method cannot be used. It is generally
[Microcontroller]
S3C2440 Linux driver transplantation——SD card driver
Development board: TQ2440 Kernel: Linux 2.6.32 PC OS: Ubuntu 11.04 This article will briefly introduce the porting of SD card driver. 1. Add board information Open arch/arm/mach-s3c2440/mach-smdk2440.c. Add the following structure: /* Added by Yan Jun for SD/MMC driver */   /*********************************
[Microcontroller]
S3C2440 Linux driver transplantation——SD card driver
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号