PDA

View Full Version : Problems with 12F675



fratello
- 9th July 2009, 21:42
Hi to all !
I am still at the beginning of understanding the MCU's...After finalizing the project with Nokia 3310 display (thermometer & clock, see in this forum) I try to make another project ; one button for electric windows of my car.
If short pulse for up, the window roll-up till detecting over-charging of motor ; if short pulse for down, rolling-down till over-charge...
I use code from this forum ; I try the schematic in ISIS, but nothing happening !
I think I do something wrong...Can somebody help me, please ?! Thanks in advance for every suggestion !
btw : adval >=256 ; that means 4.00 Volts ?

Darrel Taylor
- 10th July 2009, 00:28
Try ...
CHECK:
ADCIN 3, adval

The 675 doesn't have an AN4.

fratello
- 12th July 2009, 12:08
I made this schematic.
I write this code.
I want this :
- if I push button on gpio.3, gpio.5 goes high UNTILL voltage at AN3 goes OVER 550 mV or I push again the button ;
- idem for gpio.2 -> gpio.0.
My problems are :
- AN1 must be on Vdd ?
- the calculation of vt (voltage at AN3) is correct ? ( I use 10 bit resolution, so 5000/1024= 4,88 -> con1 = 4 & con2 = 88). Can someone to explain me more accurate ? Maybe I must use 12 V for calculation ?!
Thanks in advance for every reply !

fratello
- 12th July 2009, 14:47
I use the information from here : http://www.picbasic.co.uk/forum/showpost.php?p=67258&postcount=12
So, I need to detect the voltage from 0,48 V to 0,56 V ( load of 120 to 140W , using R1= 0,05 Ohmi) ; if voltage increase over 0.56 V, gpio.5 MUST go to 0 !
Thanks for attention...

Darrel Taylor
- 13th July 2009, 06:53
I want this :
- if I push button on gpio.3, gpio.5 goes high UNTILL voltage at AN3 goes OVER 550 mV or I push again the button ;
As it's written ... when a button is pressed, it checks the voltage ONE time then waits for the button to be released. That's all.
Not even close to what you "wanted".

The "Check's" need to be in a loop, or a couple loops since you want to look for a second button press.

Something like this might work ...
if GPIO.3=1 AND GPIO.0 = 0 then
HIGH GPIO.5
pause 20 ; debounce

while GPIO.3 = 1
CALL CHECK ; check while waiting for button release
WEND
pause 20

WHILE GPIO.3 = 0
CALL CHECK ; continue checking input
if GPIO.5 = 0 THEN ; IF LED was turned OFF in CHECK routine
GP3PressDone ; we're done
endif
WEND ; stop if button is pressed again
LOW GPIO.5

while GPIO.3 = 1 ; wait for button release
WEND
pause 20

endif

GP3PressDone:

Then do the same thing for the GP2 button.

I was bouncing back and forth from the code to the schematic, having a hard time figuring out what you were trying to do. With so many GPIO's spread throughout the program it's really, really hard.

It would be a lot easier to debug your programs if you used Aliases.
Instead of GPIO.0 etc ... give meaningful Names to each Pin ...

LED1 VAR GPIO.5
LED2 VAR GPIO.0
BUTN1 VAR GPIO.3
BUTN2 VAR GPIO.2


Then it would look like this, which is much easier to follow ...
Comments help too.
if BUTN1 = 1 AND LED2 = 0 then
HIGH LED1
pause 20 ; debounce

while BUTN1 = 1
CALL CHECK ; check while waiting for button release
WEND
pause 20

WHILE BUTN1 = 0
CALL CHECK ; continue checking input
if LED1 = 0 THEN ; IF LED was turned OFF in CHECK routine
GP3PressDone ; we're done
endif
WEND ; stop if button is pressed again
LOW LED1

while BUTN1 = 1 ; wait for button release
WEND
pause 20

endif

GP3PressDone:


You would have received an answer a lot quicker that way too. :)
<br>

Darrel Taylor
- 13th July 2009, 08:33
Also, for the Voltage conversion ...

The way you are doing it will overflow the variables and isn't very accurate.

A better way would be to use DIV32 ...
CHECK :
ADCIN 3, ADVAL
VT = ADVAL * 5000 ; 5V with 3 decimals
VT = DIV32 1023 ; / maximum A/D reading

IF VT > 550 THEN
GPIO.5 = 0
GPIO.0 = 0
ENDIF
RETURN


hth,

fratello
- 13th July 2009, 11:05
THANK YOU !!!!
I will try the soft and I will keep You inform.

fratello
- 14th July 2009, 09:43
I write this code. It's something wrong :
- if I press but1 and rel1 goes low because of 'check' (over-load detected), but2 don't work not at all (must disconect power), and rel1 goes high only after two press of but1 ;
- if I press but2 and rel2 goes high, if I press but1 rel2 goes low ;
- if I press but2 and rel2 goes low because of 'check' (over-load detected), but1 don't work not at all (must disconnect power), and rel 2 goes high only after two press of but2.
Can help me ? Thanks in advance.
btw: The 'check' subroutine works fine !

