Home

AVR064: A Temperature Monitoring System with

image

Contents

1. AMEL 4 9 LCD Writing to the LCD requires an LCD driver The driver used in this application is described in the application note AVR065 LCD Driver for the STK502LCD 4 9 1 LCD update Figure 4 8 LCD update _ C LCD_update cs _ LCD_ updateComplete TRUE No Set LCD_updateRequired FALSE Write data fromTransmit No Scrolling text Buffer Y Yes Clear all Enable all Set specialsegments segments specialsegments if l required Go to Y LCDscrolIMSG Load one byte from function transmitbuffer Le E A y Activate blinking if Set LCD_updateComplete required FALSE E D Write the digit to Set LCD_updateRequired LCD_displayBuffer P Yes 6 digits No D written to fa S buffer C Return This function will load data into the LCD_displayBuffer First check if the LCD has been updated with the data already in the LCD_displayBuffer If so set the LCD_update required to FALSE This will prevent the LCD to be updated with incomplete data if an LCD Start of Frame interrupt should occur during this function If a text string is to be scrolled clear display and call the LCDscrollMSG function If no text to scroll check if there is data to write from the TransmitBuffer and load the data into the LCD_displayBuffer Digits can be set to blink on the display
2. ad PC1 SEG11 OC04 PCINTI2 PB4 14 ag PCO SEG12 OC1APCINT13 PES T5 Di pai SEGIO OC1B PCINT14 PBS 16 E PGO SEG14 zJ GIG St z SG fa E SI o D N e Oe NU e t gt BRBRBRESZ2PRBERERB EERE os F RR GF sf S ee s gd Ts 3 88 34 amp amp amp z o GB SS ada a g o e 8 o Se se ee S S S a E E EERE The ATmega169P has lower power consumption in power down and power save than ATmega169 revision E but there are also other differences e g oscillator Please see application note AVR098 and the ATmega169 P datasheets for more information 4 AVR064 2529C AVR 02 06 3 2 STK502 3 2 1 LCD display 3 2 2 NTC thermistor 2529C AVR 02 06 AVR064 The STK502 board is a top module designed to add ATmega169 P support to the STK500 development board from Atmel The STK502 includes connectors and hardware allowing full utilization of the new features of the ATmega169 P including an LCD display while the Zero Insertion Force ZIF socket allows easy use of TQFP packages for prototyping Figure 3 2 STK502 top module for STK500 pin1 location marked TEA LED CKKKKKk See the STK502 User Guide for more information about the STK502 Liquid Crystal Displays LCDs are categorized as non emissive display devices In that respect they do not produce any form of light like a Cathode Ray Tube CRT LCDs are composed of a polarized liquid crystalline material in between two plates of glass
3. To do this the digit will be loaded with either its data value or a ASCll space 0x20 depending on the variable LCD_ Blink 18 AVR064 2529C AVR 02 06 4 9 2 Scroll function 2529C AVR 02 06 AVR064 After the LCD_displayBuffer has been updated the LCD_updatedComplete will be set to FALSE and LCD updateRequired to TRUE This will cause the LCD_displayBuffer to be written to the LCD in the LCD Start of Frame interrupt Figure 4 9 LCDscrollMsg EES R LCDscrollMsg d String pointer LCD display Yes at the end of empty string D No i No Y Write six characters Add one space and write N Clear from the String to the the remaining characters string counter LCD_displayBuffer from string to the LCD_displayBuffer y y If not set to infinite Increment scrolling decrement the string pointer NumberOfScroll variable Return Pa This function shifts the six digits on the LCD one step to the left The scroll function uses a pointer to keep track of what characters to shift in and out of the LCD When all the six digits have been updated the pointer gets incremented by one in order to shift the text string one step the next time this function is called If the pointer has reached the end of the string the LCD has to be filled up with one ASCll space at the time until all of the six digits are blank This will fade out the text string AMEL e 4 9 3 LCD
4. byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 2 byte 2 byte Transferring the data in ASCII allows a standard terminal to be used on the PC These routines transmit the data from ATmega169 P to the PC 2529C AVR 02 06 AVR064 Figure 4 6 Transmit packet to PC Send TX data N e J interrupt USARTO UDRE_ vect void USARTO UDRE interrupt void gt On going transmission Ie UDRE interrupt a Load Preamble bytes in transmit buffer Bytes left to send I Load 0x20 y bi ASCII space Disable UDRE in transmit buffer interrupt i Convert one HEX byte to 2 3 ASCIl bytes Transmit one byte a f Return from A interrupt HEX bytes left to convert Load 0x0D ASCII line feed in the end of packet i Enable UDRE interrupt that will start the transfer Return Gi DE A transmit packet starts with the preamble bytes and then the HEX bytes that are to be transmitted get converted to ASClI bytes and loaded in the packet Between each HEX byte that gets converted an ASClI byte for space 0x20 is inserted At the end of the packet an ASClI byte for Line Feed is added to indicate the end of frame The transmission starts by enabling the UDRE interrupt When all bytes are transmitted the UDRE interrupt gets disab
5. element is attached S See BRA BRAR ni afte BERD Figure 2 1 Application overview TREEREN TR AR a A aA JAN ENEY VAN VAN VAN ATmega16 U A 32 kHz R i STK500 Timer2 SWITCHES ADC Heating NTC cooling element LEDS The LCD starts with scrolling the text STK502 example application for ATmega169 P It is required that the example code is programmed into the ATmega169 P and the hardware is set up according to the section Hardware Configuration on page 6 Thermistor Select a desired temperature set point When the temperature goes below this set point value the Heater I O pin will go high and a LED on STK500 will flash When the temperature goes above the set point value the Cooler I O pin will go high and another LED on the STK500 will flash The duty cycle of the LED flashing will vary with the actual temperature deviation from the set point the greater the deviation is the brighter the LEDs will shine The LCD will display time and temperature information All data that is presented on the LCD will also be sent through the UART interface and can be received by etc a standard terminal Pressing a button on the STK500 will shift between the different information on the LCD This information is e CLOCK RTC clock running on the ATmega169 P e DATE Calculated from the RTC clock e SET POINT Selected temperature e TEM
6. set up data 5 Terminal AVR064 AIMEL vg Figure 4 10 LCDsetupData LCDsetupData e A Load Welcome string and activate infinite scrolling Menu1 active Menu3 active Menu2 active Disable colons No Load a string depending on Menu1 to be scrolled once Y y Enable Enable colons colons aya Return de If Menu isn t active the welcome will scroll over the LCD If Menu1 is active but not Menu2 the corresponding string will be scrolled once over the LCD and then the belonging data If Menu2 is active but not Menu3 just enable the colons And if Menu3 is active disable the colons to indicate that the current variable can now be adjusted All temperature and time information is transmitted through the UART interface A program on a PC can receive this data by connecting a serial cable between the RS232 SPARE on the STK500 and a com port on the PC A standard terminal can be used e g HyperTerminal Set up the terminal with the settings shown in Figure 5 1 2529C AVR 02 06 AVR064 Figure 5 1 Port Settings Port Settings Bits per second Data bits Parity Stop bits Flow control Restore Defaults Cancel Press the connect button and the data from the ATmega169 P should appear as in Figure 5 2 The data is presented according to Table 5 1 Tab
7. temperature and selected temperature set point PB4 and PB7 are heating and cooling pins respectively Connect a heating and cooling element to these pins DDRE is set as input and should be connected to the SWITCHES on the STK500 PE7 PE6 and PES are used to select what information should be displayed on the LCD and adjusting time date temperature set point and the LCD contrast Timer Counter1 is set up with PWM to use on the 0C1A 0C1B PB5 PB6 pins Enable Timer Counter2 with asynchronous operation for the RTC By using an external 32kHz crystal the RTC can run independently of the ATmega169 P system clock and will also run during sleep Set up the UART with both RX and TX enable baud rate 9600 1 MHz asynchronous operation 8 bit character size 1 stop bit and disable parity mode Set up the ADC in single ended mode Differential mode can be selected by setting ADC_init Differential instead of ADC_init SingleEnded in the source code Disable digital input on PORTF and run a dummy ADC conversion 2529C AVR 02 06 4 4 Time and date update 2529C AVR 02 06 AVR064 Enable all segment pins on the ATmega169 P Select the 32kHz as clock source for the LCD and set the prescaler bits thereafter Select 1 4 duty cycle and 1 3 bias Set up Timer CounterO Compare Match interrupt to give the required delays for the scrolling and blinking speed of the information on the LCD display Start scrolling the initial string o
8. use it in a formula to calulate the corresponding temperature Find the difference between the measured temperature and the setpoint and if necessary set heating or cooling pin Ga Return x Start by doing an A D conversion The average of 32 ADC results is used in a formula to calculate the corresponding temperature The heating or cooling pin is set depending on the difference between the calculated temperature and the temperature set point The temperature set point is selected by the user The bigger the difference is the brighter the heating or cooling LED will shine 4 6 Receive data from PC These routines take care of data coming from the PC through the UART interface 12 AVR064 2529C AVR 02 06 AVR064 Figure 4 5 Receive packet from PC interrupt USART_RXC_vect verga N void USARTO_RXC_interrupt void Store RX data SS Se ra I RXC interrupt RX_Packet complete N ge V E E Read the UDRO reg which There may be up to contains the received byte three ASCII bytes to get one HEX byte Byte in receivebuffer 0x0D YES or 0x20 end of packet or new byte Preamble received Store received byte in y NO receive buffer Convert ASCII byte to HEX Received byte 0x0D ascii value for line feed end of packet Any byte converted St
9. 95131 USA Tel 1 408 441 0311 Fax 1 408 436 4314 Microcontrollers 2325 Orchard Parkway San Jose CA 95131 USA Tel 1 408 441 0311 Fax 1 408 436 4314 La Chantrerie BP 70602 44306 Nantes Cedex 3 France Tel 33 2 40 18 18 18 Fax 33 2 40 18 19 60 ASIC ASSP Smart Cards Zone Industrielle 13106 Rousset Cedex France RF Automotive Theresienstrasse 2 Postfach 3535 74025 Heilbronn Germany Tel 49 71 31 67 0 Fax 49 71 31 67 2340 1150 East Cheyenne Mtn Blvd Colorado Springs CO 80906 USA Tel 1 719 576 3300 Fax 1 719 540 1759 Biometrics Imaging Hi Rel MPU High Speed Converters RF Datacom Avenue de Rochepleine BP 123 38521 Saint Egreve Cedex France Tel 33 4 76 58 30 00 Fax 33 4 76 58 34 80 Tel 33 4 42 53 60 00 H K ong Kong Fax 33 4 42 53 60 01 Tel 852 2721 9778 Te 1150 East Cheyenne Mtn Blvd Japan Colorado Springs CO 80906 USA 9F Tonetsu Shinkawa Bldg Tel 1 719 576 3300 1 24 8 Shinkawa Fax 1 719 540 1759 Chuo ku Tokyo 104 0033 Japan Scottish Enterprise Technology Park Tel 81 3 3523 3551 Maxwell Building Fax 81 3 3523 7581 East Kilbride G75 0QR Scotland Tel 44 1355 803 000 Fax 44 1355 242 743 Literature Requests www atmel com literature Disclaimer The information in this document is provided in connection with Atmel products No license express or implied by estoppel or otherwise to any intellectual property right is granted
10. AVR064 A Temperature Monitoring System with Features LCD Output 8 bit AVA Microcontrollers Presenting data on an LCD display e Temperature measurement Real Time Clock RTC e x UART communication with a PC Application Note PWM implementation 1 Introduction The STK502 board is a top module designed to add ATmega169 P support to the STK500 development board from Atmel STK500 and STK502 provide all hardware needed to get started developing with the ATmega169 P This application note is meant to be an example of how to use the ATmega169 P and the STK502 It includes A complete ATmega169 P code example written in C code Flowcharts explaining the code Instruction on how to configure the STK502 A pre programmed ATmega169 P including the example in this application note is shipped with each STK502 kit The source code is found on the AVR Technical Library CD shipped with the STK502 or on the Atmel AVR web site http www atmel com products avr Figure 1 1 The STK502 board Rev 2529C AVR 02 06 ATMEL AMEL 2 Application overview 2 AVR064 This application note describes how to get started with the ATmega169 P microcontroller MCU the first AVR that has a built in LCD controller driver This application is a temperature control application including a Real Time Clock RTC It will monitor the temperature through a sensor and regulate the temperature if a heating cooling
11. PERATURE Measured temperature e OFFSET Difference between the measured temperature and the set point e CONTRAST Shows all the segments available with the default hardware strapping Adjusting the CLOCK DATE SET POINT or the CONTRAST can be done by using three of the SWITCHES on the STK500 Since these switches are used for different 2529C AVR 02 06 2529C AVR 02 06 AVR064 functions there is a need for a menu system See Figure 2 2 for an overview of how the menus are arranged in this application Figure 2 2 Menu System Menu 1 Menu 2 Menu 3 WE HOUR CLOCK MINUTE Lo E m o SECOND p gt DAY L gt DATE gt MONTH L gt gt YEAR L gt SET POINT re SET POINT Le TEMPERATURE OFFSET m CONTRAST ren CONTRAST Lo gt Please see section STK500 switches on page 17 for more detailed information on how to use the menu system The CLOCK DATE and SET POINT can also be adjusted from the UART interface See section Terminal on page 20 The implementation is designed to be used with the STK502 and the LCD display that is included in this starter kit For technical specifications and
12. Return H Return d Xe o a A z There are three switches that are used as inputs to the application To do several tasks with only three switches a menu system is needed Figure 4 7 shows three menus in a hierarchy which are used in this code See Figure 2 1 for an overview of the menus Figure 4 7 refers to Button A B C in the application these buttons can be found at ButtonA is SW7 that is connected to PE7 ButtonB is SW6 that is connected to PE6 ButtonC is SW5 that is connected to PES Example After a RESET the LCD is set up to scroll a text None of the three menus are active Pressing the SW7 will toggle between the alternatives in Menu1 Clock Date Set point Temperature Offset and Contrast To adjust the variable MINUTE Press SW7 until CLOCK appears in the LCD display and select this by pressing SW6 to activate Menu2 under CLOCK Pressing SW7 will now toggle between the alternatives in Menu2 Hour Minute and Second Press SW7 until the variable MINUTE is blinking in the LCD display and select this by pressing SW6 Now Menu3 is activated the colons should disappear Pressing SW7 will increase the variable MINUTE and SW6 will decrease When desired value has been selected press SW5 to deactivate Menu3 and go back to Menu2 Press SW5 once more to deactivate Menu2 and go back to Menu The same procedure can be used to adjust the other variables as well AMEL 7 2529C AVR 02 06
13. Typically one plate is called the common or backplane and the other is called a segment or frontplane In a reflective LCD panel one that has no back light a voltage difference applied across the two electrodes will result in a polarization that will prevent the light from reflecting back to the observer This will appear as a dark segment and is therefore considered ON A lack of voltage difference will allow the light to reflect back and is considered OFF For more information on the LCD driver see application note AVR065 LCD driver for the STK502 LCD Various types of sensors can be used to measure temperature One of these is the thermistor or temperature sensitive resistor Most thermistors have a negative temperature coefficient NTC meaning the resistance goes up as temperature goes down Of all passive temperature measurement sensors thermistors have the highest sensitivity resistance change per degree of temperature change Thermistors do not have a linear temperature resistance curve The NTC thermistor used with this application has a resistance of 10kQ at 25 C beta value of 3450 and a tolerance of 1 The voltage over the NTC can be found using the A D converter in the ATmega169 P See the ATmega169 P datasheets for AMEL s AMEL how to use the ADC And by the use of Equation 3 1 the temperature can be calculated Equation 3 1 Calculation of temperature from measured ADC values p Tempera
14. by this document or in connection with the sale of Atmel products EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL S WEB SITE ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTY OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE OR NON INFRINGEMENT IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT INDIRECT CONSEQUENTIAL PUNITIVE SPECIAL OR INCIDENTAL DAMAGES INCLUDING WITHOUT LIMITATION DAMAGES FOR LOSS OF PROFITS BUSINESS INTERRUPTION OR LOSS OF INFORMATION ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice Atmel does not make any commitment to update the information contained herein Unless specifically provided otherwise Atmel products are not suitable for and shall not be used in automotive applications Atmel s products are not intended authorized or warranted for use as components in applications intended to support or sustain life Atmel Corporation 2006 All rights reserved Atmel logo and combinations thereof Everywhere You Are AVR AVR Studio and others are the regis
15. es DNF 0x99E2 OK Leaving programming mode OK As Figure 3 5 describes the only fuses that should be programmed is 4 ATmega169 P firmware Brown out detection disabled JTAG Interface Enabled Boot Flash section size 1024 words Int RC Osc Start up time 6CK 65 ms This section contains information about the source code and functions The firmware can be downloaded from the Atmel website http www atmel com products AVR For compiler info and settings device settings target setup info and comprehensive source documentation please see the readme html file included with the source The timing related functions are written for an ATmega169 P running at 1Mhz except the RTC clock and the LCD frame rate that is clocked from an external 32kHz crystal and the prescaler for the system clock is therefore set to 1 8 Please note that the ATmega169 revision B runs at 4 MHz so the communication speed of the UART will be reduced from 9 600 to 4 800 baud but otherwise will be ok 4 1 Interrupts used 4 1 1 LCD Start of Frame In this interrupt the data from the LCD_displayData buffer is latched to the LCD Data Registers The variable LCD_Blink toggles every time this interrupt occurs The interrupt is dependent of the external 32kHz crystal 8 AVR064 2529C AVR 02 06 AVR064 4 1 2 Timer Counter2 Overflow This interrupt is used to increment the variable SECOND which the whole RTC clock builds on Timer Counter2
16. iguration eset eeneeeeeecneeeeeeeeeeeseeeeetieeeeeseeeeees 6 4 ATmega169 P firmware ii 8 Mur te 8 4 4 1 LCD Startof Frame sas e aaa 8 4 1 2 Timer Counter2 Overflow nn nesreeenen neee 9 4 1 3 USARTO RX complete ei 9 4 1 4 USARTO Data Register Empty nnns nnt 9 AZ MAM OOP EE 9 4 3 InitialiZ a sane aca don ieee eli i acon keel hes iba Lario 9 4 4 Time and date Updater turi eet AE ege ane 11 4 5 Temperature calculation te teetttnttnertesttttntnnntestttnn nnns teertnnn nn 12 4 6 Receive data from PC teeren nnen 12 E E e EE 13 ANG 2 StOre RX e EE 13 4 7 Transmit packet to PO iiri aaa 14 ALG STK 5S0O SWItCNSS EE 17 49 LCD her osa iii lait aaa leo E 18 4 9 1 LCD lee 18 4 92 Scrolfunctioni siiiicana errare arnesi ansa 19 4 9 3 LCD set up data i aa aaa ea 20 E ia Rail 20 6 Table Of Contenlis iiiiiiiiiviiaeicivica 23 PERI ma 24 ATMEL 2 2529C AVR 02 06 AIMEL RO O Atmel Corporation 2325 Orchard Parkway San Jose CA 95131 USA Tel 1 408 441 0311 Fax 1 408 487 2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH 1705 Fribourg Switzerland Tel 41 26 426 5555 Fax 41 26 426 5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Atmel Operations Memory 2325 Orchard Parkway San Jose CA
17. is clocked asynchronous from the 32kHz and is therefore independent of the clock frequency 4 1 3 USARTO RX complete This interrupt takes care of incoming data from the UART interface 4 1 4 USARTO Data Register Empty This interrupt transmits data out through the UART interface 4 2 Main loop Figure 4 1 shows the main loop Figure 4 1 Main loop Initialize I m Time and date update y Temperature calculation Y Store data from receive buffer i Send data from transmit buffer I Check status on STK500 buttons I Update LCD 4 3 Initialize After a reset the firmware will initialize the ATmega169 P and its integrated peripherals The initialization runs only one time after a reset ATMEL 2529C AVR 02 06 AVR064 AMEL Figure 4 2 Initialize Initialization Set PORTB as output Set PORTE as input I Set up Timer1 with PWM Phase Correct 10 bit i Set up the Real Time Clock using Timer2 in asynchronous mode I Set up the UART Baudrate 9600 1Mhz I Set up the ADC I Set up the LCD with 1 4 duty cycle and 1 3 bias Enable all segments I Set up data for the LCD display Scrolling text Return N 3 PORTB is set as output and should be connected to the LEDS on STK500 PB5 OC1A and PB6 OC1B show the offset between measured
18. le 5 1 Transmit Packet from ATmega169 according to Figure 5 2 Data Value Preamble STK502 Hour 15 Minute 14 Second 22 Day 04 Month 11 Year high 20 Year low 02 Set point 25 C high byte 25 C low byte 14 Offset 00 Versions number 01 ATMEL n 2529C AVR 02 06 ATMEL Figure 5 2 HyperTerminal STK502 HyperTerminal lol x File Edit View Call Transfer Help Dis al 3 alal ei STK502 15 14 22 1 20 25 25 STK502 15 14 22 20 25 25 STK502 15 14 22 20 29 25 STK502 15 14 22 1 20 25 25 STK502 15 14 22 20 25 25 STK502 15 14 22 20 23 25 STK502 15 14 22 1 20 25 25 STK502 15 14 22 20 25 25 STK502 15 14 22 20 25 25 STK502 15 14 22 1 20 25 25 STK502 15 1 20 25 25 Disconnected ANSI 9600 8 N 1 SCROLL CAPS Num Capture Print echo One can also adjust the variables within the ATmega169 P from the terminal This has to be done according to Table 4 1 E g write STK502 14 37 02 25 11 20 02 24 in the terminal and press enter to indicate end of frame This will adjust the clock to 14h37m02s the date to 25 November 2002 and the temperature set point will be 24 C AVR064 2529C AVR 02 06 AVR064 6 Table of Contents eg E 1 RI ET EE 1 2 Application aVervieW vi ene ee enee ria 2 3 Hardware description cecco 4 KN MERL EE A 9 2 STKD02 ini aa lei liano oi lid at dei 5 SOA Ben EEN 5 KEN MR E Ee 5 3 3 Hardware conf
19. led AMEL e 2529C AVR 02 06 16 AVR064 AMEL Table 4 2 Transmit packet to PC Data Preamble STK502 ASCIl space 0x20 HOUR ASCIl space 0x20 MINUTE ASCIl space 0x20 SECOND ASCIl space 0x20 DATE ASCIl space 0x20 MONTH ASCIl space 0x20 YEAR_HI ASCIl space 0x20 YEAR_LO ASCIl space 0x20 SET_POINT ASCIl space 0x20 TEMP_HIGHBYTE ASCIl space 0x20 TEMP_LOWBYTE ASCIl space 0x20 OFFSET ASCIl space 0x20 Firmware revision ASCll carriage return 0x0D ASCll line feed 0x0A Size 6 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 1 byte 2 byte 2 byte 2 byte 2529C AVR 02 06 4 8 STK500 switches Figure 4 7 CheckButtons i A CheckButtons Es Y Read buttons Buttons No TT released from Return N met Tiri Menu2 Yes Menu3 Yes SE active i 2 GE Button gt Be SR Button N C A Bor Se A BoC gt B or C gt Y By y Y By y Y By Y Shift Activate Deactivate Shift Activate Deactivate Increase Decrease Deactivate Menu Menu Menu Menu Menu Menu value value Menu3 y y y Run Run Run LCDsetupData LCDsetupData LCDsetupData e 8 Y bd i EX Ee i F N Return
20. ore the HEX byte Preamble received FALSE to SRAM RX_Packet complete TRUE cl Return from NO Ke interrupt A Byte in receivebuffer 0x0D Set RX_Packet complete FALSE Return I GE 4 6 1 USART_RXC_interrupt Receiving data from the PC is done in the USART_RXC_interrupt routine It will discard all data until the correct preamble bytes are received Then it will store the succeeding bytes in a receive buffer until the byte for Line Feed appears ASCII value 0x0D This indicates the end of the packet and RX_Packet_complete flag will be set to TRUE 4 6 2 Store Px data The packet is then converted from ASCII to hexadecimal One HEX byte can contain 1 3 ASCII bytes ASCll bytes that belong to different HEX bytes are separated by an ATMEL 13 T 2529C AVR 02 06 4 7 Transmit packet to PC AVR064 AMEL ASCll space 0x20 The converted HEX bytes get continuously stored in the correct place in SRAM until the Line Feed byte appears which is the end of the packet Table 4 1 Receive Packet from PC Data Preamble STK502 ASCll space 0x20 HOUR ASCll space 0x20 MINUTE ASCll space 0x20 SECOND ASCll space 0x20 DATE ASCll space 0x20 MONTH ASCll space 0x20 YEAR_HI ASCll space 0x20 YEAR_LO ASCll space 0x20 SET_POINT ASCll carriage return 0x0D ASCll line feed 0x0A Size 6 byte 1 byte 2 byte 1
21. ram the ATmega169 P see the STK502 User Guide for help on this topic The avR064 hex file that should be programmed into the ATmega169 P can be found on the AVR Software and Technical Library CD that comes with the STK502 and on the ATMEL web site http www atmel com products avr If the ATmega169 P is reprogrammed make sure the fuses are set up according to Figure 3 5 AMEL r AMEL STK500 Program Fuses LockBits Advanced Board Auto Figure 3 5 Fuse settings Program Fuses LockBits Advanced Board Auto kb Brown out detection disabled BODLEVEL 111 TT Brown out detection level at YCC 1 8 Y BODLEVEL 110 IT Brown out detection level at YCC 2 7 Y BODLEVEL 101 TO Brown out detection level at VCC 4 3 Y BODLEVEL 100 TT External reset disable RSTDISBL 0 TM On Chip Debug Enabled OCDEN 0 bk JTAG Interface Enabled JTAGEN 0 I5 Serial program downloading SPI enabled SPIEN 0 M Watchdog timer always on WDTON 0 I Preserve EEPROM memory through the Chip Erase cycle EESAVE 0 TT Boot Flash section size 128 words Boot start address 1F 90 BOOT S TO Boot Flash section size 256 words Boot start address 1F 00 BOOT S TT Boot Flash section size 512 words Boot start address 1E00 BOOTS F Boot Flash section size 1024 words Boot start address 1C00 BOOTS I Boot Reset vector Enabled default address 0000 BOOTRST 0 TT Divide clock by 8 internally CKDI8 0 P
22. rogram Verify Read J Auto Verify IV Smart Wamings Setting device parameters serial programming mode OK Entering programming mode OK Reading fuses OxFF 0x99E2 OK Leaving programming mode OK sl ls ll TT Boot Flash section size 256 words Boot start address 1F00 BOOT S lt TT Boot Flash section size 512 words Boot start address 1E00 BDOTS I Boot Flash section size 1024 words Boot start address 1C00 BOOTS T Boot Reset vector Enabled default address 0000 BOOTRST 0 TT Divide clock by 8 internally CKDIV8 0 TT Clock output on PORTE CKOUT 0 TT Ext Clock Start up time 6 CK 0 ms CKSEL 0000 SUT 00 TO Ext Clock Start up time 6 CK 4 1 ms CKSEL 0000 SUT 01 T Ext Clock Start up time 6 CK 65 ms CKSEL 0000 SUT 10 F Int RC Osc Start up time 6 CK 0 ms CKSEL 0010 SUT 00 I Int RC Osc Start up time 6 CK 4 1 ms CKSEL 0010 SUT 01 I Int RC Osc Start up time 6 CK 65 ms CKSEL 0010 SUT 10 T Ext Low Freq Crystal Start up time 32K CK 0 ms Int Cap CKSEL IO Ext Low Freq Crystal Start up time 32K CK 4 1 ms Int Cap KSE TO Ext Low Freg Crystal Start up time 32K CK 65 ms Int Cap CKSEL T Ext Low Freq Crystal Start up time 1K CK 0 ms Int Cap CKSEL L gt Program Verify Read I Auto Verify V Smart Wamings Setting device parameters serial programming mode DK Entering programming mode OK Reading fus
23. tered trademarks or trademarks of Atmel Corporation or its subsidiaries Other terms and product names may be trademarks of others 2529C AVR 02 06
24. the LCD bit mapping please refer to the STK502 User Guide found in the AVR Studio help system and for more information on the LCD driver see Application note AVR065 LCD driver for the STK502 LCD AMEL s AIMEL 3 Hardware description 3 1 ATmega169 P The ATmega169 P is an ultra low power AVR 8 bit RISC microcontroller It includes 16K of bytes self programming Flash Program Memory 1K bytes SRAM 512 Byte EEPROM and 8 Channel 10 bit A D converter JTAG interface for on chip debugging and 4 X 25 Segment LCD Driver It can do up to 1 MIPS throughput at 1 MHz Tor ATmega169 P V or 4 MIPS throughput at 4 MHz for the ATmega169 P L The ATmega169 P is an excellent choice for low power applications that requires user interaction LCD keyboard and the possibility to interface analog sensors etc Figure 3 1 ATmega169 e Tsi o a e sig 8ELELL8 3588 8 o a a e SG SG E SB a 9 6 gt 8 w gt Se Es EE EE Eaoezzs BIBIBIBIG dp 5 liels LCDCAP ag Pa3 COM3 RXD PCINTO PEO 47 Pad SEGO TXD PCINT1 PE1 44 PAS SEG1 XCK AINWPCINT2 PE2 4 45 PAG SEG2 AIN1 PCINT3 PES 44 PAT SEG USCKISCUPCINTA PES 6 43 PG2 SEG4 DUSDA PCINTS PES 7 42 PCT SEGS5 DO PCINTS PES 8 41 POS SEGS ATmega169 CLKOPCINT7 PET PCS SEG7 SS PCINTE EE el PCA SEGS SCK PCINTS PBI ag PCS SEGS MOSI PCINT1 O PB2 PC2 SEG10 MISO PCINT11 pen 19
25. ture sla Hf Vane _B Na WW Vanc T mb p 3450 Vanc Voltage calculated from the A D conversion Na 1 263V Tiro 273 K Toso 298 K 273 C 25 C 3 3 Hardware configuration 6 AVR064 In order to make the example code work it is required to set up the cables and switches in the correct order Figure 3 3 and Figure 3 4 shows how to set up the cables and switches Figure 3 3 Cable settings 2529C AVR 02 06 2529C AVR 02 06 n AVR064 Connect PORTE on the STK502 to the SWITCHES header on the STK500 with a 10 pin cable Connect PB5 PB6 to LED5 LED6 PB4 PB7 to respectively Heating Cooling element If no heating cooling element is available just connect PORTB to the LEDS using a 10pins cable Connect PEO PE1 on the STK500 to the RXD TXD Connect the Segment pins from ATmega169 P to the STK502 LCD pins with the 34pins cable Place a jumper on the 2pins header 19 24 Insert the NTC thermistor in the screw terminal All of the three switches on the STK502 should be in the position towards the screw terminal i e the TOSC switch should be in the TOSC position the AREF switch should be in the VREF position and the PF 1 0 should be in the SENSOR position Connect PG5 and RST with a jumper on PORTG RST And most importantly insert the ATmega169 P in the ZIF socket The ATmega169 P that comes with the STK502 kit is pre programmed with the example code If it is required to reprog
26. ver the LCD display This routine updates the clock and date according to the variable SECOND that gets incremented every second in the Timer Counter2 Overflow interrupt routine The whole update routine is self explaining from the flow chart Figure 4 3 Time and date update d 1 Time update SECOND larger than 59 NO YES A Increment MINUTE Clear SECOND MINUTE larger than 59 NO YES Increment HOUR Clear MINUTE HOUR larger than 23 NO YES Increment DAY Clear HOUR DAY larger than number of days in month check if leap year NO YES Increment MONTH Set DAY 1 MONTH larger than 12 YES Increment YEAR_LO Set MONTH 1 YEAR_LO larger than 99 Increment YEAR_HI Clear YEAR_LO Return E Ze AMEL The variable SECOND is incremented in the Timer2 Overflow Interrupt routine 11 AMEL 4 5 Temperature calculation In this function the voltage over the NTC thermistor will be measured and the temperature calculated Figure 4 4 Temperature calculation 400 conversion Run an Analog to Digital Conversion 1 Increment the number of A D conversions Measured temperature 32 times NO Calculate the voltage from the ADC value and

Download Pdf Manuals

image

Related Search

AVR064: A Temperature Monitoring System with avr-x6400 avr-x6400h

Related Contents

JVC KD-DV6101 User's Manual  Betriebsanleitung Aufbau-Drillmaschine AD-2 - Ersatzteile  EWRC 300/500 NT - Eliwell-Store-logo Eliwell-Store-logo  SérieuSement amuSant ! tout l`eSprit du CaSino barrière de blotzheim  取扱説明書1はこちら  NEOPERL 97115.05 Installation Guide  SERVICE MANUAL  Manual de instruções  CDA FW480 freezer  BL 300 / BL 350  

Copyright © All rights reserved.
DMCA: DMCA_mwitty#outlook.com.