AD resistance conversion --- those years we played with mini2440 (arm9) bare metal

Publisher:PeacefulWarriorLatest update time:2024-08-09 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ADC driver design

ADC: Analog-to-digital converter.

A device that converts analog signals into digital signals;

DAC: Digital to Analog Converter.

A device that converts digital signals into analog signals.

Steps to convert analog signal into digital signal:

1. Get the value;

2. Quantification;

3. Coding;

S3C2440ADC

The S3C2440 chip has 8 A/D conversion channels AIN0~AIN7, but there is only one converter.

The conversion precision is 10 bits, so the minimum converted value will be close to 0 and the maximum converted value will be close to 1024.


The maximum conversion rate can reach 500KSPS (5000 thousand samples per second) at a conversion clock of 2.5MHZ.

In common designs, such as the mini2440 development board, AIN4, AIN5, AIN6, and AIN7 are generally used as the YM, YP, XM, and XP channels of four-wire resistive touch; the remaining AIN0~3 are brought out, of which AIN0 is directly connected to an adjustable resistor W1.

Teacher: AIN4, AIN5, AIN6, and AIN7 are for touch screens;

AIN0 is used for adjustable resistance

(So ​​that the voltage can be converted as an analog signal)

ADC driving process: 1. Initialization à 2. Start à 3. Conversion end à 4. Read conversion value


1. ADC initialization

A. Select the conversion channel - B. Set the conversion frequency

How to determine whether the conversion has started? Use a while loop to check whether ENABLE_START has become 0

How to determine whether the conversion is complete? Keep checking whether ECFLG is 1

Read conversion value

#define GLOBAL_CLK 1

#include

#include

#include "def.h"

#include "option.h"

#include "2440addr.h"

#include "2440lib.h"

#include "2440slib.h"

#include "mmu.h"

#include "profile.h"

#include "memtest.h"

#define ADC_FREQ 2500000

//#define ADC_FREQ 1250000

volatile U32 preScaler;

void adc_init(void);

int ReadAdc(int channel);

static void cal_cpu_bus_clk(void);

void Set_Clk(void);

void beep_init(void);

void beep_run(void);

/******************************************************

Function name: delay

Parameter : times

Description: Delay function

Return : void

Argument : void

Autor & date : Daniel

*************************************************** /

void delay(int times)

{

int i,j;

for(i=0;i

for(j=0;j<400;j++);

}

/******************************************************

Function name: Main

Parameter : void

Description: Main function

Return : void

Argument : void

Autor & date : Daniel

*************************************************** /

void Main(void)

{

int a0=0,tmp;

int Scom=0;

Set_Clk();

Uart_Init(0,115200);

Uart_Select(Scom);

adc_init();

while(1)

{

a0=ReadAdc(0);

Uart_Printf( "AIN0: %04dn", a0);

delay(1000);

}

}

/******************************************************

Function name: adc_init()

Parameter : int channel

Description: adc initialization

Return : void

Argument : void

Autor & date : Daniel

*************************************************** /

void adc_init(void)

{

int channel=0; //AIN0, corresponding to the adjustable resistor W1 on the development board

preScaler = ADC_FREQ;

Uart_Printf("ADC conv,freq. = %dHzn",preScaler);

preScaler = 50000000/ADC_FREQ - 1; //PCLK=50M We want to get ADC_FREQ=2500000

Uart_Printf("PRSCVL=PCLK/ADC_FREQ - 1=%dn",preScaler);

/*AD conversion frequency setting, maximum frequency is 2.5MHz*/

rADCCON = (1<<14)|(preScaler<<6)|(channel<<3); //setup channel 1<<14 enable prescaler (preScaler<<6) prescaler value channel<<3 analog channel selection

delay(1000);

}

/******************************************************

Function name: ReadAdc(int channel)

Parameter : int channel

Description: Get the value after AD conversion

Return : int

Argument : void

Autor & date : Daniel

*************************************************** /

int ReadAdc(int channel)

{

/*Start AD conversion*/

rADCCON |= 0x01; //start ADC

while(rADCCON & 0x1); //check if Enable_start is low

while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high to determine whether the conversion is finished

return ( (int)rADCDAT0 & 0x3ff ); //Read the converted value

}