Darrel Taylor
- 14th July 2009, 10:16
OOPS, my fault :o

In post #5 the line
GP3PressDone ; we're done


Should have been
GOTO GP3PressDone ; we're done

That's how it get's out of the loop under those conditions.

Sorry,

fratello
- 14th July 2009, 13:24
...still not work proper...same bugs :confused:

Darrel Taylor
- 14th July 2009, 15:23
In your LAST version, you missed the LOW statement.
if but1=1 and rel2=0 then
high rel1
pause 20

while but1=1
call check
wend
pause 20

while but1 = 0
call check
if rel1=0 then
GOTO Btn1PressDone
; pause 10
endif
wend
LOW rel1

while but1=1
wend
pause 20
endif
Btn1PressDone:

fratello
- 14th July 2009, 17:20
Thank You so much for help !
I think this is my worst project :(... I damage two PIC, now I have just one, and this project don't work, even with so much help...I write so many lines of code but nothing works right...
This is the last version. Bugs:
-if press but2, ON/OFF rel2 works fine, but if I press but1 after but2, then rel2 goes OFF and nothing works more, need to disconect power
-if press but1, ON works, without OFF ; after OFF because of 'check' nothing works more, need to disconect power.
This is one nightmare !!!
Hope I don't became verry, verry boring...and I am really sorry about my english...

Darrel Taylor
- 14th July 2009, 17:46
I think this is my worst project :(
No arguments here. :eek:

I guess it's the language barrier.

I've built the circuit you described, and am using the following program ...
As far as I can tell, it does exactly what you want it to do.

@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off

DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

CMCON = 7
OPTION_REG = %10000110
TRISIO = %00011110
ANSEL = %00011000
ADCON0 = %10001101

adval var Word
vt var word
but1 var gpio.3
but2 var gpio.2
rel1 var gpio.5
rel2 var gpio.0


main:
rel1=0
rel2=0

btn1:

if but1=1 and rel2=0 then
high rel1
pause 20

while but1=1
call check
wend
pause 20

while but1 = 0
call check
if rel1=0 then
GOTO Btn1PressDone
; pause 10
endif
wend
LOW rel1

while but1=1
wend
pause 20
endif
Btn1PressDone:


btn2:
if but2=1 and rel1=0 then
high rel2
pause 20

while but2=1
call check
wend
pause 20

while but2 = 0
call check
if rel2 = 0 then
GOTO Btn2PressDone
; pause 10
endif
wend
low rel2

while but2=1
wend
pause 20
endif
Btn2PressDone:

GOTO MAIN

check:
adcin 3, adval
vt=adval * 5000
vt=div32 1023

if vt > 1250 then
gpio.0=0
gpio.5=0
endif
return

end

fratello
- 14th July 2009, 18:25
Thanks for such a fast reply!
Yes, in ISIS works verry, very fine ! But in real world ( :) ) the bugs are present !!!! I really don't know what something else I can do... :(

fratello
- 23rd July 2009, 21:53
This is it !
Now works how I intend ! Thank You verry, verry much ! The on/off button works fine, and the check procedure too .I hope I write correct this "check procedure" for checking 5 times if is - indeed - overload (?!)
One last problem : if press but1 and rel1 is high, how can made rel1 low, with but1 - press again, of course - OR BUT2 - press once... ?!? (and some things with but2/rel2).
I try to write something, but rel1 go low AND rel2 go high...and this is unacceptable...Thanks again for attention and especially to Mr.Darrel for kindness and patience...

Darrel Taylor
- 23rd July 2009, 23:59
One last problem : if press but1 and rel1 is high, how can made rel1 low, with but1 - press again, of course - OR BUT2 - press once... ?!? (and some things with but2/rel2).

I don't understand that.
Relay1 and Relay2 can never be high at the same time.

That's because of these statements...
if but1=1 and rel2=0 then
If Relay2 is on, it won't accept a press of Button1.

Or maybe I missed the point of the question.
<br>

fratello
- 24th July 2009, 06:18
But1 make rel1 high at first push and low at second push.
But2 make rel2 high at first push and low at second push.
It is possible this :
-but1 make rel1 high at first push and low when push second time but1 OR push but2 ?
-but2 make rel2 high at first push and low when push second time but2 OR push but1 ?
So, rel1 ON with but1 , and OFF with but1 OR but2 ; rel2 ON with but2, and OFF with but2 OR but1. Hope now You understand me;I am really verry sorry for my poor english...
Thank You !


....me again. This is my working variant !
In check: procedure I write this :
if rel1 = 1 and but2 = 1 then
low rel1
pause 500
goto Btn1PressDone:
endif

if rel2 = 1 and but1 = 1 then
low rel2
pause 500
goto Btn2PressDone:
endif
In ISIS don't work, but in fact yes ! I don't understand why, but...Maybe You have another variant, much better; it's a good way to learn more. Still don't know if rel (1 or 2) stop if overload detected, only AFTER checking this overload for 5 times...

Darrel Taylor
- 24th July 2009, 11:57
OK, I see what you mean now. :o

Try this ...

btn1: 'actionare buton up

if but1=1 and rel2=0 then
high rel1

pause 20

while but1=1
call check
wend
pause 20

while but1 = 0 AND but2=0
call check
if rel1=0 then
GOTO Btn1PressDone
endif
wend
LOW rel1

while but1=1 OR but2=1
wend
pause 20

endif
Btn1PressDone:

And yes, the check: routine seems to work "only after 5 times".

fratello
- 24th July 2009, 14:27
I am speechless...THANK YOU VERRY MUCH ! Works like a charm ! Great job, You are verry, verry good in this...
Great forum, I am proud for visiting him. All the best for everyone, wherever you are !

fratello
- 26th July 2009, 20:15
I have tested this module on my car ; works verry fine, like I expect.Since this will be use on car, I think this is one good ideea to minimize the consumption.So I try to write something...Please take one advice...Thanks !

Darrel Taylor
- 26th July 2009, 22:07
I think it might be better to ...
main:
rel1=0
rel2=0
@ sleep
pause 100


It looks like you have correctly set-up the pic to wake from sleep on PORT change (either switch).

So then it wakes up ... drives the motor relays as necessary ... and only after the motor is finished, and no buttons are pressed, go back to sleep.

The two NOP's are only required if it will be jumping to an Interrupt vector on wake up.
Yours is just continuing where it left off.

Hmmm, sounds like a powered antenna driver. ??
<br>

fratello
- 27th July 2009, 07:06
Thanks for reply ! I KNOW that YOU are right. ...Now my car has "intelligent" windows :) !
...I think to 'implement' the detection of 'long press button/short press button', but after one short holidays...All the best !

