PDA

View Full Version : Displaying temperature Setpoints



Kalind
- 15th October 2008, 17:04
Hi Guys. I'm pretty new to picbasic pro. I've tried to create a temperature control system but having endless dead-ends. I've tried my best with the code and so far I managed to get the program to display the temperature. Adding in buttons though is what's giving me problems. Below is a copy of my program. Please help me somebody.


/Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
dEFINE LCD_BITS 4
DEFINE LCD_LINES 2

adval var word ' Create adval to store result
tempc var word ' Create tempc to store result
Setpoint var word
sethigh var byte
setlow var byte

Temp_Up var PORTC.0
Temp_Down var PORTC.1
High_sp var PORTC.2
Low_sp VAR PORTC.3
Main_disp VAR PORTC.4


TRISC = %11111111 ' Set PORTC to all input
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
ADCON0 = %11000001 ' Configure and turn on A/D Module
Pause 100 ' Wait 0.1 second

START:
if High_sp = 1 then gosub Set_High
IF Low_sp = 1 then gosub Set_Low
IF Main_disp = 1 then gosub Main
pause 10 '????????????? debounce how?

Keypress:
if Temp_Up = 1 then gosub Up_Loop
if Temp_Down = 1 then gosub Down_Loop


GOTO START

Main: ADCON0.2 = 1 ' Start Conversion

AGAIN: Pause 1

If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished

adval.highbyte = ADRESH ' Move HIGH byte of result to adval
adval.lowbyte = ADRESL ' Move LOW byte of result to adval

Lcdout $fe, 1 ' Clear screen
tempc=50*adval ' Conversion to Degrees
tempc=tempc/100
Lcdout "Temp = ",DEC tempc,$DF,"C" ' Display the value of temp

if Tempc > 100 then
lcdout "Out of range!"
endif
if Tempc < 0 then
lcdout "Out of Range!"
endif
Pause 1000 ' Wait 1 second

Goto Main ' Do it forever

Up_Loop:
If Temp_Up = 1 Then
Setpoint = Setpoint + 1
if Setpoint>100 then SetPoint=0
lcdout $fe, 1, "Setpoint = ", Setpoint
Pause 10
Else
Goto Keypress
Endif
Goto Up_Loop

Down_Loop:
If Temp_Down = 1 Then
Setpoint = Setpoint - 1
if Setpoint>0 then SetPoint=100
lcdout $fe, 1, "Setpoint = ", Setpoint
Pause 10
Else
Goto Keypress
Endif
Goto Down_Loop

Set_High: '?????????? Im trying to store the value
gosub Keypress '?????????? from the Temp_Up/Temp_Down.
write sethigh, Keypress '??????????

Set_Low: '?????????? Im trying to store the value
gosub Keypress '?????????? from the Temp_Up/Temp_Down.
write setlow, Keypress '??????????

end

mackrackit
- 15th October 2008, 17:33
Looking good.

Now go back here http://www.picbasic.co.uk/forum/showthread.php?t=9741
and re-read how to store and read the value.

If there is a part you do not understand ask a specific question, it will make it easier to help you.

skimask
- 15th October 2008, 17:35
Don't know what PIC you're using...so don't really know if that PIC has onchip eeprom or not...or what...

Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
mode var byte : keyin var byte : adval var word : tempc var word
highpt var byte : lowpt var byte : up var portc.0 : down var portc.1
sethighp var portc.2 : setlowp var portc.3 : maindisp var portc.4
trisc=$ff : trisa=$ff : adcon1=$82 : adcon0=$c1 : pause 100
mode = 1 : lcdout $fe , 1 : goto main
getkey: pause 50 : keyin = portc : return
gettemp: adcon0.2=1 : pause 1
checkdone: if adcon0.2=1 then checkdone
adval.highbyte=adresh : adval.lowbyte=adresl : tempc=(50*adval)/100 : return
main: gosub gettemp : gosub getkey
if maindisp = 1 then
write 0 , sethighp : pause 10 : write 1 , sethighp : mode = 1
endif
if sethighp = 1 then mode = 2
if setlowp = 1 then mode = 3
select case mode
case 1
lcdout $fe , $80 , "Temp = ", DEC3 tempc , $DF , "C"
case 2
lcdout $fe , $80 , "High Pt=" , $fe , $c0 , highpt
if up = 1 then highpt = highpt + 1
if down = 1 then highpt = highpt - 1
case 3
lcdout $fe , $80 , "Low Pt=" , $fe , $c0 , lowpt
if up = 1 then lowpt = lowpt + 1
if down = 1 then lowpt = lowpt - 1
end select
goto main