/******************************************************

Function name: Set_Clk()

Parameter : void

Description: Set the CPU clock frequency

Return : void

Argument : void

Autor & date : Daniel

*************************************************** /

void Set_Clk(void)

{

int i;

U8 key;

U32 mpll_val = 0 ;

i = 2; //don't use 100M!

//boot_params.cpu_clk.val = 3;

switch ( i ) {

case 0: //200

key = 12;

mpll_val = (92<<12)|(4<<4)|(1);

break;

case 1: //300

key = 13;

mpll_val = (67<<12)|(1<<4)|(1);

break;

case 2: //400

key = 14;

mpll_val = (92<<12)|(1<<4)|(1);

break;

case 3: //440!!!

key = 14;

mpll_val = (102<<12)|(1<<4)|(1);

break;

default:

key = 14;

mpll_val = (92<<12)|(1<<4)|(1);

break;

}

//init FCLK=400M, so change MPLL first

ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); //set the register--rMPLLCON

ChangeClockDivider(key, 12); //the result of rCLKDIVN [0:1:0:1] 3-0 bit

cal_cpu_bus_clk(); //HCLK=100M PCLK=50M

}

/******************************************************

Function name: cal_cpu_bus_clk

Parameter : void

Description: Set the frequency of PCLKHCLKFCLK

Return : void

Argument : void

Autor & date : Daniel

*************************************************** /

static void cal_cpu_bus_clk(void)

{

static U32 cpu_freq;

static U32 UPLL;

U32 val;

U8 m, p, s;

val = rMPLLCON;

m = (val>>12)&0xff;

p = (val>>4)&0x3f;

s = val&3;

//(m+8)*FIN*2 Do not exceed 32 digits!

FCLK = ((m+8)*(FIN/100)*2)/((p+2)*(1<

val = rCLKDIVN;

m = (val>>1)&3;

p = val&1;

val = rCAMDIVN;

s = val>>8;

switch (m) {

case 0:

HCLK = FCLK;

break;

case 1:

HCLK = FCLK>>1;

break;

case 2:

if(s&2)

HCLK = FCLK>>3;

else

HCLK = FCLK>>2;

break;

case 3:

if(s&1)

HCLK = FCLK/6;

else

HCLK = FCLK/3;

break;

}

if(p)

PCLK = HCLK>>1;

else

PCLK = HCLK;

if(s&0x10)

cpu_freq = HCLK;

else

cpu_freq = FCLK;

val = rUPLLCON;

m = (val>>12)&0xff;

p = (val>>4)&0x3f;

s = val&3;

UPLL = ((m+8)*FIN)/((p+2)*(1<

UCLK = (rCLKDIVN&8)?(UPLL>>1):UPLL;

}


Reference address:AD resistance conversion --- those years we played with mini2440 (arm9) bare metal

Previous article:s3c2440 bare metal development and debugging environment (MDK4.72, Jlink v8, mini2440)
Next article:Porting openssh to embedded ARM development board

Recommended ReadingLatest update time:2024-11-16 09:37

mini2440 mounts linux folder via nfs
linux 1. Install nfs server sudo apt-get install nfs-kernel-server 2. Modify the configuration file /etc/exports vim /etc/exports Add in the last line /home/stu/nfs *(rw,sync,no_root_squash,no_subtree_check) Where /home/stu/nfs is the directory you want to mount 3. Port Mapping sudo service rpcbind restart
[Microcontroller]
BOA server transplantation based on mini2440
Win7 system development board: mini2440 Virtual machine: Ubuntu 12.04 Preparation: Make sure the host and development board can communicate normally, that is, they can ping each other. For specific operation, please refer to my previous essay. 1. First download the boa source code from http://www.boa.org/ and co
[Microcontroller]
BOA server transplantation based on mini2440
Linux kernel configuration support for USB disk (for mini2440)
Configuring USB Because the USB flash drive uses SCSI commands, we first add SCSI support. In the Device Drivers menu, select SCSI device support, press Enter to enter the menu that appears, press the spacebar to select the option – SCSI device support, then enter and select SCSI disk support, return to the Device Dri
[Microcontroller]
Linux kernel configuration support for USB disk (for mini2440)
Mini2440 Burning Linux System
According to the Guoembedded course, I failed to use dnw software to burn the system under Linux system, and a white screen appeared when I started the computer. Programming steps: 1. Keep the S2 switch turned to the nor flash switch, connect the serial port cable, open the serial port tool to observe the operatio
[Microcontroller]
Mini2440 Burning Linux System
How to configure NORFASH when using JLINK to download uboot to MINI2440?
Note: The following settings are applicable to downloading an empty board (i.e. no program in the chip) using JLINK, and are downloaded to NORFALSH. 1.Target Interface (as shown below): 2.CPU settings: CPU settings include 3 parts: 2.1 Select CPU (S3C2440A is ARM920T core)   2.2 Set RAM address and size (S3
[Microcontroller]
How to configure NORFASH when using JLINK to download uboot to MINI2440?
uboot ported to mini2440
The goal of this article is to complete the porting of mini2440 so that uboot can run normally on mini2440. 1. Establish the development environment of mini2440. uboot supports many CPUs, including mini2440. But the version I chose is relatively old, 2009.08. So there is no mini2440 related files in it. Therefore,
[Microcontroller]
uboot ported to mini2440
ARM9 Learning 3-Debugging the first ARM assembly program
Debugging your first ARM assembly program 1. Double-click the KEIL uVision4 icon to open the RVMDK uVision4 integrated development environment. 2. Create a new project through the menu "projectnew uvision project...", select the storage location and project file name "Test001", and click the "Save button". 3.CPU s
[Microcontroller]
ARM9 Learning 3-Debugging the first ARM assembly program
Mini2440 bare metal test - RTC alarm interrupt, beat interrupt
Environment Construction     Hardware environment: J-link v8, mini2440, J-link adapter board, serial port to USB cable     Software environment: windows7 (32-bit), development board uboot (NandFlash), J-link driver (J-Link ARM V4.10i), SecureCRT, ADS1.2     The AXD settings in ADS are: load JlinkRDI.dll+Options-
[Microcontroller]
Mini2440 bare metal test - RTC alarm interrupt, beat interrupt
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号