Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 30th April 2008, 09:49 AM   #31 (permalink)
Experienced Member
 
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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.
Pommie is online now   Reply With Quote
Old 30th April 2008, 04:36 PM   #32 (permalink)
New Member
 
Join Date: Apr 2008
Location: US
Posts: 21
engineergirl27 is on a distinguished road
Talking Thanks for the responses guys

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.
engineergirl27 is offline   Reply With Quote
Old 30th April 2008, 04:44 PM   #33 (permalink)
Experienced Member
 
 
Join Date: Jan 2007
Location: Toronto, Canada
Posts: 4,123
Blog Entries: 1
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

I used a CCP (capture) input for the output of the 555. You simply count the number of pulses in a set time to get the humidity.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now   Reply With Quote
Old 1st May 2008, 12:18 AM   #34 (permalink)
New Member
 
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
skyhawk is a jewel in the roughskyhawk is a jewel in the rough
Default

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.
skyhawk is offline   Reply With Quote
Old 1st May 2008, 02:39 AM   #35 (permalink)
Experienced Member
 
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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
Note that the routine can't return a value like 1.614971 (20^0.16) and so it returns this value multiplied by 256 (413). You can multiply this value by 35.75 to get 14764 and then divide by 256 to get 57. This is within 2% of the full accuracy calculation. If you keep all your terms multiplied by 256 and divide after they are summed you will maintain greater accuracy.

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.
Pommie is online now   Reply With Quote
Old 1st May 2008, 08:35 PM   #36 (permalink)
New Member
 
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
skyhawk is a jewel in the roughskyhawk is a jewel in the rough
Default

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.
skyhawk is offline   Reply With Quote
Old 2nd May 2008, 06:24 PM   #37 (permalink)
New Member
 
Join Date: Apr 2008
Location: US
Posts: 21
engineergirl27 is on a distinguished road
Default

Ok so looking at the website with the tables for heat index and wind chill, would it be possible to do a two dimensional look-up table. I am thinking it would be much easier,than those equations.

Elizabeth
engineergirl27 is offline   Reply With Quote
Old 3rd May 2008, 04:12 AM   #38 (permalink)
Experienced Member
 
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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 runs from -35°F to +140°F in steps of 5° and 0 to 100% RH in steps of 5. Note that I extended the table so each row contains 24 values to simplify the maths.

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.
Attached Files
File Type: zip LookupTable.zip (13.9 KB, 4 views)

Last edited by Pommie; 3rd May 2008 at 11:04 PM.
Pommie is online now   Reply With Quote
Old 7th May 2008, 04:59 PM   #39 (permalink)
New Member
 
Join Date: Apr 2008
Location: US
Posts: 21
engineergirl27 is on a distinguished road
Default

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
engineergirl27 is offline   Reply With Quote
Old 7th May 2008, 05:02 PM   #40 (permalink)
Experienced Member
 
 
Join Date: Sep 2007
Location: Vancouver, B.C.
Posts: 900
futz is a name known to allfutz is a name known to allfutz is a name known to allfutz is a name known to allfutz is a name known to allfutz is a name known to all
Default

Quote:
Originally Posted by engineergirl27
I have a simpler equation WC = Temp - Wind Speed/4, but this is for Celcius and km/hour,
http://www.onlineconversion.com/
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now   Reply With Quote
Old 7th May 2008, 07:53 PM   #41 (permalink)
New Member
 
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
skyhawk is a jewel in the roughskyhawk is a jewel in the rough
Default

Quote:
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.
It is clear looking from looking at a windchill chart that that is not a good approximation.

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.
skyhawk is offline   Reply With Quote
Old 8th May 2008, 03:01 AM   #42 (permalink)
New Member
 
Join Date: Apr 2008
Location: US
Posts: 21
engineergirl27 is on a distinguished road
Default

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.
engineergirl27 is offline   Reply With Quote
Old 8th May 2008, 03:17 AM   #43 (permalink)
Experienced Member
 
Join Date: Mar 2005
Location: Brisbane Australia
Posts: 3,237
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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.
Pommie is online now   Reply With Quote
Old 8th May 2008, 10:17 AM   #44 (permalink)
New Member
 
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
skyhawk is a jewel in the roughskyhawk is a jewel in the rough
Default

Quote:
Temp=Temp+32
Temp=Temp+Temp*8 (This is Temp * 9, to multiply by 8 we shift left 3 times)
Temp=Temp/5
Actually the conversion from Celsius to Fahrenheit is:

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.
skyhawk is offline   Reply With Quote
Old 8th May 2008, 10:30 AM   #45 (permalink)
New Member
 
Join Date: Feb 2007
Location: Morgantown, WV
Posts: 17
skyhawk is a jewel in the roughskyhawk is a jewel in the rough
Default

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.
skyhawk is offline   Reply With Quote
Reply

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


All times are GMT. The time now is 03:45 PM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.1.0 (Unregistered)