1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

7 chapter 7 ADC module

17 107 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 17
Dung lượng 0,92 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

A/D conversion sequence Step1: Configure the A/D module • configure the port pins as analogue inputs, voltage reference, and digital I/O pins, • select A/D converter input channel, • se

Trang 1

CHAPTER 5

ADC ANALOG DIGITAL CONVERTER

Dr Vo Tuong Quan

Trang 2

What is ADC?

•A/D (Analogue-to-Digital) converter is a "mixed signal" circuit which performs digitization of the external analogue signals

•There are 8 bits, 10 bits and 12 bits ADC in PIC family.

Functional

block diagram

of the 12-bit

A/D converter

of the

dsPIC30F4013

device

Trang 3

A/D conversion sequence

Step1: Configure the A/D module

configure the port pins as analogue inputs, voltage reference, and digital I/O pins,

select A/D converter input channel,

select A/D conversion clock,

select A/D conversion trigger source,

turn on A/D module;

Step 2: Configure A/D interrupt (if required)

clear ADIF bit (IFS0,11>),

select A/D interrupt priority,

set ADIE bit (IEC0<11>);

Step 3: Start sampling

Step 4: Wait the required acquisition time;

Step 5: Trigger acquisition end, start conversion;

Step 6: Trigger acquisition end, start conversion;

Step 7: Wait for A/D to complete, by either

waiting for the A/D interrupt, or

waiting for the DONE bit to get set;

Trang 4

A/D converter configuration

1 - Select voltage reference – This process is performed by

setting the control bit VCFG<2:0> (ADCON2<15:13>)

2 - Select the A/D conversion clock - The A/D conversion

period TAD , generated by a 6-bit counter, is selected by the control bits ADCS<5:0> (ADCON3<5:0>) Period TAD

is defined by the formula:

3 - Selection of analogue inputs - The control bits ADCHS

determine which analogue inputs are selected for each sample

Trang 5

A/D converter configuration

4 - Configuring analogue port pins - The ADPCFG register

specifies the input condition of device pins used as analogue inputs

5 - Enabling the A/D converter module – When the ADON

bit (ADCON1<15>) is set, the module is in active mode and

is fully powered and functional

Manual start of the sampling process – Setting the SAMP

bit (ADCON1<1>)

Automatic start of the sampling process – Setting the

ASAM bit (ADCON1<2>)

Trang 6

A/D Pins on MCU

Trang 7

Example 1: Manual sample start and a manual conversion

start The result of the A/D conversion is sent to the output

of port D.

{device = dsPIC30F6014A

Clock=10MHz}

program Timertest1;

TRISB := $FFFF; //Port B is input

TRISD := 0; //Port D is output (for ADC results)

ADPCFG := $FBFF; //10th channel is sampled and coverted

ADCON1 := $0000; //ADC off, output_format=INTEGER

begin //Manual start of convesion

//Manual start of sampling

ADCHS := $000A; //Connect RB10 on AN10 as CH0 input

ADCSSL := 0; //No scan

ADCON3 := $1003; //ADCS=3 (min TAD for 10MHz is 3*TCY=300ns)

ADCON2 := 0; //Interrupt upon completion of one sample/convert

ADCON1.15 := 1; //ADC on

Trang 8

while TRUE do

begin

ADCON1.1:=1; //Start sampling (SAMP=1)

Delay_ms(100); //Wait for 100ms (sampling )

ADCON1.1:=0; //Clear SAMP bit (trigger conversion)

while ADCON1.0 = 0 do nop; //Wait for DONE bit in ADCON1

LATD := ADCBUF0; //Output result on port D

end;

end.

Example 1: (Cont’d)

Trang 9

Example 2: An automatic sample start and a manual conversion start The result of the conversion is sent to the output of port D.

{device = dsPIC30F6014A

Clock=10MHz}

program Timertest2;

begin

TRISB := $FFFF; //Port B is input

TRISD := 0; //Port D is output (for ADC results)

ADPCFG := $FBFF; //10th channel is sampled and coverted

ADCON1 := $0004; //ADC off, output_format=INTEGER

//Manual start of convesion //Automatic start of sampling after coversion

