![]() |
![]() |
![]() |
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#31 (permalink) |
|
Experienced Member
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Engineergirl,
When you post code put [code] before your code and [/code] after it so that it keeps it's format. Also, what is the range of T and V. Mike. Last edited by Pommie; 30th April 2008 at 09:52 AM. |
|
|
|
|
|
#32 (permalink) |
|
New Member
Join Date: Apr 2008
Location: US
Posts: 21
![]() |
Thanks for responding, I wish I would have checked before I went to bed at 3:30am but that is ok. I hope that this is readable to you guys.
Heat Index = -42.379 + 2.04901523T + 10.14333127R - 0.22475541TR - (6.83783x10^-3) T^2 - (5.481717x10^-2) R^2 + (1.22874x10^-3) T^2R + (8.5282x10^-4) TR^2 - (1.99x10^-6) T^2 R^2 Where T= Temp in Farenheit, R= Relative Humidity Wind Chill = 35.74+0.6215T-35.75(V^0.16)+0.4275T(V^0.16) where T=Air Temperature(˚F) V=Wind Speed(mph) I know you guys work in celcius I hope it is ok that it is in Farenheit. I appreciate the help you have given me already, I have to update the schematic too, because that has changed. Elizabeth Last edited by engineergirl27; 30th April 2008 at 04:38 PM. |
|
|
|
|
|
#34 (permalink) |
|
New Member
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
![]() ![]() |
I would suggest table lookups for the heat index and wind chill. Do the computations on your PC using your favorite programming language then load them into tables in the PIC. For instance, tables of the heat index for each 10% of relative humidity indexed by the temperature. Then do linear interpolation. Similar tables for wind chill using wind speed and temperature.
|
|
|
|
|
|
#35 (permalink) |
|
Experienced Member
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Those are rather complex formulas to do in assembler. You can either use floating point or fixed point. I suggest fixed point with lookup tables.
Here is a table lookup that will do the V^0.16 for V=0-100 Code:
;GetV16 returns (W^0.16)*256 in word variable Acc ;Acc must be in common area (70-7f) GetV16 addlw low V16Tab ;calculate address in table bsf STATUS,RP1 ;bank 2 movwf EEADR movlw high V16Tab btfsc STATUS,C addlw 1 movwf EEADRH call ReadFlash ;will return in bank 0 return ReadFlash bsf STATUS,RP1 ;#2 bsf STATUS,RP0 ;#3 bsf EECON1,EEPGD ;read flash bsf EECON1,RD ;do read nop ;required delay nop bcf STATUS,RP0 ;#2 movfw EEDAT ;move into Acc movwf Acc movfw EEDATH movwf Acc+1 bcf STATUS,RP1 ;#0 return V16Tab dw .0,.256,.286,.305,.319,.331,.340,.349 dw .357,.363,.370,.375,.380,.385,.390,.394 dw .398,.402,.406,.410,.413,.416,.419,.422 dw .425,.428,.431,.433,.436,.438,.441,.443 dw .445,.447,.450,.452,.454,.456,.458,.460 dw .461,.463,.465,.467,.469,.470,.472,.473 dw .475,.477,.478,.480,.481,.483,.484,.486 dw .487,.488,.490,.491,.492,.494,.495,.496 dw .497,.499,.500,.501,.502,.504,.505,.506 dw .507,.508,.509,.510,.511,.512,.514,.515 dw .516,.517,.518,.519,.520,.521,.522,.523 dw .524,.524,.525,.526,.527,.528,.529,.530 dw .531,.532,.533,.534,.534 You can produce similar tables for your other terms. Just repeat the GetV16 routine with a different table address. Note that the largest value that can go in a table is 16383 as the flash memory is only 14 bits wide. For 16 and 32 bit multiplication and addition routines try the piclist. BTW, Skyhawks suggestion of lookup tables with interpolation is another good way to do it. Mike. |
|
|
|
|
|
#36 (permalink) |
|
New Member
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
![]() ![]() |
It's good to look at the range of values you need to consider. Try taking a look at this link:
http://www.nws.noaa.gov/os/heat/index.shtml If you restrict the data to realistic combinations of temperature and relative humidity, you can see that the range of temperatures that you need to handle is larger for low relative humidity than for high. |
|
|
|
|
|
#38 (permalink) |
|
Experienced Member
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
I did something similar to this a while back. I modified it to implement the first equation. Once you have your parameters in Temperature and RH you call GetHeat and it returns the value in variable Acc (2 bytes).
Code:
GetHeat movfw Temperature ;get Temperature addlw .35 ;table starts at -35 addlw .2 ;course rounding call Divide5 ;table goes up in steps of 5 movwf Acc ;each table entry is 24 words clrf Acc+1 ;so we need to multiply by 24 bcf STATUS,C rlf Acc,F rlf Acc+1,F rlf Acc,F ;*4 rlf Acc+1,F rlf Acc,F ;*8 rlf Acc+1,F movfw Acc movwf TempWord movfw Acc+1 movwf TempWord+1 ;keep a copy of Temperature*8 rlf Acc,F ;*16 rlf Acc+1,F movfw TempWord addwf Acc,F ;T*16+T*8=T*24 btfsc STATUS,C incf Acc+1,F movfw TempWord+1 addwf Acc+1,F movfw RH ;get the relative humidity addlw .2 ;course rounding call Divide5 ;table is in steps of 5 addwf Acc,F btfsc STATUS,C incf Acc+1,F movfw Acc addlw low HeatTable ;calculate address in table bsf STATUS,RP1 ;bank 2 movwf EEADR bcf STATUS,RP1 ;bank 0 movfw Acc+1 bsf STATUS,RP1 ;bank 2 addlw high HeatTable btfsc STATUS,C addlw 1 movwf EEADRH call ReadFlash ;will return in bank 0 return ReadFlash bsf STATUS,RP1 ;#2 bsf STATUS,RP0 ;#3 bsf EECON1,EEPGD ;read flash bsf EECON1,RD ;do read nop ;required delay nop bcf STATUS,RP0 ;#2 movfw EEDATA ;move into Acc bcf STATUS,RP1 ;#0 movwf Acc bsf STATUS,RP1 ;#2 movfw EEDATH btfsc EEDATH,5 ;is it negative iorlw b'11000000' ;yes, so sign extend bcf STATUS,RP1 ;#0 movwf Acc+1 return Divide5 clrf TempWord ;returns W/5 Div5Loop incf TempWord,F addlw 100h-5 ;add -5 btfsc STATUS,C goto Div5Loop decf TempWord,W return HeatTable dw -.122,-.27,.64,.151,.233,.311,.385,.454,.519,.579,.636,.687,.735,.778,.817,.851,.881,.907,.928,.945,.958,.0,.0,.0 dw -.110,-.22,.62,.141,.217,.288,.356,.419,.478,.533,.584,.631,.674,.712,.747,.777,.803,.825,.844,.857,.867,.0,.0,.0 dw -.98,-.17,.60,.133,.202,.267,.328,.386,.440,.489,.535,.577,.615,.650,.680,.707,.729,.748,.763,.774,.781,.0,.0,.0 dw -.86,-.12,.58,.125,.187,.247,.302,.354,.403,.448,.489,.526,.560,.590,.617,.640,.659,.675,.687,.695,.700,.0,.0,.0 dw -.75,-.7,.56,.117,.174,.228,.278,.325,.368,.408,.445,.478,.508,.534,.557,.577,.593,.606,.615,.621,.624,.0,.0,.0 dw -.64,-.3,.55,.110,.161,.210,.255,.297,.335,.371,.403,.432,.459,.481,.501,.518,.531,.541,.548,.552,.552,.0,.0,.0 dw -.53,.2,.54,.103,.150,.193,.233,.270,.305,.336,.364,.390,.412,.432,.448,.462,.473,.480,.485,.487,.486,.0,.0,.0 dw -.42,.7,.54,.97,.139,.177,.213,.245,.276,.303,.328,.350,.369,.385,.399,.410,.418,.424,.427,.427,.424,.0,.0,.0 dw -.32,.12,.53,.92,.128,.162,.194,.222,.249,.272,.294,.312,.329,.342,.353,.362,.368,.371,.372,.371,.367,.0,.0,.0 dw -.23,.16,.53,.87,.119,.149,.176,.201,.224,.244,.262,.278,.291,.302,.311,.317,.321,.323,.323,.320,.314,.0,.0,.0 dw -.13,.21,.53,.83,.111,.136,.160,.181,.201,.218,.233,.246,.257,.266,.272,.277,.279,.279,.277,.273,.267,.0,.0,.0 dw -.4,.26,.53,.79,.103,.125,.145,.164,.180,.194,.206,.217,.225,.232,.237,.239,.240,.239,.236,.231,.224,.0,.0,.0 dw .5,.30,.54,.76,.97,.115,.132,.147,.161,.172,.182,.191,.197,.202,.205,.206,.206,.203,.199,.194,.186,.0,.0,.0 dw .13,.35,.55,.74,.91,.106,.120,.133,.144,.153,.161,.167,.172,.175,.176,.176,.175,.172,.167,.161,.153,.0,.0,.0 dw .21,.39,.56,.72,.86,.98,.110,.120,.128,.136,.142,.146,.149,.151,.151,.150,.148,.144,.139,.133,.125,.0,.0,.0 dw .29,.44,.57,.70,.81,.92,.101,.109,.115,.121,.125,.128,.130,.130,.130,.128,.125,.121,.116,.109,.102,.0,.0,.0 dw .36,.48,.59,.69,.78,.86,.93,.99,.104,.108,.111,.113,.113,.113,.112,.110,.106,.102,.97,.90,.83,.0,.0,.0 dw .43,.52,.61,.69,.76,.82,.87,.91,.95,.97,.99,.100,.100,.99,.97,.95,.91,.87,.82,.76,.69,.0,.0,.0 dw .50,.57,.63,.69,.74,.78,.82,.85,.87,.89,.90,.90,.89,.88,.86,.84,.80,.76,.72,.66,.60,.0,.0,.0 dw .56,.61,.66,.70,.73,.76,.79,.81,.82,.83,.83,.83,.82,.81,.79,.76,.73,.70,.66,.61,.56,.0,.0,.0 dw .62,.65,.68,.71,.73,.75,.77,.78,.78,.79,.79,.78,.77,.76,.75,.73,.70,.67,.64,.61,.57,.0,.0,.0 dw .68,.70,.71,.73,.74,.75,.76,.77,.77,.77,.77,.77,.76,.75,.74,.72,.71,.69,.67,.65,.62,.0,.0,.0 dw .73,.74,.75,.75,.76,.77,.77,.77,.77,.78,.78,.78,.77,.77,.77,.76,.76,.75,.74,.73,.72,.0,.0,.0 dw .78,.78,.78,.78,.79,.79,.79,.80,.80,.80,.81,.81,.82,.82,.83,.84,.84,.85,.86,.86,.87,.0,.0,.0 dw .82,.82,.82,.82,.82,.82,.83,.84,.84,.85,.86,.88,.89,.91,.93,.95,.97,.99,.102,.104,.107,.0,.0,.0 dw .87,.86,.86,.86,.86,.87,.88,.89,.91,.92,.95,.97,.100,.103,.106,.109,.113,.117,.122,.127,.132,.0,.0,.0 dw .91,.90,.90,.91,.91,.93,.94,.96,.99,.102,.105,.109,.113,.118,.123,.128,.134,.140,.147,.154,.161,.0,.0,.0 dw .94,.94,.95,.96,.97,.100,.102,.106,.109,.114,.118,.124,.129,.136,.143,.150,.158,.167,.176,.185,.195,.0,.0,.0 dw .97,.98,.100,.102,.104,.108,.112,.116,.121,.127,.134,.141,.149,.157,.166,.176,.187,.198,.209,.221,.234,.0,.0,.0 dw .100,.102,.105,.108,.112,.117,.122,.129,.136,.143,.152,.161,.171,.182,.194,.206,.219,.233,.247,.262,.278,.0,.0,.0 dw .103,.106,.110,.115,.121,.127,.134,.143,.152,.162,.173,.184,.197,.210,.224,.239,.255,.272,.289,.308,.327,.0,.0,.0 dw .105,.110,.116,.122,.130,.138,.148,.158,.170,.182,.196,.210,.225,.241,.258,.276,.295,.315,.336,.358,.380,.0,.0,.0 dw .107,.114,.121,.130,.140,.151,.163,.176,.190,.205,.221,.238,.256,.275,.296,.317,.339,.362,.387,.412,.439,.0,.0,.0 dw .108,.117,.128,.139,.151,.165,.179,.195,.212,.230,.249,.269,.291,.313,.337,.361,.387,.414,.442,.471,.502,.0,.0,.0 dw .110,.121,.134,.148,.163,.180,.197,.216,.236,.257,.279,.303,.328,.354,.381,.410,.439,.470,.502,.535,.570,.0,.0,.0 dw .110,.125,.141,.158,.176,.195,.216,.238,.262,.286,.312,.340,.368,.398,.429,.461,.495,.530,.566,.604,.642,.0,.0,.0 The table was generated with a little excel sheet that I wrote. I'll attach it. You should be able to generate the other table with it. To use it run the macro called "Convert" and the table data will be placed on the clipboard. I had to zip it as xls files aren't allowed. The above code was written for a 16F88 but I'm pretty sure the 876 is the same. It's untested and so you may have to debug it. Have fun. Mike. Last edited by Pommie; 3rd May 2008 at 11:04 PM. |
|
|
|
|
|
#39 (permalink) |
|
New Member
Join Date: Apr 2008
Location: US
Posts: 21
![]() |
Thanks for all your help, I am still extremely confused on the lookup table stuff, I wish that i only had to work on the programming for this. but that is not the case, I am also trying to get the paper and presentation slides done for this project which is due friday. do you guys know of any easier way to calculate wind chill, I have a simpler equation WC = Temp - Wind Speed/4, but this is for Celcius and km/hour, so I would need to the the conversions for that. which might be possibly, might but I don't know if I have enough time in the day to do that.
Elizabeth |
|
|
|
|
|
#40 (permalink) | |
|
Experienced Member
Join Date: Sep 2007
Location: Vancouver, B.C.
Posts: 900
![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
__________________
========================= Futz's Microcontrollers & Robotics ========================= |
|
|
|
|
|
|
#41 (permalink) | |
|
New Member
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
![]() ![]() |
Quote:
http://www.nws.noaa.gov/om/windchill/ The windchill for a 5 mph wind is 4 degrees lower at 40F, 11 degrees lower at 0F and 17 degrees lower at -40F. Also at 0F a 5 mph wind lowers the windchill by 11 degrees, but a 60 mph wind lowers the windchill by 33 degrees, 3 times as much not 12 times as much. The best way is a 2-d table lookup using temperature and wind speed as indices. Compute the table enties using the formula that you gave earlier: windchill = 35.74+0.6215T-35.75(V^0.16)+0.4275T(V^0.16) Last edited by skyhawk; 7th May 2008 at 07:59 PM. |
|
|
|
|
|
|
#42 (permalink) |
|
New Member
Join Date: Apr 2008
Location: US
Posts: 21
![]() |
Hey guys, well I know it is isn't a good one for production by any means, but the pressure is on being that I am going to be demonstrating it on friday, and since my teacher gave me the equation i am going to use it. I am interested enough that I will work on it some more after but I figured out how to convert from MPH to KMPH
Thanks for all the input, I will let you know what happens. |
|
|
|
|
|
#43 (permalink) |
|
Experienced Member
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
To go from MPH to kMPH you multiply by 1.6
WC = (Temp+32)*5/9 - 1.6*Wind Speed/4 or, WC = (Temp+32)*5/9 - Wind Speed*2/5 So, your code would be, Temp=Temp+32 Temp=Temp+Temp*5 Temp=Temp/9 Speed=Speed*2 Speed=Speed/5 WC=Temp-Speed Do you need help with the actual code? Mike. Last edited by Pommie; 8th May 2008 at 11:16 AM. |
|
|
|
|
|
#44 (permalink) | |
|
New Member
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
![]() ![]() |
Quote:
Temp_F = 9*Temp_C/5 + 32 i.e. you multiply by 9/5 then add 32, not the other way around! To repeat an old theme, to do these conversions I would use table lookup rather than trying to to do the math. It may be very "old school", but use of retlw is a simple but effective way to look up values. Last edited by skyhawk; 8th May 2008 at 10:19 AM. |
|
|
|
|
|
|
#45 (permalink) |
|
New Member
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
![]() ![]() |
I just occurred to me that the conversion needs to go in the other direction. You have the temperature in Fahrenheit and want it in Celsius to use the formula.
Temp_C = 5*(Temp_F-32)/9. But rather than working in Fahrenheit at all, why not convert the analog signal directly to Celsius? Edit: OK you do need to display the temperature in Fahrenheit. Sorry! Last edited by skyhawk; 8th May 2008 at 10:45 AM. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Uni Project Advice | 2-tone | Electronic Projects Design/Ideas/Reviews | 7 | 18th October 2007 12:11 AM |
| My professor screwed my final electronics project! | kungfusansu | Electronic Projects Design/Ideas/Reviews | 21 | 26th August 2007 09:57 PM |
| RPM Counter (Project Started PIC16F877A) | Ayne | Micro Controllers | 28 | 2nd May 2007 01:53 PM |
| PIC16f877A Project help | Alex Ng | Micro Controllers | 5 | 26th July 2006 07:48 AM |
| A Microcontroller based Analogue Waveforms Analyzer Project | km | Electronic Projects Design/Ideas/Reviews | 76 | 30th June 2004 06:40 PM |