ADC conversie met behulp van AVR

G

gameelgamal

Guest
HI,
Ik heb geprobeerd uit te voeren AD conversie met behulp van ATMEGA16 & code visie compiler
maar het
doesnt werk!

Ik moet een ADC-voorbeeld aan mijn programma te vergelijken met het ..

 
(shift F2) inside CodeVision to build your ADC code!

Gebruik CodeWizardAVR
(Shift F2) in CodeVision te bouwen uw ADC-code!Het werkte

 
onderstaande link vindt u de ADC-code voor WinAVR
http://booksbybibin.14.forumer.com/viewtopic.php?t=121

Bibin John
www.bibinjohn.tk

 
Gebruik de 3 ADC register ATMega16
ADMUX, ADCSRA en SFIOR.

Of, als u gebruik wilt maken van de CodeWizardAVR, u kunt het toch.
Alleen of u gratis stromend ADC of single run ADC.

 
/************************************************* ****
Project: Board Test
Versie: 1.0
Datum: 2.25.2007

Chip type: ATmega8535
Soort programma: Toepassing
Klokfrequentie: 4.000000 MHz
Memory model: Kleine
Externe SRAM grootte: 0
Gegevens Stack size: 128
************************************************** *** /

#
include <mega8535.h>
#
include "stdio.h"
#
include "realtime.h"
#
include "delay.h"
#
include "eeprom.h"

# define ADC_VREF_TYPE 0x40

/ / Lees de AD conversie resultaat
unsigned int read_adc (unsigned char adc_input)
(
ADMUX = adc_input | ADC_VREF_TYPE;
/ / Start de AD-conversie
ADCSRA | = 0x40;
/ / Wacht op de AD conversie te voltooien
while ((ADCSRA & 0x10) == 0);
ADCSRA | = 0x10;
terugkeer ADCW;
)

void init ()
(

/ / ADC initialisatie
/ / ADC Klok frequentie: 125.000 kHz
/ / ADC Voltage Reference: AVCC pin
/ / ADC High Speed Mode: Off
/ / ADC Auto Trigger Bron: Geen
ADMUX = ADC_VREF_TYPE;
ADCSRA = 0x86;
SFIOR & = 0xEF;

)unsigned int Get_Voltage ()
(
unsigned char i;
unsigned int V = 0;
unsigned int Data_ADC = 0;

buff [4] = buff [3];
buff [3] = buff [2];
buff [2] = buff [1];
buff [1] = buff [0];
buff [0] = read_adc (7);
for (i = 0; i <5; i ) Data_ADC = buff ;
V = (unsigned int) ((float) Data_ADC / 5);
return (V);
)

void main (void)
(

Vadc = Get_Voltage ();

)

Succes YOU!

 
Ik hoop dat dit zal helpen U..

Ik gebruik atmega32 .. 8 bits ADC ...en bemonstering 8 keer ...voor weergave van ADC conversie Ik gebruik lcd 16

#
include <mega32.h>

/ / Alfanumeriek LCD Module functies
# asm
. EQU __lcd_port = 0x15; PORTC
# endasm
#
include <lcd.h>
#
include <delay.h>
#
include <math.h>
#
include <stdio.h>

/ / Declareer uw globale variabelen hier
char str [16];
unsigned char adc_input;
unsigned int i;
unsigned char data_adc;
unsigned char data_tampung [8];
unsigned int jumlah;
unsigned int rata2;
unsigned char data_final;

/ / Lees de 8 meest significante bit
/ / Van de AD conversie resultaat
unsigned char read_adc (unsigned char adc_input)
(
ADMUX = adc_input | ADC_VREF_TYPE;
for (i = 0; i <8; i )
(

/ / Start de AD-conversie
ADCSRA | = 0x40;
/ / Wacht op de AD conversie te voltooien
while ((ADCSRA & 0x10) == 0);
ADCSRA | = 0x10;
/ / return ADCH;
data_adc = ADCH;
data_tampung = data_adc;

)

jumlah = 0;
for (i = 0; i <8; i )
(
jumlah = data_tampung ;
)

rata2 = ceil (jumlah /

<img src="http://www.edaboard.com/images/smiles/icon_cool.gif" alt="Koel" border="0" />

;
data_final = (unsigned char) rata2;
terugkeer data_final;
)

void main (void)
(
/ / Declareer uw lokale variabelen hier
unsigned int a = 0;
unsigned char data_kiri;
unsigned char data_serong1;/ / Input / output poorten initialisatie
/ / Port A initialization
PORTA = 0x00;
DDRA = 0x00;

/ / Poort B initialisatie
PORTB = 0x00;
DDRB = 0xFF; / / output-poort OKKK

/ / Port C initialisatie
PORTC = 0x00;
DDRC = 0xFF;

/ / Port D initialization
PORTD = 0x00;
DDRD = 0xFF;

/ / Timer / Counter 0 initialization
/ / Clock source: System Clock
/ / Klok waarde: 16000.000 kHz
/ / Mode: Normal top = FFH
/ / OC0 output: Disconnected
TCCR0 = waarde 0x01;
TCNT0 = 0x00;
OCR0 = 0x00;

/ / Timer / Counter 1 initialisatie
/ / Clock source: System Clock
/ / Clock value: Timer 1 Stopped
/ / Mode: Normal top = FFFFh
/ / OC1A output: Discon.
/ / OC1B output: Discon.
/ / Ruis Canceler: Off
/ / Input Capture op Falling Edge
/ / Timer 1 Overflow Interrupt: Off
/ / Input Capture Interrupt: Off
/ / Compare A Match Interrupt: Off
/ / Vergelijk B Match Interrupt: Off

TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0x00;
OCR1AL = 0x00;
OCR1BH = 0x00;
OCR1BL = 0x00;

/ / Timer / Counter 2 initialisatie
/ / Clock source: System Clock
/ / Clock value: Timer 2 Gestopt
/ / Mode: Normal top = FFH
/ / OC2 output: Disconnected
ASSR = 0x00;
TCCR2 = 0x00;
TCNT2 = 0x00;
OCR2 = 0x00;

/ / External Interrupt (s) initialisatie
/ / INT0: Off
/ / INT1: Off
/ / Int2: Off
MCUCR = 0x00;
MCUCSR = 0x00;

/ / Timer (s) / Counter (s) Interrupt (s) initialisatie
TIMSK = 0x00;

/ / Analog comparator initialisatie
/ / Analog Comparator: Off
/ / Analog Comparator Input Capture door Timer / Counter 1: Off
ACSR = 0x80;
SFIOR = 0x00;

/ / ADC initialisatie
/ / ADC Klok frequentie: 500.000 kHz
/ / ADC Voltage Referentie: Aref pin
/ / Alleen de 8 meest significante bits van
/ / De AD conversie resultaat worden gebruikt
ADMUX = ADC_VREF_TYPE;
ADCSRA = 0x85;

/ / LCD module initialisatie
lcd_init (16);
lcd_clear ();
lcd_gotoxy (0,0);
sprintf (str, "start");
lcd_puts (str);

while (1)
(

read_adc (3);
data_conversion = data_final;

lcd_clear ();
lcd_gotoxy (0,0);
sprintf (str, "Dataconversie =% u", data_conversion);
lcd_puts (str);

);

 
alle codes in verschillende zijn ok, maar wel aansluiten externe condensator btwn Aref en GND proberen.

 

Welcome to EDABoard.com

Sponsor

Back
Top