fratello
- 1st August 2009, 20:25
I'm back ! ...with another challenge :
- if press short but1 (or but2) the schematic works like before (ON/OFF rel, at every press of but1/but2 or overload detection) ;
- but...if press long (over 1 sec) but1 (or but2) the relay must be ON as long as the but is press; once the but is release, the relay must go OFF.
I try to implement some code from Melanie's advices (Thanks !) founded on this forum, but the result are not good...Relay don't go ON not at all ...
I see this is the way witch work the electric windows on other cars ( with two different type of press: long & short) ; maybe, with - a lot of - help, I make my car (b.t.w. - Logan by Renault !) with really intelligent windows ! Thanks in advance for any advice !

Darrel Taylor
- 2nd August 2009, 00:01
Challenge? ... What challenge? :)

Started with a previous version ...

'************************************************* ***************
'* Name : THE_BUTON_sleep.BAS *
'************************************************* ***************
@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off

DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

CMCON = 7
OPTION_REG = %10000110
TRISIO = %00011110
ANSEL = %00011000
ADCON0 = %10001101

GIE var intcon.7 ' global interrupt enable 1=on ; 0=off
gpie var intcon.3 'port change interrupt enable 1=0n ; 0=off
gpif var intcon.0 'port change interrupt flag bit

adval var Word
vt var word
u var byte
cnt var byte
but1 var gpio.3
but2 var gpio.2
rel1 var gpio.5
rel2 var gpio.0

Timer1 VAR WORD EXT :@Timer1 = TMR1L
TMR1ON VAR T1CON.0
TMR1IF VAR PIR1.0
T1Count VAR BYTE
LongPress VAR BIT
T1CON = %00110100

u=0
cnt=0
GIE=0
GPIE=1
IOC.2=1 ' int-on-change for GPIO.2 enabled
IOC.3=1 ' int-on-change for GPIO.3 enabled

but1=0
but2=0
rel1=0
rel2=0

main:
rel1=0
rel2=0
@ sleep
pause 100
Timer1 = 3037
T1Count = 0
LongPress = 0

btn1: 'actionare buton up

if but1=1 and rel2=0 then
high rel1
TMR1ON = 1
pause 20

while but1=1
call check
wend
IF LongPress THEN Stop_UP
T1Count = 0
pause 20

while but1 = 0 and but2 = 0
call check
if rel1=0 then
GOTO Btn1PressDone
endif
wend
Stop_UP:
LOW rel1

while but1=1 OR but2 = 1
wend
pause 100
endif
GPIF=0 'Clear ort change interrupt flag

Btn1PressDone:


btn2: ' actionare buton down
if but2=1 and rel1=0 then
high rel2
TMR1ON = 1
pause 20

while but2=1
call check
wend
IF LongPress THEN Stop_Down
pause 20

while but2 = 0 and but1 = 0
call check
if rel2 = 0 then
GOTO Btn2PressDone
endif
wend
Stop_Down:
low rel2

while but2=1 or but1=1
wend
pause 100
endif
GPIF=0 'Clear ort change interrupt flag
Btn2PressDone:

GOTO MAIN

check: ' verificare pentru supracurent
adcin 3, adval
vt=adval * 5000
vt=div32 1023

for cnt = 1 to 5
if vt > 270 then
u=u+1
if u > 5 then
gpio.0=0
gpio.5=0
endif
pause 50
goto check
else
u=0
endif
next cnt