If that doesn't give you some ideas...nothing will...
But remember, I SUCK! DUDE!

P.S. Your program has been COLONized! In the process of De-COLONizing the code above and figuring out what goes where, you might learn something...

skimask
- 15th October 2008, 17:37
Looking good.
????????????????????????????????????????????????



if Tempc < 0 then
lcdout "Out of Range!"
endif


That looks REAL good! for one thing...

mackrackit
- 15th October 2008, 17:43
????????????????????????????????????????????????



if Tempc < 0 then
lcdout "Out of Range!"
endif


That looks REAL good! for one thing...
Well maybe I should have said looking better? At least the OP has code that looks like he wrote.

skimask
- 15th October 2008, 17:55
At least the OP has code that looks like he wrote.
Now, I'll admit, sometimes there's only one way to do something, and sometimes there are hundreds of ways of doing something...but...
http://www.picbasic.co.uk/forum/showthread.php?t=8804&highlight=down_loop
See anything in there? :)

mackrackit
- 15th October 2008, 18:43
Now, I'll admit, sometimes there's only one way to do something, and sometimes there are hundreds of ways of doing something...but...
http://www.picbasic.co.uk/forum/showthread.php?t=8804&highlight=down_loop
See anything in there? :)
There goes the benefit of doubt.

Kalind
- 15th October 2008, 18:55
what's post #3 all about ski? Im using a 16f873.

skimask
- 15th October 2008, 19:21
what's post #3 all about ski? Im using a 16f873.
Wow....first I've seen of it here...unlike those other 6 threads...

Kalind
- 20th October 2008, 12:07
well, this is what i managed to do. i hooked it up to my circuit but the program isnt doing what i wanted it to do. Skimask?

/code

Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

mode var byte
keyin var byte
adval var word
tempc var word
highpt var byte
lowpt var byte
up var portc.0
down var portc.1
sethighp var portc.2
setlowp var portc.3
maindisp var portc.4
trisc=$ff
trisa=$ff

adcon1=$82
adcon0=$c1
pause 100

mode = 1
lcdout $fe , 1
goto main

getkey:
pause 50
keyin = portc
return

gettemp:
adcon0.2=1
pause 1

checkdone:
if adcon0.2=1 then checkdone

adval.highbyte=adresh
adval.lowbyte=adresl
tempc=(50*adval)/100
return

main:

gosub gettemp

gosub getkey

'saving part
if maindisp = 1 then
write 0 , sethighp
pause 10
write 1 , sethighp
mode = 1

endif

if sethighp = 1 then mode = 2
if setlowp = 1 then mode = 3

select case mode

case 1
lcdout $fe , $80 , "Temp = ", DEC3 tempc , $DF , "C"

case 2
lcdout $fe , $80 , "High Sp=" , $fe , $c0 , highpt
if up = 1 then highpt = highpt + 1
if down = 1 then highpt = highpt - 1

case 3
lcdout $fe , $80 , "Low Pt=" , $fe , $c0 , lowpt
if up = 1 then lowpt = lowpt + 1
if down = 1 then lowpt = lowpt - 1
end select
goto main

skimask
- 20th October 2008, 13:36
well, this is what i managed to do.
Looks like it's pretty much what I managed to do...


i hooked it up to my circuit but the program isnt doing what i wanted it to do.
It might help for you to tell us exactly what it IS or isn't doing...

Kalind
- 20th October 2008, 13:53
taking your advice with the program, i hooked it up and on the lcd it prompts the user to enter a LOW SP. upon the use of the increment decrement buttons, on the second line of the lcd are characters which are being displayed. when the 'main' button is pressed, it does not go to the main display and also when the HighSp button is pressed, it does not go to that screen. im so lost with this whole thing

