Beruflich Dokumente
Kultur Dokumente
ForumHelp
Profile
OfficialCCSSupport
Search
Logintocheckyourprivatemessages
Login
Register
CCSdoesnotmonitorthisforumonaregularbasis.
PleasedonotpostbugReportsonthisforum.Sendthemto
support@ccsinfo.com
3:0FRQWUROZLWKLQSXWIURP$'&
CCSForumIndex>GeneralCCSCDiscussion
Viewprevioustopic::Viewnexttopic
Author
Message
adhemp
PWMcontrolwithinputfromADC
Posted:ThuApr05,20076:06pm
Heyguys,I'mcurrentlyworkingontemperaturesensingprojectwhereIwouldliketoalterthedutycyclecomingfrom
myPIC(16F877)basedonthetemperaturereadfromathermistor.Ihavethethermistorasonelegofavoltage
Joined:05Apr2007
Posts:3
dividercircuitwho'svoltageoutputissenttoanopampforbuffering,thentotheADCofthePIC.
I'mnotsureifI'mmissingsomethingsimpleinmyADCcodeorwhat,butifyoucouldtakealookandofferany
suggestionsthenI'dbemostappreciative...thanks!
Code:
LQFOXGH)K!
GHYLFHDGF
IXVHV+612:'7123527(&712/93%52:1287387
XVHGHOD\FORFN 0+]
YRLGLQLWB$'&YRLG
YRLGPDLQ^
LQWYDOXHYROWDJHELWYDOXHIRU$'&UHDGLQJ
VHWBWULVBDEGHVLJQDWHSRUW$IRUWKHUPLVWRUVDVDOOLQSXWVIURP
WKHUPLVWRUV
LQLWB$'&
ZKLOH758(
^
GHOD\BPV
RXWSXWBORZ3,1B&6HW&&3RXWSXWORZ
VHWXSBFFS&&3B3:0&RQILJXUH&&3DVD3:0
VHWXSBWLPHUB7B',9B%<B+]
YDOXH UHDGB$'&UHDGLQYROWDJHIURPWKHUPLVWRU
YROWDJH YDOXH
LIYROWDJH!VZLWFKLQJYROWDJHLQYROWDJHGLYLGHU
FLUFXLW
VHWBSZPBGXW\GXW\F\FOHRQSLQ&
LIYROWDJH
VHWBSZPBGXW\GXW\F\FOHRQSLQ&
`
`
YRLGLQLWB$'&YRLG
^
VHWXSBDGFBSRUWV$B$1$/2*$$$5HI 9GG
VHWXSBDGF$'&B&/2&.B,17(51$/
VHWBDGFBFKDQQHO6HWV$BWRB'LQSXWWRFKDQQHO3LQRQ3,&
GHOD\BXV
`
PCMprogrammer
Posted:ThuApr05,200711:26pm
HereisalinktoademoprogramthatshowshowtoreadtheA/D
anddisplaytheresultasavoltage.
Joined:06Sep2003
Posts:19034
http://www.ccsinfo.com/forum/viewtopic.php?t=28842&start=7
Thatprogramisn't100%applicabletoyourproblem,butitmighthelp.
Here'sabetteridea.You'rerunningtheA/Din10bitmode,and
presumablyyourboardisrunningat+5v.SotheA/Dvalueread
fora+5vinputwillbe1023.Fora0voltinput,itwillbe0.
For3volts,itwillbe(3/5)*1023=approximately614.
Youdon'tneedtoconverttherawA/Dvaluetoasingledigit"volts"
value.Youalreadyknowthatifyouread614,it'sat3.0volts.
Soyoucandefineaconstantthatrepresentsthe3vlevel.Thenuse
thatconstantinyourcode:
Code:
GHILQH$'&BB92/76
Code:
YDOXH UHDGBDGF
LIYDOXH!$'&BB92/76
^
'RVRPHWKLQJ
`
Also,youneedtolookabitmorecloselyatyourlogicinthecode
thatsetsthePWMdutycycle.Whatifthevoltageisexactly3volts?
Yourcodedoesn'thandlethatstate.
Whatifthevoltagechangesslightlyeveryfewmilliseconds,dueto
noise?Whatifonemomentit's2.95volts,andthenit's3.01volts,etc.
Yourprogramwouldconstantlydofairlylargechangesindutycycle.
Youneedtolookintotheconceptof"hysteresis".
Lastly,doyoureallyneed10bitsofresolution?It'spossiblethatthe
bottomoneortwobitsmightbenoise,anyway.Itmightbebetterto
usetheA/Din8bitmodeandjustreadavaluefrom0to255fromit.
Idon'tknowyourrequirements,sothat'sjustasuggestion.
adhemp
Joined:05Apr2007
Posts:3
Posted:FriApr06,20073:35pm
Thanksforyourhelp...I'mnowabletoswitchbetweendutycyclesbasedonchangingvoltageinthedividernetwork.I
ranintoanotherproblemtodaythatIcouldn'tquiteunderstand.TheinputintotheADConthePICisinitially~3.8V,
measuredwithanoscilloscope.
IfIrunthefollowingcode:
Code:
LIYROWDJH! $'&BB92/76VZLWFKLQJYROWDJHLQYROWDJHGLYLGHUFLUFXLW
VHWBSZPBGXW\GXW\F\FOHRQSLQ&
LIYROWDJH$'&BB92/76 YROWDJH! $'&BB92/76
VHWBSZPBGXW\GXW\F\FOHRQSLQ&
LIYROWDJH$'&BB92/76
VHWBSZPBGXW\GXW\F\FOHRQSLQ&
thenIwouldexpecttohaveadutycycleof50%showninitially.However,thedutycyclebeginsat75%andthen
switchesto50%atapproximately3.4V.Oddly,thetransitionbetweenthe50and15%dutycyclesoccursat3V,as
expected.
Doyouknowwhythisinitialdutycyclewouldbeoffbutthesecondtransitionat3Vwouldnotbe?
Thanks!
PCMprogrammer
Posted:FriApr06,20074:25pm
1.Postthe#definestatementsforthoseconstants.
Joined:06Sep2003
Posts:19034
2.Verifythattheoscilloscopeiscalibratedproperlybycheckingthe
A/Dinputvoltagewithavoltmeter(assumingit'saDCvoltage).
adhemp
3.MeasuretheVddvoltageforyourPICwithavoltmeter.Isit5.0v?
Posted:SatApr07,20073:23pm
Figureditout...sillymistakeonmypartinhowIdefinedmyconstants.Thanksforyourhelp.
Joined:05Apr2007
Posts:3
Displaypostsfromprevious: AllPosts
OldestFirst
Go
CCSForumIndex>GeneralCCSCDiscussion
AlltimesareGMT6Hours
Page1of1
Jumpto: GeneralCCSCDiscussion
Go
Youcannotpostnewtopicsinthisforum
Youcannotreplytotopicsinthisforum
Youcannotedityourpostsinthisforum
Youcannotdeleteyourpostsinthisforum
Youcannotvoteinpollsinthisforum
PoweredbyphpBB2001,2005phpBBGroup