IF TMR1IF then
TMR1IF = 0
Timer1 = 3037
T1Count = T1Count + 1
if T1Count = 2 then
TMR1ON = 0
T1Count = 0
LongPress = 1
endif
ENDIF

return


end ' of program
I'll have to charge you for the next one though. :eek:
<br>

fratello
- 2nd August 2009, 07:26
Mr.Darrel, You are great ! Thank You so much for support; without You, I never ended this project. I wish You all the best !
PS : I don't understand Your last proposition (because of "the language barrier") but I hope not be crossed with me ! The challenge is for ME ! Hope to learn how much it's possible from You and this forum ! Of course You don't need to compete with nobody ! Greetings from Romania !!!

Darrel Taylor
- 2nd August 2009, 08:06
Sorry, my humor is hard to understand even if you speak english. ;)
Nothing bad intended.

I'm glad you got your power windows working the way you wanted.

Cheers!

Archangel
- 2nd August 2009, 08:47
I'll have to charge you for the next one though. :eek:
<br>You still accepting EBeer ? :D

fratello
- 3rd August 2009, 16:17
OOps ! I have a big problem : but1 don't work proper ! I double/triple check all ; I change the button, but nothing... After a few press on but1 or EVEN on but2, but1 became inopperating ! If press but2, rel2 go high and but1 stop him, but don't make rel1 high ! Or, if rel2 go low because of overload, but1 don't work not at all ! Must disconnect power source for 're-starting' him...
But2 works verry fine, but but1 don't !!! I really don't understand ! I check everything for so many times, I change even PIC...Please, help...again...:(

Archangel
- 3rd August 2009, 17:31
Hi fratello,
2 changes for you to try.
1.turn WDT timer on in your config.
2.You have used: Call check in several places, change them to
GoSub check

Darrel Taylor
- 3rd August 2009, 17:36
Check the T1CON assignment.
Make sure it has 8-digits.
T1CON = %00110100

If it's not 8 digits, or if the digits are different, along with disabling the rel1 output on GP5, it may also make it difficult to re-program the chip.
<br>

fratello
- 3rd August 2009, 19:27
Thanks for reply ! The code posted by Mr.Darrel works fine with this two modifications :
' @ Sleep
' GPIF=0 'Clear port change interrupt flag
Here are something wrong...and, of course, it's only my fault...

Archangel
- 4th August 2009, 04:12
Great !
Now I have a related question for Darrel . . .
Sleep vs @ sleep
PBP vs ASM ?
I tried both on John's T flusher code and only @sleep would work
Am I correct, sleep works with some time designation I. E. Sleep 60 , and @ SLEEP works with interrupts ?

Darrel Taylor
- 4th August 2009, 18:23
SLEEP vs. @ SLEEP vs. NAP

PBP's SLEEP command is designed to work with the Watch Dog Timer.
It sets the WDT prescaler to an appropriate divisor then internally does an @ SLEEP.
When it wakes-up it decrements a counter and if that counter is still greater than zero, it goes back to sleep.

The processor may have to go through several hundred or even thousands of sleep/wake cycles before execution of the program will resume. It all depends on the specified period.

If the WDT is disabled and you are relying on port change interrupts to wake the PIC it will take just as many of those interrupts before the program resumes execution.

If you are using ASM Interrupts, the ISR will be called on each wake-up. This also may happen several hundred times before the rest of the program can see what happened in the interrupt.

If you are using ON INTERRUPT, no interrupts will be serviced until after the complete SLEEP command has finished.<hr>
@ SLEEP in assembly language, simply puts the processor to sleep for 1 sleep/wake cycle. Program execution will resume immediately on the first wake-up. Or if interrupts are enabled, it will jump to the ISR first, then resume were it left off. Although if interrupts are enabled, you <strike>must have 2 NOP's</strike> should have 1 NOP after the @ SLEEP statement to allow the pipeline to load the ISR's first instruction.<hr>
PBP's NAP command operates much like @ SLEEP, except it changes the WDT prescaler according to the specified period (12F-16F only) before executing an @ SLEEP internally.

It only waits one sleep/wake cycle.

hth,

Archangel
- 4th August 2009, 21:08
@ SLEEP in assembly language, simply puts the processor to sleep for 1 sleep/wake cycle. Program execution will resume immediately on the first wake-up. Or if interrupts are enabled, it will jump to the ISR first, then resume were it left off. Although if interrupts are enabled, you must have 2 NOP's after the @ SLEEP statement to allow the pipeline to load the ISR's first instruction.
Thank You Darrel,
1 sleep / wake cycle ? still not causing sparks across my synapses, Is that OSC/4, Arbitrary countdown of WDT, something conjured using black cat bones and herbs? AND IF WDT is not enabled, will it sleep forever waiting for an interrupt? And if so will that interrupt wake it up?

Darrel Taylor
- 4th August 2009, 23:02
1 sleep / wake cycle ? still not causing sparks across my synapses, Is that OSC/4, Arbitrary countdown of WDT, something conjured using black cat bones and herbs? ...
1 sleep/wake cycle is the process of putting the PIC to sleep, and having it wake-up from one of many reasons.

If that reason is due to the WDT, it may be more like "Black DOG bones". :)
The WDT isn't very accurate in most PIC's. And it varies from one Family to another. But essentially it's the base period of the WDT, multiplied by the Prescaler.