ADCHS := $000A; //Connect RB10 on AN10 as CH0 input

ADCSSL := 0; //No scan

ADCON3 := $1003; //ADCS=3 (min TAD for 10MHz is 3*TCY=300ns)

ADCON2 := 0; //Interrupt upon completion of one sample/convert

ADCON1.15 := 1; //ADC on

Trang 10

while TRUE do

begin

Delay_ms(100); //Wait for 100ms (sampling )

ADCON1.1:=0; //Clear SAMP bit (trigger conversion)

while ADCON1.1 = 0 do nop; //Wait for DONE bit in ADCON1

LATD:= ADCBUF0; //Output result on port D

end;

end.

Example 2: (Cont’d)

Trang 11

ADC

Using CCS-C compiler in programing ADC function

1 - Setup_ADC ( mode )

ADC_OFF : not use ADC

ADC_CLOCK_INTERNAL: sampling time = MCU clock (2-6 us)

ADC_CLOCK_DIV_2: sampling time = MCU clock/ 2 (0.4 us -when using OSC 20MHz )

ADC_CLOCK_DIV_8 : sampling time = MCU clock/ 8 (1.6 us )

ADC_CLOCK_DIV_32 : sampling time = MCU clock/ 32 (6.4 us)

2 - Setup_ADC_ports ( value )

ALL_ANALOGS ; NO_ANALOG ; AN0_AN1_AN3

3 - Set_ADC_channel ( channel )

4 - Read_ADC ( mode )

ADC_START_AND_READ : default

Trang 12

Example 3:

Trang 13

#include <16F877.h >

#use delay( clock=20000000 )

// ADC 8 bit , ADC : 0-255

#device *= 16 ADC = 8

#FUSES hs,nowdt,noput,nolvp

#byte portB =0x06

#byte portC=0x07

#define RS pin_c0

#define RW pin_c1

#define E pin_c2

Int8 adc, donvi, chuc, tram;

Int8 a =0;

{

output_b(0x38);// config LCD

truyen_lenh();

output_b(0x0E);

truyen_lenh();

Delay_ms (100 );

Setup_ADC ( ADC_internal ) ; Setup_ADC_ports (AN0);

Set_ADC_channel ( 0 ) ;

Delay_us (10 );

While (true ) { adc = read_adc ( ) ;

a = adc;

convert_to_ascii();

hienthi();

} }

Trang 14

Example 3: (Cont’d)

void convert _to_ascii()

{a=a%1000;

tram=a/100 + 0x30;

a=a%100;

chuc= a/10 + 0x30 ;

donvi=a%10 + 0x30;

}

Void hienthi() {

Output_b( 0x80);

Truyen_lenh ; Output_b (‘V’);

Truyen_du_lieu ();

Output_b (donvi);

Truyen_du_lieu ();

Delay_ms (10 );

Output_b ( chuc);

Truyen_du_lieu ();

Delay_ms (10);

Output_b ( tram);

Truyen_du_lieu ();

Delay_ms (10);

}

Trang 15

Example 3: (Cont’d)

void truyen_lenh() //Allow to transmit data to LCD’s register

{output_low(RS);

output_low(RW);

output_high(E);

delay_ms(5);

output_low(E);

delay_ms(5);}

void truyen_du_lieu()//put data to RAM then appear on LCD

{output_high(RS);

output_low(RW);

output_high(E);

delay_ms(5);

output_low(E);

delay_ms(5);

}

Trang 16

Example 4:

void open_adc()

{

setup_adc_ports(RA0_RA1_RA3_ANALOG);

setup_adc( ADC_CLOCK_INTERNAL );

set_adc_channel( 0 );

}

unsigned int32 pro_adc()

{

char i;

adc_value=0;

for(i=1;i<=200;i++)

{

adc_value+=read_adc();

delay_ms(1);

}

adc_value/=200;

return adc_value=adc_weight(adc_value);

}

ADC

Trang 17

DAC – Digital Analog Converter

How can we use DAC module in PIC microcontroller?

What should we need more in order to use this function?

Give examples?

Ngày đăng: 07/11/2017, 14:16

TỪ KHÓA LIÊN QUAN

w