ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 8177
Скачиваний: 1
© MCS Electronics, 1995-2007 |
||
Offset |
An optional numeric variable of constant that specifies gain or mode. This |
|
option has effect on newer AVR micro’s only. The offset will be added by the |
||
channel value and inserted into the ADMUX register. |
||
The GETADC() function only will work on microprocessors that have an A/Dconverter. The pins of the A/D converter input can be used for digital I/O too.
But it is important that no I/O switching is done while using the A/D converter.
Make sure you turn on the AD converter with the START ADC statement or by setting the proper bit in the ADC configuration register.
Some micro’s have more then 7 channels. This is supported as well.
GetADC() returns a word variable since the A/D converter data registers consist of 2 registers. The resolution depends on the chip.
The variable ADCD can be used to access the data register directly. The compiler will handle access to the byte registers automatically.
See also
CONFIG ADC
Example
'----------------------------------------------------------------------------- |
|
--- |
: adc.bas |
'name |
|
'copyright |
: (c) 1995-2005, MCS Electronics |
'purpose |
: demonstration of GETADC() function for 8535 or |
M163 micro |
: Mega163 |
'micro |
|
'suited for demo |
: yes |
'commercial addon needed |
: no |
'use in simulator |
: possible |
' Getadc() will also work for other AVR chips that have an ADC converter |
|
'----------------------------------------------------------------------------- |
|
--- |
' we use the M163 |
$regfile = "m163def.dat" |
|
$crystal = 4000000 |
|
$hwstack = 32 |
' default use 32 |
for the hardware stack |
'default use 10 |
$swstack = 10 |
|
for the SW stack |
'default use 40 |
$framesize = 40 |
|
for the frame space |
|
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128 'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible Config Adc = Single , Prescaler = Auto
'Now give power to the chip
Start Adc
'With STOP ADC, you can remove the power from the chip 'Stop Adc
Dim W As Word , Channel As Byte
Channel = 0
page -501-