![]() |
![]() |
![]() |
|
|
|||||||
| 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) |
|
Is there any way of keeping a PIC alive for say 20 seconds after power has been removed?
What I mean is, this circuit I'm TRYING to make, will be connected to the ignition of the car, and once the ignition is turned on it will start. Once the 2 X DS1620's have reached their preset temperatures they go HIGH which in effect calls the TestSolenoid routine. NOW IF the ignitions is still on, the solenoids operate until switch S1 is pressed (PORTB.6 goes high) which is fine. What I want to do IF its at all possible is IF the power to the circuit is interrupted (Ignition going off) BEFORE S1 goes High then another output enables, ie PORTB.7 which could be connected to a siren through a transistor switch to remind me to switch the ignition on and then press the S1 before turning it off again. I know this MAY be possible if I have a 2nd power to the circuit direct from the car battery and maybe have this power the 5V bus for the PIC, and have the 5V bus for the DS1620's only work when the ignition switch is on. obviously using relays, but this seems messy and I've no idea what the current consumption of the circuit might be it it was left powered up and the car not used for a few weeks Hope I've made the question sound realistic and not impossible.. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
The DS1620s in stand alone mode still need a pulse on pin 2 to start the conversion. Refer page 2 of the data sheet.Edit, just read the data sheet and you are correct, if you tie Conv low it will convert continuously. For your information, this is how I would rearrange your code to make it more readable. This isn't meant as a criticism, it is just that people are familiar with certain ways of doing things. Code:
MAIN:
high PORTB.0 'toggle the clock pin.
Pause 10 'the conversion will be complete
Low PORTB.0 'before the inputs are read further down.
' Temploop to read the temperature and display on LCD
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"
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endif
Goto MAIN ' Do it forever
Edit, I should add that what you have achieved so far is remarkable considering you haven't programmed before. Mike. Last edited by Pommie; 3rd March 2008 at 12:09 PM. |
||
|
|
|
|
|
(permalink) |
|
Many thanks
I cant claim credit for writing the code, all i did was "borrow" snippets of other peoples code and modified it for my own use, although having said that, it did take a major rewrite and some bits I had to keep trying till it actually worked. the one thing I'm not certain about is this: Code:
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" Thanks for the tip about layout of the code, I've taken your advice and its now all neat and tidy HOWEVER would the program not pause endlessly at this point? Code:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endi
Thanks Last edited by karenhornby; 3rd March 2008 at 01:25 PM. |
|
|
|
|
|
|
(permalink) |
|
The program won't pause endlessly. The way the code works is that the code in blue will only get executed if B.1=1 and B.4=1. Otherwise, it will skip straight to the endif statement at the bottom.
Code:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endif
Code:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
endif
endif
Code:
IF PORTB.1 = 1 AND PORTB.4 = 1 THEN
if PORTB.6 = 0 then
'was Solenoid
HIGH PORTB.2
HIGH PORTB.5
Lcdout $fe,2, "VEG-OIL"
else
'was Purge
HIGH PORTB.5
LOW PORTB.2
Lcdout $fe,2, "FLUSHING" ;ten second hold before solenoids are set to zero
Pause 10000 'PAUSES for TEN SECONDS then (HOPEFULLY) SETS OUTPUTS B2 and B5 LOW
Lcdout $fe,2, "Diesel"
LOW PORTB.5
LOW PORTB.2
While(PORTB.6=0) 'wait for button to be pressed again
Wend 'this is short for while end
endif
endif
Hope that makes sense. Mike. |
|
|
|
|
|
|
(permalink) |
|
That made perfect sense and I actually understand a bit about how these things work now, even though I've only learnt a few of the commands you can program into them.
Thanks |
|
|
|
|
| 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 |