AND IF WDT is not enabled, will it sleep forever waiting for an interrupt? And if so will that interrupt wake it up?
Yup! She'll pull a "Sleeping Beauty" until a Prince comes along for a kiss.

Available Princely possibilities are ...
From the Midrange Reference.

http://www.pbpgroup.com/files/Wake-Ups.GIF

Also, Bruce pointed out that the datasheets recommend 1 NOP after @ SLEEP instead of 2.

Not sure why I thought it was two. :o
<br>

Archangel
- 5th August 2009, 05:19
<h1> THANK YOU ! </h1>
That is what I needed confirmation on.

fratello
- 5th August 2009, 08:09
Yes, it's work now !
@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_ON, pwrt_on, mclr_off, bod_off
...
@ Sleep
...
GPIF=0
...
Thanks again to all for help ! @ Cheers ;) !

fratello
- 7th August 2009, 12:26
Works...but don't sleep ! I measure the current and it is all the time about 3.5 mA. Based on "PICadilly 12F675", writen by Ian Burn, I try to re-re-redefine the code. But...even I made like in book, the current consumption it's 3.5 mA !
" @ DEVICE PIC12F675, intrc_osc_noclkout, wdt_OFF, pwrt_on, mclr_off, bod_off
....
IOCB= %00001100
INTCON.3=1
OPTIONS_REG.6=1
....
main:
...
INTCON.0=0
Pause 100
@SLEEP
Pause100
... "
I don't understand why do not work ! I remove the PIC from schematic, and the current consumption is about 2.5 mA; so, the 12F675 consume about 1 mA, all the time and never go to sleep with "less than 1 microamp" !

Archangel
- 7th August 2009, 16:48
Hi fratello,
Well you have taken this thread every which away, instead of making new threads for different projects, so we do not really know which schematic and code you are asking about, so only "General" statements can be applied here. First, you are chasing 1 ma out of 3.5 ma, is there any way to kill the 2.5 since it is the bigger portion? Secondly, I do not think you will ever see 1&micro;A, maybe wrong just my opinion. Just before @ SLEEP, I would try tristating the GPIO by TRISIO = 255, disable WPU and in your configs, shut off WDT, and disable MCLRE, you might switch to LP_OSC, to further reduce power. Read this thread, different chip but useful maybe:
http://www.picbasic.co.uk/forum/showthread.php?t=11325

fratello
- 7th August 2009, 17:43
Thanks for reply ! I use the schematic from post #1 and the code continuous improved in this thread. I made this changes on the last code posted by Mr.Darell. I say that I use this schematic on automobile ; I think every way to reduce the consumption it's necessary...or maybe the battery of my car give enough current, even I don't start the engine for a long period...It is not a verry big problem, but I want to understand the "mechanism" of the sleep procedure, and I am dissatisfied because, even I try all the variants, the obvious results are not present ! Just I try to make this project almost perfect and I really appreciate the support of all. Sorry if I disturb somebody...or if I became boring...

Darrel Taylor
- 7th August 2009, 23:21
fratello,

Have you changed anything?
I see you put the WDT back to OFF ... good.

Here's a picture of my breadoard of your circuit, in case you see something different.
Obviously, I'm using LED's instead of relays, but the rest should be the same.

When in SLEEP mode, I measure about 8 ľA on my cheap DVM.

The only time it's not in sleep mode, an LED(relay) is ON, so that current is about 7 mA.

http://www.pbpgroup.com/files/Frat_Windows_SM.JPG

Here's the program I'm currently using.

Archangel
- 8th August 2009, 03:01
it is not a very big problem, but I want to understand the "mechanism" of the sleep procedure, and I am dissatisfied because, even I try all the variants, the obvious results are not present ! Just I try to make this project almost perfect and I really appreciate the support of all. Sorry if I disturb somebody...or if I became boring... Ya, Me too . . . You are not disturbing, or boring me, I just need to be clear on what you are doing, so as to understand, the post about PICadilly confused me.

fratello
- 8th August 2009, 06:44
This is schematic I use. With my FUKE DT-830B I measure 3.5 mA -all the time- with no button push (so both relay OFF) and about 37 mA with one relay ON (without motor, of course). I remove the PIC and the current consumption is 2.5 mA (the two transistors ?) .
I use the same code ; I compile him after copy/paste of Yours ! Maybe it's because of my multimeter ? Anyway, thank You all so much for support !

Archangel
- 8th August 2009, 07:30
This is schematic I use. With my FUKE DT-830B I measure 3.5 mA -all the time- with no button push (so both relay OFF) and about 37 mA with one relay ON (without motor, of course). I remove the PIC and the current consumption is 2.5 mA (the two transistors ?) .
I use the same code ; I compile him after copy/paste of Yours ! Maybe it's because of my multimeter ? Anyway, thank You all so much for support !Hi fratello, You could play with some resistors to bias those transistors so the base is more negative than the emitter to cause them to turn off more, do not tristate the outputs, drive them low, they will stay that way in sleep ( if I understand the data sheet that is ) . Try measuring the current with the relays out, betcha you get a low reading like Darrel did, MeThinks the logic zero on the port is still above zero volts (maybe due to internal leakage collector to base) giving the transistor some drive to increase the drain, try putting some emitter resistors in and see if it changes anything.

