ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 2221

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

CodeVisionAVR

5.8 Setting the Analog-Digital Converter

Some AVR chips contain an analog-digital converter (ADC).

By selecting the ADC tab of the CodeWizardAVR, you can specify the ADC configuration.

Checking the ADC Enabled check box enables the on-chip ADC.

On some AVR devices only the 8 most significant bits of the AD conversion result can be used. This feature is enabled by checking the Use 8 bits check box.

Some AVR devices allow the ADC to use a high speed conversion mode, but with lower precision. This feature is enabled by checking the High Speed check box.

If the ADC has an internal reference voltage source, than it can be selected using the Volt. Ref. list box or activated by checking the ADC Bandgap check box.

© 1998-2007 HP InfoTech S.R.L.

Page 196

CodeVisionAVR

Some AVR devices allow the AD conversion to be triggered by an event which can be selected using the Auto Trigger Source list box.

If you want to generate interrupts when the ADC finishes the conversion, then you must check the

ADC Interrupt check box.

If ADC interrupts are used you have the possibility to enable the following functions:

by checking the ADC Noise Canceler check box, the chip is placed in idle mode during the conversion process, thus reducing the noise induced on the ADC by the chip's digital circuitry

by checking the Automatically Scan Inputs Enabled check box, the CodeWizardAVR will generate code to scan an ADC input domain and put the results in an array. The start, respectively the end, of the domain are specified using the First Input, respectively the Last Input, spinedit boxes.

If the automatic inputs scanning is disabled, then a single analog-digital conversion can be executed using the function:

unsigned int read_adc(unsigned char adc_input)

This function will return the analog-digital conversion result for the input adc_input. The input numbering starts from 0.

If interrupts are enabled the above function will use an additional interrupt service routine adc_isr. This routine will store the conversion result in the adc_data global variable.

If the automatic inputs scanning is enabled, the adc_isr service routine will store the conversion results in the adc_data global array. The user program must read the conversion results from this array.

© 1998-2007 HP InfoTech S.R.L.

Page 197

CodeVisionAVR

For some chips, like the Atmega169V/L, there is also the possibility to disable the digital input buffers on the inputs used by the ADC, thus reducing the power consumption of the chip.

This is accomplished by checking the corresponding Disable Digital Input Buffers check boxes.

If the Automatically Scan Inputs option is enabled, then the corresponding digital input buffers are automatically disabled for the ADC inputs in the scan range.

© 1998-2007 HP InfoTech S.R.L.

Page 198


CodeVisionAVR

5.9 Setting the ATmega406 Voltage Reference

Some AVR chips, like the Atmega406, contain a low power precision bang-gap voltage reference, which can be configured by selecting the Voltage Reference tab of the CodeWizardAVR.

Checking the Voltage Reference Enabled check box enables the precision voltage reference.

The Voltage Calibration list box allows for precision adjustment of the nominal value of the reference voltage in 2mV steps.

The Temperature Gradient Adjustment slider allows shifting the top of the VREF versus temperature curve to the center of the temperature range of interest, thus minimizing the voltage drift in this range. The Atmega406 datasheet may be consulted for more details.

© 1998-2007 HP InfoTech S.R.L.

Page 199


CodeVisionAVR

5.10 Setting the ATmega406 Coulomb Counter

The Atmega406 chip, contains a dedicated Sigma-Delta ADC optimized for Coulomb Counting to sample the charge or discharge current flowing through an external sense resistor Rs.

This ADC can be configured by selecting the Coulomb Counter tab of the CodeWizardAVR.

Checking the Coulomb Counter Enabled check box enables the Coulomb Counter Sigma-Delta ADC.

The Accumulate Current Conversion Time list box specifies the conversion time for the Accumulate Current output.

The Regular Current Detection Mode check box specifies that the Coulomb Counter will repeatedly do one instantaneous current conversion, before it is turned of for a timing interval specified by the

Sampling Interval list box.

The interval selected using the above-mentioned list box includes a sampling time, having a typical value of 16ms.

The Accumulate Current Interrupt check box enable the generation of an interrupt after the accumulate current conversion has completed. This interrupt is serviced by the ccadc_acc_isr ISR. The Regular Current Interrupt check box enable the generation of an interrupt when the absolute value of the result of the last AD conversion is greater, or equal to, the values of the CADRCC and CADRDC registers. This interrupt is serviced by the ccadc_reg_cur_isr ISR.

The Instantaneous Current Interrupt check box enables the generation of an interrupt when an instantaneous current conversion has completed. This interrupt is serviced by the ccadc_conv_isr ISR.

The Regular Charge Current, respectively Regular Discharge Current, list boxes determine the threshold levels for the regular charge, respectively regular discharge currents, setting the values for the CADRCC, respectively CADRDC, registers used for generating the Regular Current Interrupt.

