Advertisement  

Tuesday, 19 March 2024
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #200 - Light intensity and other environmental parameters With Xmega AVR Print

Here is little project, which in the next once proves the superiority an Xmega AVR microcontroller on monitoring and controlling process.

This project was designed to control and monitoring the environmental conditions that includes a set of sensors for measuring Light intensity temperature and humidity. XMEGA16A4 Microcontroller is used in this project.


Written by: Mohammad Jafar Dalvand, University of Tehran, Iran
Email Address: Dalvand@ut.ac.ir

Microcontroller

The XMEGA A4 is a family of low power, high performance and peripheral rich CMOS 8/16-bit microcontrollers based on the AVR® enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the XMEGA A4 achieves throughputs approaching 1 Million Instructions Per Second (MIPS) per MHz allowing the system designer to optimize power consumption versus processing speed.

The XMEGA A4 devices provides the following features: In-System Programmable Flash with Read-While-Write capabilities, Internal EEPROM and SRAM, four-channel DMA Controller, eight-channel Event System, Programmable Multi-level Interrupt Controller, 36 general purpose I/O lines, 16-bit Real Time Counter (RTC), five flexible 16-bit Timer/Counters with compare modes and PWM, five USARTs, two Two Wire Serial Interfaces (TWIs), two Serial Peripheral Interfaces (SPIs), AES and DES crypto engine, one Twelve-channel, 12-bit ADC with optional differential input with programmable gain, one Two-channel, 12-bit DAC, two analog comparators with window mode, programmable Watchdog Timer with separate Internal Oscillator, accurate internal oscillators with PLL and prescaler and programmable Brown-Out Detection. The Program and Debug Interface (PDI), a fast 2-pin interface for programming and debugging, is available.

 

 

Sensors

Light:

The TSL230R, TSL230AR, and TSL230BR programmable light-to-frequency converters combine a configurable silicon photodiode and a current-to-frequency converter on single monolithic CMOS integrated circuits. The output can be either a pulse train or a square wave (50% duty cycle) with frequency directly proportional to light intensity. Device sensitivity is selectable in three ranges, providing two decades of adjustment. The full-scale output frequency can be scaled by one of four preset values. All inputs and the output are TTL compatible, allowing direct two-way communication with a microcontroller for programming and output interface. An output enable (OE) is provided that places the output in the high-impedance state for multiple-unit sharing of a microcontroller input line. The devices are available with absolute-output-frequency tolerances of 5% (TSL230BR), 10% (TSL230AR), or 20% (TSL230R). They have been temperature compensated for the ultraviolet-to-visible light range of 320 nm to 700 nm and respond over the light range of 320 nm to 1050 nm. The devices are characterized over the temperature range of –25°C to 70°C.


An env 02.jpg


Humidity:

The HIH-4000 Series Humidity Sensors are designed specifically for high volume OEM (Original Equipment Manufacturer) users. Direct input to a controller or other device is made possible by this sensor’s linear voltage output. With a typical current draw of only 200 µA, the HIH-4000 Series is often ideally suited for low drain, battery operated systems. the RH sensor is a laser trimmed, thermoset polymer capacitive sensing element with on-chip integrated signal conditioning. The sensing element's multilayer construction provides excellent resistance to most application hazards such as wetting, dust, dirt, oils and common environmental chemicals.

 

Data PrintOut


An env 01.jpg


Temperature:

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1⁄4°C at room temperature and ±3⁄4°C over a full −55 to +150°C temperature range.

 

Features

  • Calibrated directly in ° Celsius (Centigrade)
  • Linear + 10.0 mV/°C scale factor
  • 0.5°C accuracy guaranteeable (at +25°C)
  • Rated for full −55° to +150°C range
  • Suitable for remote applications
  • Low cost due to wafer-level trimming
  • Operates from 4 to 30 volts
  • Less than 60 μA current drain
  • Low self-heating, 0.08°C in still air
  • Nonlinearity only ±1⁄4°C typical
  • Low impedance output, 0.1 W for 1 mA load

Schematic

An env 03.jpg

Source code

$regfile = "xm16a4def.dat"
$crystal = 32000000 '32MHz
$hwstack = 64
$swstack = 40
$framesize = 40
 
'include the following lib and code, the routines will be replaced since they are a workaround
$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
 
'First enable the osc of your choice
Config Osc = Enabled , Pllosc = Disabled , Extosc = Disabled , 32khzosc = Disabled , 32mhzosc = Enabled '32MHz
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 '32MHz
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
' ADC Configuration
Config Adca = Single , Convmode = Signed , Resolution = 12bit , Dma = Off , Reference = Intvcc , _
Event_mode = None , Prescaler = 256 , _
Ch1_gain = 1 , Ch1_inp = Diffwgain , Mux1 = &B00001001 , _
Ch2_gain = 1 , Ch2_inp = Single_ended , Mux2 = &B00010000
 
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Serial interface configuration
Config Com3 = 20000 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
'Config Serialin2 = Buffered , Size = 20 , Bytematch = 66
Open "COM3:" For Binary As #3
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
'Config Interrupts and timer
Config Priority = Static , Vector = Application , Lo = Enabled , Med = Enabled 'Enable Lo Level Interrupts
 
Config Porte.1 = Input
Config Xpin = Porte.1 , Outpull = Pullup , Sense = Falling 'enable Pullup and reaction on falling edge
 
Config Event_system = Dummy , Mux0 = Porte.1 , Digflt0 = 8 'Eventchannel 0 = PINE.1, enable digital filtering
Config Tce0 = Normal , Prescale = E0 , Event_source = E0 , Event_action = Freq ' Normal = no waveform generation, Event Source = Event Channel 0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
 
'Enable Receive Interrupt For Com3
On Usartd0_rxc Sending
Enable Usartd0_rxc , Lo
Enable Interrupts
 
' Port Configuration
Ddre.0 = 1 : Porte.0 = 0
Ddrd.7 = 1 : Portd.7 = 1
Ddrd.6 = 1 : Portd.6 = 0
Ddrd.5 = 1 : Portd.5 = 0
Ddrd.4 = 1 : Portd.4 = 1
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
'Variables defination
Dim A(2) As Word , Adc_step(2) As Single , Temp As Single , Hum As Single
Dim Freq As Word , C(3) As String * 5 , Datasend As String * 16 , Sum(2) As Long
Dim N As Byte , D(2) As Single , Sent As Bit
 
 
Adc_step(1) = 0.0315
Adc_step(2) = 0.0976
 
 
 
Do
 Portd.4 = 0
 Waitms 100
 Freq = Tce0_cnt
 Tce0_cnt = 0
 Sum(1) = 0
 Sum(2) = 0
For N = 1 To 2
 A(1) = Getadc(adca , 1 , &B00001001) 'ADC A, Channel 0 , MUX = &B00000000 --> PINA.0
 A(2) = Getadc(adca , 2 , &B00010000) 'ADC A, Channel 0 , MUX = &B00000000 --> PINA.0
 
 Sum(1) = Sum(1) + A(1)
 Sum(2) = Sum(2) + A(2)
Next N
 
 D(1) = Sum(1) / 2.0
 D(2) = Sum(2) / 2.0
 Hum = D(1) * Adc_step(1)
 Hum = Hum + 21
 Temp = D(2) * Adc_step(2)
 Temp = Temp + 3
 
Loop
Close #3
End
 
 
Sending:
Print #3 , Datasend
Return 'end program