Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > Electronic Projects Design/Ideas/Reviews


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.

Reply
 
Thread Tools Display Modes
Old 3rd March 2008, 11:42 AM   (permalink)
Default 2nd Question...

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..
karenhornby is offline   Reply With Quote
Old 3rd March 2008, 11:49 AM   (permalink)
Default

Quote:
Originally Posted by karenhornby
I put the END command there because IF the subroutine PURGE gets called, then the program ends once that section has done its bit.
\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.
The END instruction doesn't stop the program. You need something like Label: goto Label.

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
The code above goes in a straight line from top to bottom as this is considered good practice and it makes it easier for others to understand.

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.
Pommie is online now   Reply With Quote
Old 3rd March 2008, 12:38 PM   (permalink)
Default

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"
Hopefully if I've done that right it will OUTPUT PORTB.5 AND LOW PORTB.2 for a period of 1t seconds then set both ports LOW


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
Because IF PORTB.6 = 0 then the program will sit there and not loop testing PORTB.6 again??
Thanks

Last edited by karenhornby; 3rd March 2008 at 01:25 PM.
karenhornby is offline   Reply With Quote
Old 4th March 2008, 02:09 AM   (permalink)
Default

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
As the code in the blue section also contains an IF statement, then if B.6=0 the red section will be executed, otherwise (if B6=1) the green section is executed.
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
Because you don't want it to restart after it has purged you should add a stop of some sort. I suggest waiting for the button to be pressed again so you can restart the sequence if needed.
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
The way the code is indented is to indicate which code goes with which statement. You should be able to look down code and instantly see which "endif" goes with which "if" because they are indented the same.

Hope that makes sense.

Mike.
Pommie is online now   Reply With Quote
Old 4th March 2008, 09:13 AM   (permalink)
Default

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
karenhornby is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 04:28 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.