Pré-visualização parcial do texto
Baixe Phan 3 - Embedded C Programming And The Atmel AVR 2nd Edition - created PDF by Huy Nam e outras Notas de estudo em PDF para Engenharia Elétrica, somente na Docsity!
900 MHz Transmitter À foge The 900 MHz transmitter is an off-the-shelf FM transmitrer gles. The TXM900HPII module supports eight different E to us Phone” band. A DIP switch is used to select which channel we wisa «9 “ module by Linx Technolo- els 11 the “portable tele- ce, allowing us to phone or interfering signals. move the radio fi PRRRRO eii a local portable dio frequency away from that of a P d to conserve power, because “The transmitter supports a power-down feature that will be use the outdoor unit runs from batrery and solar power. : The input to the module is the USART TXD signal directly sistor is uscd to prevent overdriving the modulation input of the friso cause itto “over modulate.” The maximum modulation voltage fper the é is not TTL; iris only abour 1 V AC. The input of the module hos : Some experimentation proved that 3.9k gave the best pertormane wi modulation forces the transmitter output to swing outside the proper FM range, which would cause both the receiver to not “hear” the transmitted signal and the transmitter to generate unwanted RF interference. from the Megal6. À 3.9K re- itrer, which would specification) r Power Supply The power supply is pretty basic. You will note that there are actuzlly nvo 5 V supplies, one for the radio and one for everything else. This is done to reduce £ digital noise from the processor to the transmitres, as well as to lower the amount oº conducted RF from the transmitter back into everything else. The battery is a 12 V, 2200 mAh, gel-cell type “unit. Thesc are extremely rugged and rechargeable. They are considered a zero-maintenance type of battery. E ; - The solar panel is diode coupled into the system such that on a sunnv day it will not only completely power the outside unit but charge the battery as well. You may also note that there is no current limiting between the solar panel and the system. The solar panel has à limited current capability due to its high internal resistance. Adding more resistance WO simply reduce the charging rate of the battery as well as the solar pânel's contribution in running the system. A 5.6.5 SOFTWARE DESIGN, OUTDOOR UNIT Designing the software is teally just planning out how the software will function. When the “design of the software is complete, we have a list of tasks and their priorities and a set a C s describing how the tasks are ticd together. À A A ; ta being sentto the transmitir, tese four tasks are all ha i i H a ad ndled on an interrupt basis. The only erating 0op of the sofivare are to calculate when to serd informa to put the information into a buffer for the ; tasks left for the main op- j tion to the transmitterand transmitier. igure 512 shows a basie 7 die it y Figu 3 2 basic fow diagram for the Outdoor urit software. Note that there isa main process and tour interrupt ox exception Processes; one for the rain gauge intermpt (INTO), cad for sampling the temperature, humidity, wind direction. and voltage read- De O amo tie RO Pe (TIS Ae e ; : ings (AD Cy another É U SART iransr ns (USART PME) qual another for sampling the wind speed timer (Timer Dand inttiatina transmissions (TIRO Aline Bastos cisco actual Fetitstatetitetioo fuive Deer) covered im che, tion of the hard- he ADOS char are Doe the AVR mesure the ter perature, humidity, and battery health. Timer 1 samples wind speel. INTO is used to seep track of raintall. The telemetry is even kept simple by using the USART of the AVR such that standard I/Q tou- tines could be used "right out of the box.” Ware 5.6.6 HARDWARE DESIGN, INDOOR UNIT i à : | are asim id do Now we repeat the design process for the indoor unit. When the hardwar: esign is done, we will have full schematics for the indoor unit, às shown in Figure 5-13. The indoor unit has a 900 MHz receiver module for gathering information from the E É É É RR ta S sda ssor, tem- outdoor unit. The indoor unit comprises the same basic power PRE PAR sor, e i idi i r tons of a barom: Perature sensing, and humidity sensing as the outdoor unit. The a pressure sensor, buttons, LEDs, a beeper, a 32.767KHz watch crystal for a real-time clock, andan LCD display really set it functionally apartfrom the outdoor unit. à : s iver is left There is no bartery-charging system'on the indoor unit, and the 900 MHz pias bi Sha dd, y PjNe, E . E E E Ê É active all the time so that the outdoor unit ceports are heard. The input-power, ry age 15 monito it can” w-b: 4 dition. i 1 nreport a low-battery con ag onit red so that the indoor pat : P E e É Ee. is an otf-the-shelf EM receiver module by A as et e É E TCEEIN Ursa gra 11 " a à Re : RXM900 PII pre ao supports eight dir cd pe ça move the radio — g ; À ii i a 7 pda Vi E à JÁ DIP-switeh is used to select veia Bento phone or interfering sigrads= The cup Abe 5 frequency away trom that ofa local pi aid io 2 TO SE RR a» NUM 190pu| YONUOW 19/02 NOUS EIS 8 t y , e (epou uq-pJ AVIASIQ “3NN PXOZZXIL/LXOL ach i heric noise could aPpearto scern what ig signal and what is Noise, a n use an interrupt as à pating Signal ET; Mb teaçê overhead required to decode the : e» ting stected” signal, REI By creating an “RF detected” signal, co E the USART and lower the amount O messages from the outside unit. Power Supply ; ; ted two 5 V supplies, one for the radio and g scr ) É p i outdoor unit, the power suppiy igital noise from the proces. aa br caTaa else. This is ore to reduce O aisfng É ne A to ig ço E a jack, Consistin x na 5 S sor to the receiver. The battery is a 6 e ve ir into the system, allowing instant ries. The off-the-shelf power supply is dio DR arara power cutage. switching from power supply to battery backup in The LCD backlight is driven directly from the wall supply. The backlight requires too much current to run from the battery, and it consumes enough Esta RR 2 large amount regulators. Theretore, we opted to drive the backlicht directly and bypass all rue to operate (on battery €—we can ncthe E E e al core ot chese issnes. In rhe eventofa power failure. thé unit will cont : fa dire seslesi IRS ER power), but the display backlight will be out, making the display harder to se shine a flashlight on it if we need to know what it says. of! 5.6.7 SOFTWARE DESIGN, INDOOR UNIT The indoor unit has two basic functions: collect and convert data, and interface with a human. The collection process is fairly straightforward in that the indoor unit measures the indoor temperature, humidity barometric pressure, and battery health on its own ADCsin exactly the same manner as the outdoor unit. The outdoor parameters of temperature, hu- midity rainfall, wind speed, wind direction, and battery health are collected in the same units as the indoor unit (ADC Counts, timer counts, ete.). E toughest ad to Partos the indoor unit software is defining the human interface. eferring to. erationa! 1 ton” | RD ig a a Ha dead Abi Fa ae e E in'Section 5.6.2, “Definition Phase,” this weather . Hivenmcolumn LCD and an arrangement of three buttons. À played in groups of three, as shown in Table 5-4 Temperature Indoor CEDER o - Perature Outdoor ; ja á : W E as (4, v,-) Wind Speed es a e “ty Indoo; rp im ion, * ad. E OTERTA 5 Tr Humidity Outdoor D “iai É Is (HM, D,M, y): “Time (* fashes E ew Point (Qutdoor) Date — Tables4 Porameter Triads to Be i | a to Be Displayed li Fligh-Rainfall Aler: Low Batt Outdoor Low Batt Indocr No Outdoor Comm Table 5-5 Possible WarningiAlert Messages . batteries and press the SET button to clear the error. The batteries can be checked atany time, simply By unplugging the power supply from the unit. fem, inei- This low-voltage Jeicciuiá cam also be uscd foras apnéia ' ther the outdoor or the indoor unit. If the voltage is detected to be below normal, data such as the accumulared rainfall can be saved'to EEPROM, and then the unit could simply hold in a loop waiting for the power to disappear completely or to return to an acceptable level. Handling EEPROM storage in this as-nceded manner also preserves its life, because con- tinuously writing to EEPROM will eventually lead to its failure. As discussed in Chapter 1, the potential for failure is due to the way that EEPROM memory itself is constructed, a function ofeleciro-chemistry. In many cases, this memory area will have a rating of 10,000 or 100,000 write operations, maximum. A low-battery condition on the outside unit will eventually lead to no data reports from the outside unit. In this case, the loww-battery LED indicator on the inside unit will be turned on solid until the outside Unit voltage goes back Up to normal. When the outside unit volt- age goes back to normal, the LED vil go back off. É S t the outdoor unit't power oing away, or a lengthy period of RF interference. While shi: condition exists, al nda parameters will be replaced with question marks, For example, wind speed would read: Input: O'to5 V DC thedugha TORA Method: Apply different voltages to the input through a PolEndioRREE Té : AE ui Potentiometer to a weather vane and measu ] re the voltage in : : Put to the microcontroller with à volt ) : ith a voltmeter. vtué Wind Speed RR : á ; Input: 30 mph wind i : É pr aeh INC might recua ro e ) calm day! É asa a! Tend, a reliable method of transportation, and a xpected Results: 75 Ha si Mal to the mi = X : signal Croprocessor. E 1 o the mi processor. Method: Cause the a ete “TR e inemome ter to be blown at a knowr; rate'and measure the pulse train to : crocontroiler using a ireguency counter, an oscilloscope, or the microcontroller irself. You might need to write software to count the pulses and transmit them to the indoor uni: te ses and r uni: ses isa SUR ted anerame- pulse per revolution. The out- tor displav fa portable mer! had of cu = cd anel y 1 2 impb. Only minor adjustmeats may be required. ter tor tins projects factorv e puris approximately 2.515 | Rain Gauge Input: One cup (8 07.) of water Expected Results: À representative number of transitions presented to the imicrocôntroiler input. Method: $/oww!y pour the water into the rain gauge and, using a counter or the microcontroller itself, count the transitions. The RG-T transitions every 0.01 inch of r infall, so a counter should indicate 722 low-to-high transitions, or 1444 changes of state. You may need to write software to count the transitions and transmit them to the indoor unit for display. The selected rain gauge for this project is factory calibrated and should need no adjustments. Air Temperature : Input: Ice water, room temperature, warm hands. ei -Expected Results: A representative voltage presented to the microco miuda nana as | , 24 inches or so. Seal the device in M “Place the NTC device on some long wire leads, 24 inches or s paia a od as much air à possible): Place the device in ice water 32 F(OC ag after a minute or so, 2.39 V DC should be present at the mine controllaç gemperaçure, 70'F (210) a voltage of approsimately-3:3 W should be the indoor-unit hardivaro Th designs. Knowing for certain that the development and integration time, as well as your tail” when things do not make sense. j ca Outdoor Unit Checkout à Poe a r ra ; i lo. ER m the lab supply for 12V DC “with a current limit of approximately one ampere. At this point, no battery or solar Panel should be connected. - Connect a lab supply to the battery or solar panel connection. - Make syre that Vcc and Vec.| areat5V DC. ifthe power supply is not corract, nothing will be quite right. - Using a voltmeter, verify that the BATT signal (pin 38 of the Megal6) is approximately 3.8V DC. a - Using a voltmeter, verify that the output of the humidistat is a level that corresponds with the humidity of the room that you are in. An office or classroom is typically 20 to 30% RH. Whatever the Percentage is. you should measure abou: char percentage of SV on rhe HUMID signal (pin 39 of rho Mega lá) - Using a voltmeter. verify that the Output Of the temperature ses" 5 a levei that cor: responds with the temperature of the room that you are in. The average office or iassroom temperature is about 70ºF (21 “C).and that shouid causa a voltage of ap- proximately 3.3V to appear at the TEMP signal 4pin40 of the Meza16).If you pinch the thermistor in your fingers while watching this voltage, you should see the voltage rise as your body heat warms the sensor. Connect the anemometer and the wind vane to the appropriate inputs. Using an oscilloscope, verify that the SPEED signal (pin 2 of the Mega 16) has pulses of adequate level (TTL level, which is greater than 3.3Y for a “high” and less than 1.5V for a “low”).These pulses will exist only while you spin the anemometer, so give it a whirl! - Using a voltmeter, verify that the WIND input (pin 37 of the Mega 16) moves uniformly “from 0V to 5Y DC as you slowly rotate the wind vane. As you cross north, the voltage will jump from O0Y to SV,or from 5Y to 0Y. E. the rain gauge to the appropriate input. E ie à voltmeter or an oscilloscope, verify the RAIN signal (pin 16 of the Mega 16). As ! ã pour water through the gauge, you. ithar tip the seesãw assembly by hand or pour water e à ã má Na voltage of the RAIN signal transition from OV to 5V DC and back again. sing the test program listed below program the Megal6 with the following ings. These settings guarantee the prope eration . BODLVL = ON . JTAG = OFF . (ojos) = (Ci . CESAVE = OFF . BOOTRST= O pa a a E - outdoor unit erra tee tinclude «Mega sinclude Fr ear tt test erra e ea nd dd 16.h> «stdio.h> e send test. Eslay ms(100); putst( "UUUStest*QQOrr"); delay ms (500); PORTC.6 =; Geslay ms (500); PORTC.6 = 0; ) 3. Usinga RF sj gnal-strength m TxM900HpII evaluation ki eter,aspectrum analyzer, or à Linx Technologies that the RF ener missions should with a &y should go off b Occur about ones etw . een transmissions for 500 milliseconds. Trans parte rt et mt a aerea err te stream every 1 /l allow q +! transmit message /1 RF power off fl wait /! PRF power on ' P ; ; . C.monitor the messages being transmicred. Not cond apart. e es NS SS AA t code Meneses amena) Eeananao Unit Tes O led ginclude ginclude /* LCD Control Lines +/ “PORTB.O PORTB.1 pORTB.2 gdeíine LCD E idefide LCD RS 4gefine LCD RW sdefine LCD PORT PORTC unsigned char LCD ADDR; /+ LCD DATA PORT */ LCD RW = 0; (4 set t'R act ) [ll raise E (data & 0x0F put à Put ala adia (4 p E o LCD BW = 1; / di ie ] delay ms(3): . , (3: (4 allow Sisp 2 ESP a Ely tó cirmk void wr di ( -Sisp(unsigned char data) LCD RW = 0. LCD E = 1. o LCD ! E 2. PORT= (data > CDE =p. 2 4); [1 gr . Strobe ypn CDE =s. it tata LCD PORT . [1 out » Lcd E fdata «q Sto th E=0; 0x0F) Ne display (! now, s- Se roha o . E LCDLRS = nto À WE disp(c), LCD ADDR++; Void disp ces esco Ê Érom ag Flunsigned char flash “SA) !* display-string a ( É while("sa I= 0) disp crar(*sa-»); E na É : , vivaita) LCD R5 = 6; delay ms(59); Wc nal (On uê ce enabies the display War nal tomas fofos float interface mode. É wr' half(0x33); /! These c angs can be Found wr half(0x22); ti in the manufacturer's data sheets. : wr disp(0x28); 1; Enable the internal 5x? font wr disp(Cx01); sá a wr disp(0x10); /4 Set cursor-to move . E 11 (instead of display shift). , wr disp(0x06); /! Set the cursor to move right, and: = ae tear É or vtf not shift therdisplaye RARE => " wr disp(0x0c); // Turns display on, cursor off, and É o /! cursor blinking cff. y // init. character font ram to rogo for (i=9xd0, i<0x5Fi À++) ( ISP LE(PINA & 0xE0) 4; LE amy buttos posses 4 PORPD O ft LOW BATT LED ON k PORTD.S = 1; delay ms(?); PORTD.5S = 0; */ beep the Pseger-- delay ms(1); ; , É else um a " LI. Very the message Indoor Test” appears on the LCD. 12. Press the UNITS, SELECT, and SET buttons. The b=aper should scund at approximately 500 Hz.a nd the LOW BATTERY LED shou!d | ghtas lonzas o-z cí the butrons is =: dy probirg pins 28 y that. 5.6.10 SYSTEM INTEGRATION AND SOFTWARE DEVELOPMENT PHASE, OUTDOOR UNIT he outdoor The first stepin pt “tis to define the unit op- ing of th= actual processed outdoors, then each of the on units, like “For “C for temperature, to be trunsmited, Rainfa!i gets a bit messy in thatit basically takes un Id have to know how long forever is. “This thought proces data collected in the most basic form possible and letting the indoor unit do the conversions at the end. Besides, the indoor unit has a eration. In this c; o where the proce data Is to occu nd comm (o) 15 to leaving clock and interfaces with the human anyway. Soin this system the most basic units wou!! be ADC counts, Timer 1 counts, and the state of the rain gauge and the weather vane, Tais data can be combined and transmitted asa packet of values on a periodic basis. The transmitted period of the packets is not really ent- ical There should be enosuh data to catch the peaks ot wind and get an accurate represen- “not particularly fast-moving parameters, but humans like to feel nstance, a typical digital voltmeter offers a ling that is taking place is the wind speed. ar tation of rainfall. Th like they are being updates fairly frequently: Fora one-second sampling rate. The only critical samp will be samp E sd | to wind speed representatom., | during the eransmission of the data. Tt Às duro ry consumption unit that the highest current requirements ef me active to time inactive, ulti he indoor ply, whether it is the solar Panel, the- “ One consideration is the batte ing the transmission of the data to t the system are achieved. The duty c determines the average current draw ont * battery, or both. ; À . j d is to define the inputs and outputs of de are starte : 1 s a great way to get started, since another tound ycle, or ratio of ti he power sup) The next step in getting the softw microprocessor that are to be used. This 1 À o ca tieropro j he schematic, and ore the definitions are made of sanity checking gets performed on the sc ] ic is ed. The defnit the need for constantly referring back to the schematic is peieR no . eo the . o EE 5-15 remirder: comments follow cutdoor unit may appear as shown-in Figure > 15. À remindc s ing the gdefine statements need “/” and “as delimiters. Onee the pins have been labeled, the actual inputs, outputs, and p figured. This is usually performed at or called from the top ot inef = ()" (see code in Figure 5-16), note pherals need zo be con- 1). In the initialization Based on à 4.0 MHz oscillator, the interru his real-tins tick wii de uscd to sample che ancs fine to transmir the data to the indoor unit. Timer 1 is con tic ons in the ancmoncrer to measure wind s on “any change”, which allows cach tipping ofthe secsuv in che The USART is configured for 9600 baud, 8 data bits and 1 sions. The ADC is ser up to convert at the slowest rate, v O interrupt ; à tro to be captured » RF transmis- is gemer 'ly the best, and to generate um interrupt upon completion of each conversion. idefine TX CTS PINC.7 1 fCefine Tx 2OW PORTC.6 tt : fdefine WIND S a l tdefine a Ê fdefine NPUT 0 1 * ' fdefine LAST ADC INPUT 3 o E o tácsfine A -VREF TYPE 0x40 unsigned int adc data/LAST ADC INPUT FIR tdeíine TEMPE ; dani ine = ei ade data(0] /« analo . define BATER ade data(1) ;+ sonia o 7 adc data(2] sa igeia cha Og chan fdefine WIND DIRECTION ade data [3 ) ta a(3) ;+ Figure 5-|5 Example Definitions, Outdoor Unit I/Q mv ad » [o [o] Pa) u n ed [4 wo 7% INTL: OFf NR ; “/* INT2: CEÉ : j GICR]=0x40; MCUCR=0x01; MCUCSR=0x00; SIPR=0x40; Dea raia upt(s) initializa /* Timer (s)/Count dis Interrup TIMSK=0x01; PESCOp, NO Paldtyo e? PS GERT cane /* UART Bau VCSR H UCSR3=0x43; * UBRRL=0x19; JBRRH=0x00; hi '* Analog Comparator initializatíion /* Rnalog Comparator: Off ** Analog Comparator Input Co ptura by Timer/Counter 1:.0f£ */ ACSR=0x80; SFIOR=0x00; Rê MADE initialization Ee RE : ê FRADE Clock frequency: 31.250 kHz 2, /* ADC Voltage Reference: AVCC pin +/ ADMUX=FIRST ADC — INPUT [ADC —VRE Rm ADCSRA=0xCF; E , /* Watchdog Timer initialization RA /* Kacchãog Timer Pre WDTCR=0x0F; Scaler: 05Cc/2048 +/ 4 . (* Global enable inter tasm("seir) Y e Ed Rainfall is handled by simply keeping track of the state of the vo. e Tic da in this manner is probably a little overdone, but there are still a Eamgde cação 5 real world operation ofthe rain Sauge, and this is a good way to ent options o] The INTO functjon of PIND.2 h: to generate an interrupt in Ea Sang This means when the signal ar PIND,2 changes from high-to-low or low-to-high, the FOterrupt service rouhhe Fes O" ishown in Figure 5-18) gets calle In this AMterrupt routine, the charibteç a ne às set 10 reflect the rain gaus= input êdeiine êdefine tdefine '* analog chan (o) fdefine * aralog chan £, fdefine * analog chan 2, Fdsfire ** analog chan 2, rdex]=ADCW:; /*sBelect next ADC-input *4 if (++input index>(LAST ADC INPUT-FIRST ADC INPUT)) np t index=0; : ADMUX=input index+FIRST ADC INPUT|ADC VREF TYPE; /*. Start the nex:>: ADC conversion :/