Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What would be the best way?

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I am trying to get my head around what I thought would be a simple task!

I am running a Carputer and have used a relay to bridge the on off switch (momentary push to make switch) so when the relay is energised I.E. when the ignition is turned on, it shorts the switch for about a second turning on the PC.

When the ignition is turned off it again shorts the switch again and turns off the PC (standby)

Now this setup is working but the problem is if I need to turn the ignition on or off a couple of times within a short period. This can cause the pulse to be ignored if the PC is still either starting up or shutting down.

So I thought why not use a PIC and have a set period - say a minute - where the PIC would ignore any more offs and ons of the ignition and always be in sync.

Thats where I get stuck! I think I can manage the program part which I would be writing in MikroBasic, but I cannot for the life of me think how to go about the actual logic of the on, off and ignore. The more i try and think about it the more puzzled I become.

Any suggestions out there?

Thanks.........Al
 

rajbex

Member
If I have understood you properly, I would say, first find out the minimum time interval (Tmin) that the carputer requires to respond to two successive ON/OFF or OFF/ON. Then program your PIC controller such that it records the history of turning ON/OFF of ignition, and make use of timer to determine the gap between any two successive attempts of switching ON/OFF. For example, suppose when you turn the ignition off, the PIC logs the event and start a timer of interval more than Tmin. If there is any further attempt of turning ON the ignition before the timer runs out, avoid it.
I don't know will this help you or not, but I am kind of unclear what you exactly need.

- Raj
Experiments with PIC16F628A
 

Pommie

Well-Known Member
Most Helpful Member
Why not have a check for if the computer is on/off and then do,

If ignition is off for more than 1 (or 2..) minute AND computer is on then pulse relay.
If ignition is on AND computer is off then pulse relay.

Mike.
 

bigal_scorpio

Active Member
Hi guys,

I have got to the stage of writing the program now, but on burning it I seem to have done something wrong! Could someone take a look please. All that happens is the LED on GPIO2 turns on and stays on for minutes! Then it flickers off and comes back on again.......And thats without pressing either of the switches on GPIO0 or 1.

I have GPIO0 and 1 pulled low and switched highs on them.

I must be doing something stupid, but I have just had news that a good friend has passed away and I can't concentrate on anything at the moment, he was only 54!

Anyway any help would be much appreciated.........Al

PS this is on a PIC12F629 with internal clock ON and all the Watchdog and PWRE and BOD turned off.

I have
Code:
program PCtimer



DIM i as byte
TRISIO = %00000011
GPIO = %00000000


main:

IF (GPIO.0 = 1) and (GPIO.1 = 0) THEN   'on criteria
goto pulse
End if

IF (GPIO.0 = 0) and (GPIO.1 = 1) THEN   'off criteria
goto pulse
End if


GOTO main

PULSE:

GPIO.2 = 1         'set pulse on GPIO.2 for 1 sec
DELAY_MS(1000)
GPIO.2 = 0
For i = 0 to 30   'set period to wait before checking status again
DELAY_MS(1000)
NEXT i

GOTO main

End.
 

Pommie

Well-Known Member
Most Helpful Member
The only thing I can see is that you don't turn off the comparator. Try adding CMCON=7.

BTW, which compiler are you using?

Mike.
 

AtomSoft

Well-Known Member
dude i think this would be simple on a PIC...

what speed is your pic? lets say 4mhz... either use timer or loop (SIMPLER somewhat)

If using a loop:

Step 1:
Is pin high --- no then wait....

if high then start the loop

in the loop simply count up to about 60000000 @ 4mhz PIC thats 60,000,000 Cycles aka 60 seconds (more or less) use mPLAB sim to verify

if the pin is high after 60,000,000 counts then its time to turn on or off the computer....

If the pin is low before 60,000,00 you can have it do something depending on length or what ever
 
Last edited:

bigal_scorpio

Active Member
Hi again,

Mike I added the CMCON = 7, but sadly nothing to report, and I mean nothing, so I added a couple of lines hoping that I could see when the delay was running by lighting LED on GPIO4, and guess what? It doesn't light up ever so I am obviously not getting to that part.

Code:
program PCtimer



DIM i as byte
CMCON=7
TRISIO = %00000011
GPIO = %00000000


main:

IF (GPIO.0 = 1) and (GPIO.1 = 0) THEN   'on criteria
goto pulse
End if

IF (GPIO.0 = 0) and (GPIO.1 = 1) THEN   'off criteria
goto pulse
End if


GOTO main

PULSE:

GPIO.2 = 1         'set pulse on GPIO.2 for 1 sec
DELAY_MS(1000)
GPIO.2 = 0
GPIO.4 = 1         'show by LED on GPIO.4 that delay is working
For i = 0 to 30   'set period to wait before checking status again
DELAY_MS(1000)
NEXT i
GPIO.4 = 0         'turn off delay LED
GOTO main

End.

I am using MikroBasic compiler on the EasyPic5 dev board and have the config flags set as this:-
CPD OFF
CP OFF
BODEN OFF
MCLRE OFF (have tried off too)
PWRTE OFF (have tried off too)
WDT ON (have tried off too)
HS_OSC ON
INTRSC_OSC NOCLKOUT ON

This must be a very simple program in terms of size and I must be doing something monumentally stupid! Help.

Regards.........Al
 

bigal_scorpio

Active Member
dude i think this would be simple on a PIC...

what speed is your pic? lets say 4mhz... either use timer or loop (SIMPLER somewhat)

If using a loop:

Step 1:
Is pin high --- no then wait....

if high then start the loop

in the loop simply count up to about 60000000 @ 4mhz PIC thats 60,000,000 Cycles aka 60 seconds (more or less) use mPLAB sim to verify

if the pin is high after 60,000,000 counts then its time to turn on or off the computer....

If the pin is low before 60,000,00 you can have it do something depending on length or what ever

Hi Jason,

Yeah I thought it would be simple but I still can't get the ^&$%^& to work! ;)

Any suggestions on my code appreciated.

Al
 

bigal_scorpio

Active Member
Why do you have this:

HS_OSC ON
INTRSC_OSC NOCLKOUT ON

Its conflicting

Hi Jason,

From how I understand the manual, HS_OSC ON sets the speed of oscillation and INTRSC_OSC NOCLKOUT ON tells the PIC to use the internal oscillator.

But I will try with just one or the other set just to rule it out. ;)

Al

Addition - You were right mate, I turned off the HS_OSC and the program works to a degree.

Now the problem is that the delay is not working right. but only giving a light for about a second and not 30 as I expected.

Any further thoughts?
Al
 
Last edited:

bigal_scorpio

Active Member
Solved!

Hi to all,

Thanks to all the help from you guys I have found the problem and solved it.

It was a combination of what Jason said with the conflict and the WDT, once I had sorted both it was all OK.

Thanks again........Al :D
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top