aratti
- 20th October 2008, 14:05
Put yours subrouteenes at the end of your code, never at the beginning!

Modify your If then in the following manner:

if maindisp = 1 then
write 0 , sethighp
pause 10
write 1 , sethighp
mode = 1
maindisp = 0 ' reset flag
endif

Otherwise it will write at every cycle and in this case you do not need the " IF Then " statement. Set your flag to 1 when writing is needed

Yours code for reading key:

getkey:
pause 50
keyin = portc
return

You read the status of the all 8 inputs, than you need to decode to find which key has been pressed.


More:

Are you pulling up your inputs using normally closed switches? otherwise with this code you have to pull down your inputs.
Al.

skimask
- 20th October 2008, 14:10
Ok, are you sure all of your buttons are working properly?

skimask
- 20th October 2008, 14:14
Put yours subrouteenes at the end of your code, never at the beginning!
Disagree 100%, ok maybe 99% :)
If using a PIC16 (or 12,or 10) series PIC, if you are able to keep the 'subroutines' in the first bank of code space, you'll save code space due to the fact that the BANK Select registers don't need to be changed, and at the same time save instruction cycles. And if your subroutines are at the beginning, they're the first thing to get seen while skimming thru the code, makes them harder to forget them (I guess more of a brain thing there).

At any rate, there's one more small bug in your If/Then correction above (post #13)...a small one...actually two small bugs...one matters, the other doesn't really matter...

Kalind
- 20th October 2008, 14:14
yup. They connected from +5v to ground using a 10K

skimask
- 20th October 2008, 14:16
yup. They connected from +5v to ground using a 10K
No, what I mean is, how do you know the PIC and/or your code is actually recognizing the buttons as pressed or not-pressed.
Again, just 'cause you want it doesn't mean it...
And what do you mean from +5v to ground using 10K? Leaves a bit to the imagination...

Kalind
- 20th October 2008, 14:24
check the button pic. that is how i connected it ski

skimask
- 20th October 2008, 14:27
check the button pic. that is how i connected it ski
button pic...hmmm...what button pic?

skimask
- 20th October 2008, 14:31
Humour me for a bit...


Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
keyin var byte : trisc=$ff : pause 1000 : lcdout $fe,1
main: keyin = portc : lcdout $fe, $80, BIN8 keyin : goto main
end

Push the buttons, what happens?

Kalind
- 20th October 2008, 14:41
should display binary number

skimask
- 20th October 2008, 14:48
should display binary number
And does it?

Kalind
- 20th October 2008, 14:53
i dont know..this isnt the main concern...lets get back to reality

skimask
- 20th October 2008, 15:18
i dont know..this isnt the main concern...lets get back to reality
Not the main concern? Where are you at? Happy-ville where everything works the 1st time according your wishes?
That little 'display a binary number' program would verify that all of your buttons actually work and change states. If your buttons don't work in the first place, which you're not 100% sure they do, you just say they do because they're connected, how do you expect the rest of the program to follow suit?
Get back to reality? Here's a bit of reality for you... I was all set to lead you from one place to the next to the end, with a ready-made program, and figured you might learn a little bit of something along the way.
Here's the reality part...How about you finish this project on your own? Then let us know how that goes for you?
Maybe somebody else with a bigger heart will come along, write the code to exactly watch your specifications and your hardware, debug it, test it under all known conditions, then drop by your house some weekend, with a finished PCB, a CD with all of the code on it, fully commented and explained in a long long video, and might even bring a 6-pack of your favorite beverage, and a large pizza from the local vendor.
As Dennis Miller used to say on Saturday Night Live back in the day "That's the news, and I am outta here!!!"

Kalind
- 20th October 2008, 15:24
myself. Sticking to the basics.

Kalind
- 21st October 2008, 09:10
Does this make any sense? (Well to me it does) At the moment, nothing appears on the LCD. Please could somebody tell me what I need to add/delete to obtain success from this code.

Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

tempc var word
tempc1 var word
Conv1 Con 4
Conv2 Con 82/100
mode var byte
keyin var byte
adval var word
highpt var byte
lowpt var byte
up var portc.0
down var portc.1
sethighp var portc.2
setlowp var portc.3
maindisp var portc.4
trisc=$ff
trisa=$ff