fratello
- 8th August 2009, 10:26
OOps ! I have a big problem : but1 don't work proper ! I double/triple check all ; I change the button, but nothing... After a few press on but1 or EVEN on but2, but1 became inopperating ! If press but2, rel2 go high and but1 stop him, but don't make rel1 high ! Or, if rel2 go low because of overload, but1 don't work not at all ! Must disconnect power source for 're-starting' him...
But2 works verry fine, but but1 don't !!! I really don't understand ! I check everything for so many times, I change even PIC..:(
Some problem !!!!

fratello
- 8th August 2009, 13:10
I change the resistors from transistors base with 2k2 instead 4k7; nothing !!!
I change the transistors (BC337) with others (2SC1815; 2SC9014) but the results are all the time the same : after couple of pressing on but1 OR but2 (doesn't matter !) but2 (and rel2) works fine but but1 (rel1-of course) became inopperating !

Archangel
- 8th August 2009, 16:10
Hi Fratello,
Ok, in the crude drawing I posted, R3 is selected to limit the current going through the relay coil. r1 is selected to limit current going into the transistor's base, and R2 is the trick. R2 needs to be smaller than R3, but not so low a value so as to inhibit the transistors operation. R2 will increase the ON current, but should help drive the transistor to "cut off".
in this link:http://engr.astate.edu/jdg/Electronics/Lab1/09TransistorBiasing.html
Scroll down to Figure 5.
RC is your relay coil represented as a resistor
R1 is the resistor from the pic port, I know it is shown as connected to Vcc, but when your port goes high that is exactly what you have
R2 is the "pulldown resistor, causing cutoff
RE is the current limiting resistor for the load.

fratello
- 8th August 2009, 19:19
The problem are sure somewhere in the code ! The same code, how I say earlier, work if @SLEEP (and just this command !!!) is disabled !!!
Like in the previous code, which work - for real !- just after adding little pause in different places, I think this code is good, but need...something, I don't know what ! I spend all my day trying different variant of code...with pause from 20 to 100, but useless...I don't lose my hope ! Cheers !

Darrel Taylor
- 8th August 2009, 19:48
http://www.pbpgroup.com/files/Frat_board.JPG

If it is a 78L05 ... then that's where your 3mA is going. (Quiescent Current)
<br>

fratello
- 8th August 2009, 20:37
Hi Mr.Darrel !
Maybe I can't explain verry clear !
If @SLEEP command is 'enable', the repause current is 2.5 mA (like without PIC !). But, after couple of press of but1 or but2, but1 don't work more ! Need to disconnect power !
If @SLEEP is 'disable' (by ' in front of her), the repause current is 3.5 mA, and but1 and but2 works without problems ! I do not change nothing in schematic !
Just use @SLEEP (2.5 mA ; problems with but1) or not (3.5 mA ; not problems)
Sorry for my poor english...

Darrel Taylor
- 8th August 2009, 20:53
Your problems are NOT in the program, since the same program is running here without any problems.

What is that part I pointed to above?

Where are the Flyback diodes for the relay coils?

Where are the capacitors ... decoupling, and on the regulator?
<br>

fratello
- 9th August 2009, 07:49
The regulator is ST78L05, with 1x0.1 uF decoupling on output (SMD,on the back side) ; the diodes for relays are 1N4007 (on the back side). Thanks for patience !

Archangel
- 9th August 2009, 09:29
Hi Fratello,
I think what Darrel is saying is the 3ma you are measuring is going out through the regulator as HEAT, and your circuit is working as expected.
Question, if this is a power window switch, do you shut off it's power with the ignition ? You lose more than 3ma because the top of the battery is not clean, and you cannot clean it well enough to not lose it.

fratello
- 9th August 2009, 11:26
I put one capacitor of 1uF to output of 78L05 and I replace the two diodes from relays with 1N4148, and ...YES !!!!!! Now the consumption is 2.5 mA and BOTH buttons work VERRY WELL !!!!! What a simple solution !!!! I can't explain why now work, but I'm HAPPY ! THANK YOU ALL SO MUCH !
...now I have in mind another thing : at the first start of this module, reading the current of overrload and memorized him in eeprom, for using as reference for further decoupling of relays. I read about this first 'calibration' in "12F675 Voltage monitor" by Frank Miller. Now I don't know how reading the highest level of voltage assuming the variation of tension is something like this ...
PS : Hope not making mistake if I bring here this new subject...
PS2 : A new observation : It's enough to put 1 uF capacitor; don't need to replace the two diodes on relays ! I try this on the other module.

Acetronics2
- 9th August 2009, 15:04
Hi, Fratello

you should try the ICL 7663 as a regulator, instead of the 78L05 ...

quiescent current is ... rather interesting !!!

Alain

Darrel Taylor
- 9th August 2009, 22:45
That 10ľA or less quiescent looks really nice.

Is there something like that in a fixed voltage TO-92, so fratello can just stick one in his PC board?
<br>

Acetronics2
- 10th August 2009, 09:23
That 10ľA or less quiescent looks really nice.

Is there something like that in a fixed voltage TO-92, so fratello can just stick one in his PC board?
<br>

Hi, Darrel

LP 2950 ACZ 5.0 from National, i.e.???

regards

Alain

fratello
- 10th August 2009, 16:42
I try to put another 'tips' in the code of this button.
At start ( plus by auto's contact) the PIC read from eeprom the value of overrload (variable "calibra"). If this is zero or less than minimum value (setting by me at 270 mV) start subroutine "calibration:". The value of maximum tension reading here are memorized as new value for "calibra".
One new start : the value of calibra is NOT zero or less than minimum value, so the module works as usual.
It's correct the code ? I think it's something wrong with reading/writing "calibra" from eeprom ?!? How write correct value of "calibra" in eeprom ?

fratello
- 10th August 2009, 18:19
I made some experiments ; the window roll-up (or roll-down) in about 6 seconds. I'm thinking to something like this :
...............
eeprom 0, [0, 0]
..............
read 0, calibra.byte0
read 1, calibra.byte1
if calibra =0 then
high rel1
....read U for maximum 7-8 seconds
....identify the highest value of U
....write this value in eeprom for further using as max.value in check:
low rel1
endif
..............
main:
....etc,etc.

Help, please, with the red lines; starting with what ? I use "search" but perhaps not so good ; I can't find one "clue" ! Thanks for supporting me !

fratello
- 10th August 2009, 20:01
I read about MAX. It's this correct :
'------------------------
read 0, calibra.byte0
read 1, calibra.byte1
if calibra =0 then
high rel1
gosub calibration
endif
'------------------------
calibration:
for cnt=0 to 80
adcin 3, v_cal
v_cal=v_cal * 5000
v_cal=div32 1023
vmax=vmax max v_cal
pause 100
next cnt ' reading v_cal for about 8 seconds ?
endfor
low rel1
calibra=vmax
calibra.highbyte = ADRESH
calibra.lowbyte = ADRESL
write 0, calibra.byte0
write 1, calibra.byte1
Return
'---------------------------
Thanks for any advice !
L.E.: The problem is : writing vmax ( example: 275) to eeprom, and then reading.

fratello
- 11th August 2009, 16:14
This is my working code :
calibration:
rel1=1 ' rel1 = 1 -->> window roll-up !
for cnt=1 to 80 ' assuming window roll-up complete in 8 seconds !
adcin 3, v_cal
v_cal=v_cal * 5000
v_cal=div32 1023
vmax=0 max v_cal
pause 100
next cnt

low rel1
calibra = vmax
if calibra > 20 then ' "20" is value knowing by user !
write 0, calibra.byte1
pause 10
write 1, calibra.byte0
pause 10
else
calibra = 19
write 0, calibra.byte1
pause 10
write 1, calibra.byte0
pause 10
endif
RETURN

fratello
- 15th August 2009, 17:19
The value for long press button it's a little to big. I want to reduce him. So,
Please, help :
Timer1 = 3037 ' 1 second
Timer1 = ? ' for 0.5 sec
' for 0.6 sec
' for 0.7 sec
' for 0,8 sec
Thanks !

Darrel Taylor
- 15th August 2009, 23:12
3037 with a prescaler of 1:8, sets Timer1 to 500mS periods.
2 of those periods are counted to reach 1 second.

To calculate the number for any other time period, download mister-e's calculator ...

PicMultiCalc v1.3.1
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2957

In the "Timer Helper" app, set the time to 300ms and it shows the reload value as 28037. Two 300ms periods would give you a total time of 600ms.

Set it to 500mS and you'll see where I got the original number.

Any other period can be calculated easily.
<br>

fratello
- 16th August 2009, 07:26
Thank You !

fratello
- 22nd April 2010, 18:09
As a supplement measure of safety I try to re-define the "check procedure" : if vs > 270 OR "time elapsed from but(1 or 2) = 1, no matter if long/short press" > 10 seconds then low rel . But, of course :( , the code not react as I wish...What I do -again- wrong ?! Thanks in advance for reply !
'************************************************* ***************
'* Name : THE_BUTON_sleep.BAS *
'************************************************* ***************
'
'
'
@ DEVICE PIC12F675, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, bod_off

INCLUDE "Elapsed.bas"

DEFINE OSC 4
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50

CMCON = 7
OPTION_REG = %10000110
TRISIO = %00011110
ANSEL = %00011000
ADCON0 = %10001101

GIE var intcon.7 ' global interrupt enable 1=on ; 0=off
gpie var intcon.3 'port change interrupt enable 1=0n ; 0=off
gpif var intcon.0 'port change interrupt flag bit

adval var Word
vt var word
u var byte
cnt var byte
but1 var gpio.3
but2 var gpio.2
rel1 var gpio.5
rel2 var gpio.0

Timer1 VAR WORD EXT :@Timer1 = TMR1L
TMR1ON VAR T1CON.0
TMR1IF VAR PIR1.0
T1Count VAR BYTE
LongPress VAR BIT
T1CON = %00110100

timpulUP var byte


u=0
cnt=0
GIE=0
GPIE=1
IOC.2=1 ' int-on-change for GPIO.2 enabled
IOC.3=1 ' int-on-change for GPIO.3 enabled

but1=0
but2=0
rel1=0
rel2=0

timpulUP=0
Gosub ResetTime ' Reset Time to 0d-00:00:00.00

pause 100

main:
rel1=0
rel2=0
@ sleep
pause 100
Timer1 = 3037
T1Count = 0
LongPress = 0

btn1: 'actionare buton up

if but1=1 and rel2=0 then

'this lines added ----------------
Gosub StartTimer ' Start the Elapsed Timer
IF SecondsChanged THEN
SecondsChanged = 0
IF Seconds = 10 THEN
TimpulUP=1

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
ENDIF
ENDIF
'----------------------------------
high rel1
TMR1ON = 1
pause 20

while but1=1
call check
wend
IF LongPress THEN Stop_UP
T1Count = 0
pause 20

while but1 = 0 and but2 = 0
call check
if rel1=0 then
GOTO Btn1PressDone
endif
wend
Stop_UP:
LOW rel1

while but1=1 OR but2 = 1
wend
pause 100
endif
GPIF=0 'Clear ort change interrupt flag

Btn1PressDone:


btn2: ' actionare buton down
'this lines added ----------------
Gosub StartTimer ' Start the Elapsed Timer
IF SecondsChanged THEN
SecondsChanged = 0
IF Seconds = 10 THEN
TimpulUP=1

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
ENDIF
ENDIF
'----------------------------------
if but2=1 and rel1=0 then
high rel2
TMR1ON = 1
pause 20

while but2=1
call check
wend
IF LongPress THEN Stop_Down
pause 20

while but2 = 0 and but1 = 0
call check
if rel2 = 0 then
GOTO Btn2PressDone
endif
wend
Stop_Down:
low rel2

while but2=1 or but1=1
wend
pause 100
endif
GPIF=0 'Clear ort change interrupt flag
Btn2PressDone:

GOTO MAIN

check: ' verificare pentru supracurent
adcin 3, adval
vt=adval * 5000
vt=div32 1023

for cnt = 1 to 5
if vt > 270 or timpulUP=1 then
u=u+1
if u > 5 then
gpio.0=0
gpio.5=0
endif
pause 50
goto check
else
u=0
Gosub ResetTime
endif
next cnt

IF TMR1IF then
TMR1IF = 0
Timer1 = 3037
T1Count = T1Count + 1
if T1Count = 2 then
TMR1ON = 0
T1Count = 0
LongPress = 1
endif
ENDIF

return


end ' of program

fratello
- 23rd April 2010, 07:51
I discover some errors in the code I posted yesterday.


btn1: 'actionare buton up

if but1=1 and rel2=0 then

'this lines added ----------------
Gosub StartTimer ' Start the Elapsed Timer
IF SecondsChanged THEN
SecondsChanged = 0
IF Seconds = 10 THEN
TimpulUP=1
ENDIF
ENDIF
'----------------------------------
high rel1
TMR1ON = 1
pause 20

'----------------------- // ---------------------------------------
'----------------------- // ---------------------------------------

btn2: ' actionare buton down

if but2=1 and rel1=0 then

'this lines added ----------------
Gosub StartTimer ' Start the Elapsed Timer
IF SecondsChanged THEN
SecondsChanged = 0
IF Seconds = 10 THEN
TimpulUP=1
ENDIF
ENDIF
'----------------------------------
high rel2
TMR1ON = 1
pause 20

'----------------------- // ---------------------------------------
'----------------------- // ---------------------------------------

check: ' verificare pentru supracurent
adcin 3, adval
vt=adval * 5000
vt=div32 1023

for cnt = 1 to 5
if vt > 270 or timpulUP=1 then
u=u+1
if u > 5 or timpulUP = 1 then
gpio.0=0
gpio.5=0
Gosub ResetTime
endif
pause 50
goto check
else
u=0
Gosub ResetTime
endif
next cnt

'----------------------- // ---------------------------------------
'----------------------- // ---------------------------------------



Still not work fine...

fratello
- 23rd April 2010, 17:58
My previous posts are wrong !
This is what work good for me ( about 10 seconds) :

btn1: 'actionare buton up

if but1=1 and rel2=0 then
high rel1
TMR1ON = 1
pause 20

while but1=1
t1Count=T1Count+1
call check
wend
IF LongPress THEN Stop_UP
T1Count = 0
pause 20

while but1 = 0 and but2 = 0
t1Count=T1Count+1
call check
if rel1=0 then
GOTO Btn1PressDone
endif
wend
Stop_UP:
idem for btn2
and :
if vt > 270 o then
u=u+1
if u > 5 or T1Count > 100 then
gpio.0=0
gpio.5=0
endif
pause 50
goto check
else
u=0


It's correct what I do ? Thanks !