© 1998-2007 HP InfoTech S.R.L.

Page 200

CodeVisionAVR

The Atmega406 datasheet may be consulted for more details about the Coulomb Counter.

5.11 Setting the SPI Interface

By selecting the SPI tab of the CodeWizardAVR, you can specify the SPI interface configuration.

Checking the SPI Enabled check box enables the on-chip SPI interface.

If you want to generate interrupts upon completion of a SPI transfer, then you must check the SPI Interrupt check box.

You have the possibility to specify the following parameters:

SPI Clock Rate used for the serial transfer

Clock Phase: the position of the SCK strobe signal edge relative to the data bit

Clock Polarity: low or high in idle state

SPI Type: the AVR chip is master or slave

Data Order in the serial transfer.

Checking the Clock Rate x2 check box, available for some AVR chips, will double the SPI Clock Rate.

For communicating through the SPI interface, with disabled SPI interrupt, you must use the SPI Functions.

If the SPI interrupt is enabled, you must use the spi_isr interrupt service routine, declared by the CodeWizardAVR.

© 1998-2007 HP InfoTech S.R.L.

Page 201


CodeVisionAVR

5.12 Setting the Universal Serial Interface - USI

By selecting the USI tab of the CodeWizardAVR, you can specify the USI configuration. The USI operatinging mode can be selected using the Mode list box.

One of the USI operating modes is the Three Wire (SPI) mode:

© 1998-2007 HP InfoTech S.R.L.

Page 202

CodeVisionAVR

The USI can also operate in the Two Wire (I2C) mode:

The Shift Reg. Clock list box sets the clock source for the USI Shift Register and Counter.

As both the USI Shift Register and Counter are clocked from the same clock source, the USI Counter may be used to count the number of received or transmitted bits and generate an overflow interrupt when the data transfer is complete.

Checking the USI Counter Overflow Interrupt check box will generate code for an interrupt service routine that will be executed upon the overflow of the USI Counter.

If the USI Start Condition Interrupt check box is checked then the CodeWizardAVR will generate code for an interrupt service routine that will be executed when a Start Condition is detected on the I2C bus in USI Two Wire operating mode.

© 1998-2007 HP InfoTech S.R.L.

Page 203


CodeVisionAVR

5.13 Setting the I2C Bus

By selecting the I2C tab of the CodeWizardAVR, you can specify the I2C bus configuration.

Using the I2C Port list box you can specify which port is used for the implementation of the I2C bus. The SDA Bit and SCL Bit list boxes allow you to specify which port bits the I2C bus uses.

© 1998-2007 HP InfoTech S.R.L.

Page 204

CodeVisionAVR

5.13.1 Setting the LM75 devices

If you use the LM75 temperature sensor, you must select the LM75 tab and check the LM75 Enabled check box.

The LM75 Address list box allows you to specify the 3 lower bits of the I2C addresses of the LM75 devices connected to the bus. Maximum 8 LM75 devices can be used.

The Output Active High check box specifies the active state of the LM75 O.S. output.

The Hyst., respectively O.S. , spinedit boxes specify the hysterezis, respectively O.S. temperatures.

The LM75 devices are accessed through the National Semiconductor LM75 Temperature Sensor Functions.

© 1998-2007 HP InfoTech S.R.L.

Page 205

CodeVisionAVR

5.13.2 Setting the DS1621 devices

If you use the DS1621 thermometer/thermostat, you must select the DS1621 tab and check the

DS1621 Enabled check box.

The Output Active High check box specifies the active state of the DS1621 Tout output.

The Low, respectively High, spinedit boxes specify the low, respectively high temperatures trigger temperatures for the Tout output.

The DS1621 devices are accessed through the Maxim/Dallas Semiconductor DS1621 Thermometer/Thermostat functions.

© 1998-2007 HP InfoTech S.R.L.

Page 206

CodeVisionAVR

5.13.3 Setting the PCF8563 devices

If you use the PCF8563 RTC, you must select the PCF8563 tab and check the PCF8563 Enabled check box.

The CLKOUT list box specifies the frequency of the pulses on the CLKOUT output.

The Alarm Interrupt check box enables the generation of interrupts, on the INT pin, when the alarm conditions are met.

The Timer|Clock list box specifies the countdown frequency of the PCF8563 Timer.

If the Int. Enabled check box is checked, an interrupt will be generated when the Timer countdown value will be 0.

If the INT Pulses check box is checked, the INT pin will issue short pulses when the Timer countdown value reaches 0.

The Timer|Value spinedit box specifies the Timer reload value when the countdown reaches 0.

The PCF8563 devices are accessed through the Philips PCF8563 Real Time Clock Functions.

© 1998-2007 HP InfoTech S.R.L.

Page 207