adcon1=$82
adcon0=$c1
pause 100

main:

gosub checkdone

gosub getkey

checkdone:
if adcon0.2=1 then checkdone

adval.highbyte=adresh
adval.lowbyte=adresl
Lcdout $fe, 1
tempc = adval * Conv1
tempc1 = adval * Conv2
tempc = tempc + tempc1
pause 1000
return

getkey:
pause 50
keyin = portc
return

if maindisp = 1 then
write 0 , sethighp
pause 10
write 1 , sethighp
LCDOut "TEMP = ", dec(tempc / 10), ".", dec1 (tempc // 100), $DF , "C"
endif

if maindisp = 1 then
write 2 , setlowp
pause 10
write 3 , setlowp
LCDOut "TEMP = ", dec(tempc / 10), ".", dec1 (tempc // 100), $DF , "C"
endif

if sethighp = 1 then gosub setsetpointh
if setlowp = 1 then gosub setsetpointl

setsetpointh:

lcdout $fe , $80 , "High Sp=" , $fe , $c0 , dec highpt
if up = 1 then highpt = highpt + 1
if down = 1 then highpt = highpt - 1
return

setsetpointl:

lcdout $fe , $80 , "Low Pt=" , $fe , $c0 , dec lowpt
if up = 1 then lowpt = lowpt + 1
if down = 1 then lowpt = lowpt - 1
return

goto main

skimask
- 21st October 2008, 14:06
Does this make any sense? (Well to me it does) At the moment, nothing appears on the LCD. Please could somebody tell me what I need to add/delete to obtain success from this code.


i dont know..this isnt the main concern...lets get back to reality
The reality is that you don't read and/or follow thru your own code (or somebody else's code for that matter)...
If you did, you'd find at least 2 hard 'breaks' and 5 'bugs'...

Kalind
- 21st October 2008, 15:03
i've read thru it many times. im no programmer. i'll admit to taking snips from others and to me it makes sense. the main temperature measurement part is mine. the button fuctions is not but i tried to make sense of it all. please just guide me to eliminating the errors

skimask
- 21st October 2008, 18:09
please just guide me to eliminating the errors
Gimme this...gimme that...gimme gimme gimme...I got a kid on the way and I figured I'd have to wait about 2-3 years before I got to listen to that. Apparently not...

I tried to do the guiding thing. You told me to get back to reality, so I did...

Kalind
- 22nd October 2008, 07:23
what joy do u get out of being spiteful? all im askin for is guidance..

mackrackit
- 22nd October 2008, 08:09
all im askin for is guidance..
If you are wanting to learn, then go back to post #2,3 and 20.
If you are wanting someone to do the project for you just say so. It will save us all a lot of time.

Kalind
- 22nd October 2008, 16:49
just want to apologise for asking too much. i manage to get the thing working. just have to try tweak here and there...

skimask
- 23rd October 2008, 03:17
just want to apologise for asking too much. i manage to get the thing working. just have to try tweak here and there...
And what ended up fixing the problem?

Kalind
- 23rd October 2008, 06:15
well, the button where connected incorrectly. that being my partners fault. also a few things in the program which where so obvious.. now im gona add in buzzer for high/low and also relays to switch loads at certain temps.

Kalind
- 23rd October 2008, 08:11
BIG PROMLEM!!! After adding on all the extra's (relay code, leds...etc), the pic is operating at snails pace!!! What do i do about this now??

mackrackit
- 23rd October 2008, 08:50
BIG PROMLEM!!! After adding on all the extra's (relay code, leds...etc), the pic is operating at snails pace!!! What do i do about this now??
Did you DEFINE the OSC or mes with the configs?

Post you code so we can take a look.

Kalind
- 23rd October 2008, 09:20
im using a 4mhz crystal oscillator. I did define it in ADCON0. Bit 6-7 as 11. i would also like to know what difference would there be if i had to amplify the output signal from the LM35. and if i did, please explain to me whether i'd be getting more accurate results? N.B. 16F873

Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

mode var byte
keyin var byte
adval var word
tempc var word
highpt var byte
lowpt var byte
highled var porta.1
lowled var porta.2
relayhigh var porta.3
relaylow var porta.4
buzzer var porta.5
up var portc.0
down var portc.1
sethighp var portc.2
setlowp var portc.3
maindisp var portc.4
highpt = 100
lowpt = 0
trisc= %00011111
trisa=%00000001
adcon1=%11110010
adcon0=%11000001

pause 100

lcdout $fe , 1
mode = 1
goto main

getkey:
pause 50
keyin = portc
return

gettemp:
adcon0.2=1
pause 1

checkdone:
if adcon0.2=1 then checkdone

adval.highbyte=adresh
adval.lowbyte=adresl

tempc=50*adval
tempc=tempc/100

If tempc>=highpt then
gosub high_flash
SOUND buzzer, [60, 100, 23, 200]
relayhigh = 1
else
relaylow = 0
lowled = 0
buzzer = 0
endif

If tempc<=lowpt then
gosub low_flash
SOUND buzzer, [20, 100, 23, 200]
relaylow = 1
else
relayhigh = 0
highled = 0
buzzer = 0
endif

return

main:
gosub gettemp
gosub getkey

if maindisp = 0 then mode = 1
pause 50
if sethighp = 0 then mode = 2
pause 50
if setlowp = 0 then mode = 3
pause 50

select case mode

case 1
write 0 , sethighp
pause 10
write 1 , setlowp
lcdout $fe , 1
Lcdout "TEMP = ",DEC tempc,$DF,"C"

case 2
lcdout $fe , 1
lcdout $fe , $80 , "High Setpoint:" , $fe , $c0 , dec highpt, $DF , "C"
if up = 0 then highpt = highpt + 1
if down = 0 then highpt = highpt - 1
if highpt>100 then highpt=0

case 3
lcdout $fe , 1
lcdout $fe , $80 , "Low Setpoint:" , $fe , $c0 , dec lowpt, $DF , "C"
if up = 0 then lowpt = lowpt + 1
if down = 0 then lowpt = lowpt - 1
if lowpt>100 then lowpt=0
end select
goto main

high_flash:
HIGH highled
PAUSE 350
LOW highled
PAUSE 350
RETURN

low_flash:
HIGH lowled
PAUSE 350
LOW lowled
PAUSE 350
RETURN

mackrackit
- 23rd October 2008, 10:01
im using a 4mhz crystal oscillator. I did define it in ADCON0. Bit 6-7 as 11. i would also like to know what difference would there be if i had to amplify the output signal from the LM35. and if i did, please explain to me whether i'd be getting more accurate results? N.B. 16F873

You define the oscillator


DEFINE OSC 4

but PB defauts to 4 so you should be good there.

The LM35 does not need amplification. If it is giving a fluctuation on the reading a capacitor between the signal and 0 volts (ground) will fix that.

Still looking through you code...
When it gets to the LED blinking, do they blink at the correct speed? Or are you seeing slow running some place else?

Kalind
- 23rd October 2008, 10:11
there entire device has slowed down. temperature changes used to be instantaneous. going into the different menu's were instantaneous. for some odd reason every has slowed down.

About the amplification, wouldnt it affect the resolution of the measurement?

mackrackit
- 23rd October 2008, 10:32
there entire device has slowed down. temperature changes used to be instantaneous. going into the different menu's were instantaneous. for some odd reason every has slowed down.So when you press a button it takes a bit for anything to happen?

I do not see anything obvious in you code other than it is doing a lot of things now that take time. Takes a little time to get back to the button. To make the buttons react faster you will want to explore interrupts.


About the amplification, wouldnt it affect the resolution of the measurement?
No.
The resolution is controlled by the ADC, 8 or 10 bit, and the VREF (voltage reference)
This link goes to a volt meter
http://rentron.com/serial.htm
but that is all a LM35 is (sort of)
Bruce has a good explanation about how to read a voltage and display it.

Kalind
- 23rd October 2008, 10:43
yeah it takes abit longer than before to do stuff. im really concerned as to why this is happening bcause it kinda defeats the purpose of intantaneous measurement. Is there anything you would recommend? Should i maybe try change the oscilator to fosc/32? would that help?

mackrackit
- 23rd October 2008, 11:06
Still looking...And it is getting late

What does this part do for you?


getkey:
pause 50
keyin = portc

Kalind
- 23rd October 2008, 11:34
provides debounce for buttons connected to portc

skimask
- 23rd October 2008, 13:48
Well, since those buttons seemed to work out so well (refer to post #20 and post #34), do you want to humour me a little bit more?


Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
keyin var byte : adval var word : tempc var word : trisa=1 : trisc=$1f
highled var porta.1 : lowled var porta.2 : adcon1=$f2 : adcon0=$c1
pause 1000 : lcdout $fe,1 : goto main
main: adcon0.2=1 : pause 1
checkadc: highled=1:if adcon0.2 = 1 then checkadc
highled=0:adval.highbyte=adresh : adval.lowbyte=adresl : tempc=(50*adval)/100
pause 50 : keyin = portc : temp = temp + 1 : lowled=temp.3
lcdout $fe,1,"T=",DEC5 tempc,$DF,"C",$fe,$c0,BIN8 keyin : goto main
end

What happens?

Kalind
- 23rd October 2008, 14:10
hey guys. i just realised that everything is fine until the actual temperature reaches the respective setpoints. thats when the design starts to really slow down during its operation. i cant seem to understand why this is so.

Refering to post #44

looks like temperature being measured...

keyin = portc : temp = temp + 1 : lowled=temp.3


not sure about that though..

on the lcd will be displayed temperature on the first line and i assuming the binary value of keypressed on line 2

skimask
- 23rd October 2008, 14:28
hey guys. i just realised that everything is fine until the actual temperature reaches the respective setpoints. thats when the design starts to really slow down during its operation. i cant seem to understand why this is so.
Gee....Ya think? You wrote the code (or did you?), you should know why it happens...



...................
If tempc>=highpt then
gosub high_flash
....................
If tempc<=lowpt then
gosub low_flash
.....................
high_flash:
HIGH highled
PAUSE 350
LOW highled
PAUSE 350
RETURN

low_flash:
HIGH lowled
PAUSE 350
LOW lowled
PAUSE 350
RETURN

How long do you suppose it takes each of those last 2 chunks of code to execute?
Better yet...how long does it take for a PAUSE 350 to execute?

Kalind
- 23rd October 2008, 14:39
less than half a second.....what r u getting at ski?

skimask
- 23rd October 2008, 15:02
less than half a second.....what r u getting at ski?

WHAT HAPPENS EVERY TIME YOUR CODE FALLS THRU TO ONE OF THOSE FLASHING LED SUBROUTINES?
How long does it take for each one of those subroutines to execute once they're started (i.e. Gosub'd to and returned from)?
It happens on each time around the loop after the temperature has exceeded the set point.
How fast can your buttons/lcd/the-rest-of-the-program possibly run if it's tied up in a pause for 700ms on each run through the loop.
JEEZE MAN!!! READ THRU YOUR OWN CODE FOR ONCE!!!! What did you do? Cut and paste this from somewhere else? How about getting your FRIEND to help you out more...if this friend actually exists...you know, the same one that HELPED you with those buttons earlier...
Screw it...I'm done...really...this is about as annoying and frustrating as it can possibly get...the only thing that could be worse would be if your name/handle was TED's, but then again, that was more funny than annoying.

Kalind
- 23rd October 2008, 15:24
It's for the same reason that I removed those two routines and decided to just make those pins high instead. the same thing happens...

skimask
- 23rd October 2008, 16:05
It's for the same reason that I removed those two routines and decided to just make those pins high instead. the same thing happens...
I tried, in one last vain attempt to draw your attention to something that might be slowing down your whole project.
But, I can see that I've failed again, because you've failed AGAIN...or maybe just YOU have FAILED to READ your OWN code...AGAIN!

You don't think those 2 SOUND statements, with their ~3 seconds of sound making might not have anything to do with anything?

Ok, now I'm done... Some people you just can't prod into looking at their own stuff closer...because it's all good. Of course it's all good...they wrote it...how can they possibly be wrong or mistaken about anything? Their logic is great...it flows in the code just like it does in their minds...Or does it?!?!?!?!!!!????

Why don't you go ask your instructor for advise... You've got 48 hours...

Kalind
- 24th October 2008, 09:18
ski, i removed both of those flashing routines and the problem was still there. then i removed the SOUND statements aswel. seemed to have sorted out the lag issue. the problem is that now i have only a high led and low led when the setpoints are reached but thats not even working


checkdone:
if adcon0.2=1 then checkdone

adval.highbyte=adresh
adval.lowbyte=adresl

tempc=50*adval
tempc=tempc/100

If tempc>=highpt then
gosub high_flash
SOUND buzzer, [60, 100, 23, 200]
relayhigh = 1
else
relaylow = 0
lowled = 0
buzzer = 0
endif

If tempc<=lowpt then
gosub low_flash
SOUND buzzer, [20, 100, 23, 200]
relaylow = 1
else
relayhigh = 0
highled = 0
buzzer = 0
endif

return

mackrackit
- 24th October 2008, 10:15
I still see sound in that snippet and the leds are = 0 ???

Kalind
- 24th October 2008, 11:36
what i meant was that i removed those lines of code. now im using the following which is without the other features i was planning to implement. below is the latest code.


Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 5
Define LCD_EREG PORTB
Define LCD_EBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

mode var byte
keyin var byte
adval var word
tempc var word
highpt var byte
lowpt var byte
highled var porta.1
lowled var porta.2
relayhigh var porta.3
relaylow var porta.4
up var portc.0
down var portc.1
sethighp var portc.2
setlowp var portc.3
maindisp var portc.4
highpt = 100
lowpt = 0
trisc= %00011111
trisa=%00000001
adcon1=%10001110
adcon0=%11000001

pause 100

lcdout $fe , 1
mode = 1
goto main

getkey:
pause 50
keyin = portc
return

gettemp:
adcon0.2=1
pause 1

checkdone:
if adcon0.2=1 then checkdone

adval.highbyte=adresh
adval.lowbyte=adresl

tempc=50*adval
tempc=tempc/100

If tempc>=highpt then
high highled
high relayhigh
else
low relaylow
low lowled

endif

If tempc<=lowpt then
high lowled
low relaylow
else
low relayhigh
low highled

endif

return

main:
gosub gettemp
gosub getkey

if maindisp = 0 then mode = 1
pause 50
if sethighp = 0 then mode = 2
pause 50
if setlowp = 0 then mode = 3
pause 50

select case mode

case 1
write 0 , sethighp
pause 10
write 1 , setlowp
lcdout $fe , 1
Lcdout "TEMP = ",DEC tempc,$DF,"C"

case 2
lcdout $fe , 1
lcdout $fe , $80 , "High Setpoint:" , $fe , $c0 , dec highpt, $DF , "C"
if up = 0 then highpt = highpt + 1
pause 50
if down = 0 then highpt = highpt - 1
pause 50
if highpt>100 then highpt=100
pause 50

case 3
lcdout $fe , 1
lcdout $fe , $80 , "Low Setpoint:" , $fe , $c0 , dec lowpt, $DF , "C"
if up = 0 then lowpt = lowpt + 1
if down = 0 then lowpt = lowpt - 1
if lowpt>100 then lowpt=100
end select
goto main


im realy desperate to get this thing working guys....

mackrackit
- 24th October 2008, 11:46
Looks like you removed the command to goto

checkdone:

Kalind
- 24th October 2008, 11:59
but there was no command prior to this that said goto checkdone. . .

mackrackit
- 24th October 2008, 12:10
but there was no command prior to this that said goto checkdone. . .
OOPPS, gettemp runs into checkdone.

Do the relays work?

Kalind
- 24th October 2008, 12:42
well, i tested the relay port using a multimeter and there seems to be no voltage output when tempc>=highpt and the same goes for he highled port.

mackrackit
- 24th October 2008, 12:57
In post #37 the code worked but was slow.
In post #43 the outputs on PORTA does not work.

ADCON1 and ADCON0 has been changed between the two post??

Kalind
- 27th October 2008, 14:52
well i thought by changing the oscillator settings it would sought out th delay but obviously no change. im trying to do some code concerning high led and low led outputs. will post it by the end of today. please take a look at it and let me know if im going the right path