![]() |
![]() |
![]() |
|
|
|||||||
| Electronic Projects Design/Ideas/Reviews Are you building an electronic project or want to? Maybe you need some assistance? Come and submit your electronic questions here and let our experienced members find a solution. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Can someone please have a read through this and tell me if I've made any mistakes as I dont have a method for testing yet.
Hopefully I've written it in Picbasic Pro ( I hope) What its supposed to do is compare inputs B1 and B4 and IF they are BOTH high then make outputs B2 and B5 high and at the same time get the LCD on line 1 to display the word VEG-OIL IF a pushbutton switch (on Input B6) is pressed then outputs B2 goes LOW and B5 stays HIGH and the LCD displays the word FLUSHING for a period of 10 seconds then both outputs B2 AND B5 go LOW and at the same time the LCD displays the word DIESEL When the program starts the LCD display clears the screen, waits a period of 1 second then Line 1 displays the above, while LINE 2 displays the temperature as measured by the 3rd DS1620 continually while the PIC is powered up. I wont claim to have written this code, most of it is borrowed from other examples online from various places ,all I did was modify the bits I wanted and HOPE it works! Can anyone tell me the easiest PIC for this to work in, or if any code or pins need changing to work with other pics? I based it all on the 16F877 ( i think) and please bear with me, I've pnly started getting interesting in programming PIC's in the last week and uptill today knew nothing about programming. By the way, IF this does actually appear to work could anyone compile it for me please? Last edited by karenhornby; 3rd March 2008 at 01:26 AM. |
|
|
|
|
|
|
(permalink) |
|
You didn't include your code. May I suggest that you enclose it in [code] tags. By typing [code] and [/co de] (without the space) before and after your code, it makes it a lot easier to read.
Mike. Edit, I see you added it now so ignore the above. Last edited by Pommie; 3rd March 2008 at 01:28 AM. |
|
|
|
|
|
|
(permalink) |
|
Sorry I'm only starting to learn about programming and dont even have a programmer as yet!
HOPEFULLY this is what you mean... Code:
' PicBasic Pro program to read DS1620 3-wire temperature sensor connected to PORTC.0
‘PORTC.1 and PORTC.2
' and display temperature on 2nd line of LCD AND display fuel state on LCD line 1
‘inputs are PORTB1 (DS1620) PORTB4 (DS1620) and PORTB6 (pushbutton switch)
‘Outputs are PORTB1 (SOLENOID 1) PORTB5 (SOLENOID 2) and LCD Display 2 X 16 or 2 X 20 in 4 bit mod
‘IF PORTB.6 = 1 the switch is closed on pin RB6 (pushbutton pressed)
‘IF and ONLY IF BOTH DS1620’s connected to PORTB.1 AND PORTB.4 are HIGH then BOTH OUTPUTS on PORTB.2 and ‘PORTB.5 are set HIGH driving (through a transistor switch) a relay on each OUTPUT port.
‘IF the switch is closed on PORTB.6 then OUTPUTS on PORTB.1 goes LOW and PORTB.5 goes HIGH AND the display ‘shows the word FLUSHING for a period of 10 seconds and then all outputs reset to a LOW state and LCD displays the ‘word DIESEL
‘”HOPEFULLY” and hopefully using a 16F877 PIC CHIP
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe, 1, “DIESEL” $C0 "Temp in degrees C" ' Display sign-on message
input PORTB.1
output PORTB.2
input PORTB.4
output PORTB.5
input PORTB.6
output PORTB.7
MAIN
if PORTB.1=1 then
if PORTB.4=1 then
if PORTB.6=0 then SOLENOID
Endif
If PORTB.1=1 then
If PORTB.4=1 then
If PORTB.6=1 then PURGE
Endif
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto Temploop ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.2 1
Output PORTB.5 0
Lcdout $fe “FLUSHING”
Pause 1000 ’10 second hold before solenoids are reset
Output PORTB.2 0
Output PORTB.5 0
Lcdout $fe “Diesel”
‘SOLENOID send outputs to solenoids and display fuel state on LCD
SOLENOID:
Output PORTB.2 1
Output PORTB,5 1
Lcdout $fe “VEG-OIL”
Last edited by karenhornby; 3rd March 2008 at 04:35 AM. |
|
|
|
|
|
|
(permalink) |
|
Where's the rest?
edit ah there it is. It's larger than 40 lines so you'll have to buy PICBASICpro. Last edited by blueroomelectronics; 3rd March 2008 at 01:36 AM. |
|
|
|
|
|
|
(permalink) |
|
I've never used PicBasic and so I'm not sure of the syntax. I think what you want is something like,
Code:
Main:
If (PORTB.1=1) and (PORTB.4=1) and (PORTB.6=0) then
Lcdout $fe,1,"VEG-OIL"
PORTB.2=1
PORTB.6=1
Endif
If (PORTB.1=1) and (PORTB.4=1) and (PORTB.6=1) then
Lcdout $fe,1,"FLUSHING"
PORTB.2=1
PORTB.5=0
Pause 1000
Lcdout $fe,1,"DIESEL"
PORTB.2=0
PORTB.5=0
Endif
Goto Main
There is however a slight problem, the DS1620 requires the clock pin pulsing every second to make it do a conversion and set the over temp output. This can also be done by the pic. Do you have a rough circuit diagram. Mike. Last edited by Pommie; 3rd March 2008 at 06:12 AM. |
|
|
|
|
|
|
(permalink) |
|
Attached is a VERY ROUGH circuit of what I've planned.
What I want, is 2 inputs from 2 X DS1620's set to THERMOSTAT mode, with a HIGH output on pin 5 going into the inputs on the PIC in my case, PORTB.1 and PORTB.4 PORTB.2 AND PORTB.5 are OUTPUTS to transistors switching solenoids PORTB.6 is an input connected to a pressbutton switch DOES portb.6 HAVE to have an output? I'd like it to work so that IF PORTB.1 = 1 AND PORTB.4= 1 AND PORTB.6 = 1 THEN the outputs will be PORTB.2 = 0 and PORTB.5 = 1 but count for 10 seconds and at the end of the ten seconds make PORTB.2 = 0 PORTB.5 = 0 I've left the bit about the LED off this section as I hope from the previous its explained enough OH forgot to say, clock is a 4Mhz Xtal. Can this circuit/code be in a "smaller" pic? other than the 16F877 ie one with less lines. Please go easy on me, bear in mind a week ago I hadn't even considered ever learning how to program a PIC let alone have any idea how to go about it. Last edited by karenhornby; 3rd March 2008 at 04:31 AM. |
|
|
|
|
|
|
(permalink) |
|
Since your using your DS1620 in thermostat mode (you do have to program them or they don't do much)
Could I suggest a pair (or three) of LM34 or LM35 sensors instead? You can hook them directly to AD0, 1 , 2 and use a TL431 as a +VREF. This will give you accurate sensing on 4 I/O pins. |
|
|
|
|
|
|
(permalink) |
|
DO ALL inputs HAVE to have an output on a PIC chip, or can you have say 3 inputs but only 2 outputs?
Last edited by karenhornby; 3rd March 2008 at 05:11 AM. |
|
|
|
|
|
|
(permalink) |
|
Thanks Bill for the suggestion, however I decided on the DS1620's as it reduces component count considerably, and they only have to be programmed once, and the programmer is only a couple of components, and I've already got the program to do it, thats why I chose the DS1620's, I was originally going to go with the LM35's as you may remember from my first attempt using a 555 and various other circuitry that was just messy compared to this (IF I can get it to work)
I've played with the code a bit more, and put it into the PROTON PLUS editor, tried compiling it to see what I get and I've corrected several errors, and I'm down to just 2 errors now. can someone help out please? and let me know even if all errors are gone, do they think it will work? as I've not got a developement board or programmer for PIC's yet, I'm doing all this in my head at the moment and learning as I go The modified code is: Code:
DEVICE = 16F877 ' We'll use a PIC16F877 PICmicro
XTAL = 4 ' With a 4MHz crystal
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe,1, "DIESEL"
Lcdout $fe,$C0, "Temp in degrees C" ' Display sign-on message
input PORTB.1
output PORTB.2
input PORTB.4
output PORTB.5
input PORTB.6
output PORTB.7
IF PORTB.1 = 1 AND PORTB.4 = 1 AND PORTB.6 = 0 GOTO SOLENOID
ENDIF
IF PORTB.1 = 1 AND PORTB.4 = 1 AND PORTB.6 = 1 GOTO PURGE
ENDIF
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto Temploop ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.2 1
Output PORTB.5 0
Lcdout $fe, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 1000
Output PORTB.2 0
Output PORTB.5 0
Lcdout $fe, "Diesel"
‘SOLENOID send outputs to solenoids and display fuel state on LCD
SOLENOID:
Output PORTB.2 1
Output PORTB,5 1
Lcdout $fe, "VEG-OIL"
Error at Line [30] In file [OILCON~1.BAS] *** THEN directive missing from IF command! *** Error at Line [31] In file [OILCON~1.BAS] *** Misplaced or Incorrect 'ENDIF'. Also check its corresponding IF Command! *** ANYONE able to help Please? Anyone know the answer? Last edited by karenhornby; 3rd March 2008 at 06:00 AM. |
|
|
|
|
|
|
(permalink) |
|
I don't use PICBASICpro, I take it you bought it because I don't own anything higher than the demo version and it won't compile more than 40 lines of code.
You need a comma ", $C0 ," in line 20 I think. |
|
|
|
|
|
|
(permalink) |
|
Thanks Bill
thats one of the errors I spotted, umm to answer your question, seeing I didnt know anything about programming, and I wasnt willing to pay loads of money just to try something to see if it was easy to learn or not... "I'm borrowing a friends computer who had it installed to see if its worth buying" |
|
|
|
|
|
|
(permalink) | |
|
Quote:
To answer an earlier question, Pics can have any combination of inputs and outputs. Any pin can be either. Mike. |
||
|
|
|
|
|
(permalink) |
|
Hopefully I've done it
and Hopefully someone can confirm this please? By the way, will the time I've programmed give a 10 second pause/delay? Here's the code: Code:
DEVICE = 16F877 ' We'll use a PIC16F877 PICmicro
XTAL = 4 ' With a 4MHz crystal
' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
' Alias pins
RST var PORTC.0 ' Reset pin
DQ var PORTC.1 ' Data pin
CLK var PORTC.3 ' Clock pin
' Allocate variables
temp var word ' Storage for temperature
Low RST ' Reset the device
ADCON1 = 7 ' Set PORTA and PORTE to digital
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start
Lcdout $fe,1, "DIESEL"
Lcdout $fe,$C0, "Temp in degrees C" ' Display sign-on message
input PORTB.1 'Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.2 'OUTPUT to Solenoid 1
input PORTB.4 ' Input from DS1620 in Thermostat mode (only HIGH or LOW)
output PORTB.5 'OUTPUT to Solenoid 2
input PORTB.6 'INPUT from Pushbutton Switch
output PORTB.7
MAIN:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN TestSolenoid
' Temploop to read the temperature and display on LCD
Temploop:
RST = 1 ' Enable device
Shiftout DQ, CLK, LSBFIRST, [$ee] ' Start conversion
RST = 0
Pause 1000 ' Wait 1 second for conversion to complete
RST = 1
Shiftout DQ, CLK, LSBFIRST, [$aa] ' Send read command
Shiftin DQ, CLK, LSBPRE, [temp\9] ' Read 9 bit temperature
RST = 0
' Display the decimal temperature
Lcdout $fe,$C0, dec (temp >> 1), ".", dec (temp.0 * 5), " degrees C"
Goto MAIN ' Do it forever
‘PURGE flushes IP pump of oil and replaces it with diesel
Purge:
Output PORTB.5
LOW PORTB.2
Lcdout $fe, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 1000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe, "Diesel"
LOW PORTB.5
LOW PORTB.2
END
‘SOLENOID send outputs to solenoids(Switches fuel supply from Diesel to Veg-Oil)
'and display fuel state on LCD
SOLENOID:
Output PORTB.2
Output PORTB.5
Lcdout $fe, "VEG-OIL"
GOTO TempLoop
TestSolenoid: 'check to see if PURGE button is pressed
if PORTB.6 = 0 then SOLENOID
if PORTB.6 = 1 then PURGE
Last edited by karenhornby; 3rd March 2008 at 10:35 AM. |
|
|
|
|
|
|
(permalink) |
|
That looks like it would work. I'm not sure why there is an END instruction in the middle of your code and why the compiler didn't throw a wobbly because of it. You might want to add a goto TempLoop at the end of your code incase Portb.6 goes from 1 to zero just before the last line.
Shouldn't the outputs in Solenoid be high or low? The clocking of the 3rd DS1620 is taken care of by the shiftout and shiftin commands. The clocking of the other two still needs doing. You could connect them to bit 0 of PORTB and toggle it to start the conversion. Mike. |
|
|
|
|
|
|
(permalink) |
|
I put the END command there because IF the subroutine PURGE gets called, then the program ends once that section has done its bit.
The other two subroutines end by telling the program to go back to the the TempLoop which basically runs the program again in a loop until once of the subroutines SOLENOID or TestSolenoid is called. If TestSolenoid is called then the program either starts again via Solenoid, OR Ends itself after calling the subroutine PURGE Hopefully that makes sense? Oh the 1st 2 DS1620's DONT need clocking, they are running in thermostat mode with only a 1 wire output, pin 5 either high or low, only other 2 connections are +5V and 0V (once the temperature thresholds have been programmed into it. Thanks for the hint about the last line, I've added GOTO TempLoop as the last line Last edited by karenhornby; 3rd March 2008 at 11:33 AM. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Drive 33 Servos With One PIC + USART | wschroeder | Micro Controllers | 40 | 14th July 2008 02:22 PM |
| PIC12f675 | MERV | Micro Controllers | 18 | 10th December 2007 07:18 PM |
| pic programming.................. what next? | tama182 | Micro Controllers | 76 | 7th March 2006 03:13 PM |
| Chip talk | dreamproject | Electronic Projects Design/Ideas/Reviews | 8 | 2nd April 2005 07:24 PM |
| Check my Timer code | MrMikey83 | Micro Controllers | 7 | 17th January 2005 06:56 AM |