Shop OBEX P1 Docs P2 Docs Learn Events
Got a problem and i need help. — Parallax Forums

Got a problem and i need help.

biggin205biggin205 Posts: 2
edited 2004-12-10 05:55 in BASIC Stamp
Im trying to build a Temperature and light intensity sensor. the problem is that i cant get my temperature sensor to work worth a damn. It doesnt vary at all, i dont know if its hardware of software, im just not very good at this and i need help. Somebody help me please and make it quick if at all possible.

'
[noparse][[/noparse] Title ]
' TEMPERATURE AND LIGHT INTENSITY LOGGING IN RAM.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Constants ]
Kal···· CON·········· 35··························· ' Calibration constant for AD592.
Lical·· CON·········· 15··························· ' Calibration constant for photodiode.
'
[noparse][[/noparse] Declarations ]
log VAR Byte(18)··································· ' 18 bytes reserved for the log file.
rct VAR Word······································· ' Variable for RCTIME.
light VAR Word····································· ' Variable light intensity.
TC VAR Word········································' Variable for degrees Celsius from AD592.
n VAR Byte········································· ·' Counter for the pushbutton.
ptr VAR Byte······································ · ' Pointer to next entry in data log file.
'
[noparse][[/noparse] Pre-Program ]
OUTS=%0000000001000000
DIRS=%1111111111111001
DEBUG CLS
DEBUG "Ready to log data!", CR
SEROUT 2,16468,[noparse][[/noparse]254,12]
SEROUT 2,16468,[noparse][[/noparse]254,14]
SEROUT 2,16468,[noparse][[/noparse]"Ready to log data!"]
FREQOUT 0, 200, 2550
FREQOUT 0, 400, 3400
ptr = 0············································ ' Pointer initialization.
'
[noparse][[/noparse] Main Routine ]
DO························································ ' Main loop.
· DO
· LOOP UNTIL (IN1=0)······························· ' Loop here until button is pressed
· n = 0·················································· ·' Variable initialization.
· DO···················································· · ' Loop to track pressing time.
··· PAUSE 100
··· n = n + 1······································· ··· ' Increment counter.
· LOOP UNTIL (IN1=1 OR n>12)·················· ' Conditions to stop the loop.
· IF (n>=12) THEN·································· ·' Long click?
··· GOSUB Long_Click
· ELSEIF ptr>17 THEN······························· ' Short click but memory full?
··· GOSUB Memory_Full
· ELSE····························· ······················ ' Short click instructions.
··· GOSUB Get_Data
· ENDIF
LOOP············································ ········· ' Jump to the main loop.
'
[noparse][[/noparse] Subroutines ]
Long_Click:
· FREQOUT 0, 50, 2550································· ········ ' Feedback sound.
· FREQOUT 0, 100, 3400
· DEBUG CLS, "logged data!", CR, "degC",TAB,"Lux",CR
· FOR n=0 TO 16 STEP 2·········· ···························· ' Will show 9 records.
··· TC = log(n)······································· ··········· ' Get temperature.
··· light = log(n+1) * 2········································ '·Get light.
··· DEBUG DEC TC, TAB,·································· ··· ' Display.
········· DEC light, CR
· NEXT································ ··························· ' Next record of 9.
· DO·················································· ··········· ' Do nothing
· LOOP UNTIL (IN1=1)···································· ··· ' Until button is released
· DEBUG CR, "press RESET to erase data", CR
· SEROUT 2,16468,[noparse][[/noparse]254,12]
· SEROUT 2,16468,[noparse][[/noparse]"Connect to computer to see all readings,or press RESET to·· erase data."]
RETURN
Memory_Full:
· DEBUG CR, "memory full"····································· · ' Message.
· SEROUT 2,16468,[noparse][[/noparse]254,12]
· SEROUT 2,16468,[noparse][[/noparse]"Memory Full!"]
· FREQOUT 0, 50, 3400····················· ····················· ' Audio indication.
· FREQOUT 0, 200, 2000, 2100
RETURN
Get_Data:
· FREQOUT 0, 10, 1900····································· ·' Sound to show we got here.
· RCTIME 5, 0, rct············································ ' Read temperature probe.
· HIGH 5························································· ·' Discharge AD592 capacitor.
····································································· ' Calculate Celsius.
· TC = Kal / rct * 10 + (Kal // rct * 10 / rct) - 273
· log(ptr) = TC················································ · ' Store temperature.
· ptr = ptr + 1················································ ·· ' Point to next bin.
· RCTIME 6, 1, rct········································· ··· ' Read photodiode
· HIGH 6························································· ·' Discharge photodiode capacitor
···························· ····································· ' Calculate lux.
· light = 65535 / rct */ Lical
· log(ptr) = light/2 MAX 255········· ··················· ' Store light intensity/2.
· ptr = ptr + 1············································ ········ ' Point to next bin.
· DEBUG DEC TC, " C", TAB,·································· ·' Display values.
······· DEC light, " lux", CR
· SEROUT 2,16468,[noparse][[/noparse]254,12]
· SEROUT 2,16468,[noparse][[/noparse]DEC TC, " C",13]
· SEROUT 2,16468,[noparse][[/noparse]DEC light," LUX",13]
· PAUSE 400
RETURN

Post Edited (biggin205) : 12/10/2004 3:01:25 AM GMT

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2004-12-10 05:55
    In cases like this, where one gizmo doesn't work in the context of a large program, it often helps to use a minimum program and try to isolate the problem. Once you are sure that the hardware is working, then get back to the larger program.

    This is a program out of the last chapter of the Applied Sensors text. If you have not already, you might want to go back and try the small programs that introduce this sensor earlier in the book.


    p5 ----/\/\-----o-------[noparse][[/noparse]-AD590+]------ Vdd (+5 volts)
            100        |
                    ===== 0.22uF
                         |
                      Vss
                                            
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    result
    DO
       RCTIME 5, 0, result
     ' Read temperature probe.
      LOW 5                                                           ' Discharge AD592 capacitor.
      Debug ? result
      pause 500
    LOOP
    



    Try that and see if it works, that is, does the value of rct go down when the temperature goes up. Whoa! I see now that your program has a HIGH 5 there where it should be LOW 5. That could resolve the problem right there. Was it like that in the Applied Sensors text?

    The capacitor needs to be discharged to zero volts before executing the RCTIME command. If the voltage at p5 is already high when the RCTIME command is executed, then it will always return a result of 1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.