PDA

View Full Version : A new challenge (I'm in trouble again)



Davidmarks
- 17th February 2012, 01:11
My recent successes with my Christmas star have got me a request from a neighbour for lighthouse flashing circuit for his model lighthouse. No problem with flashing routines,\however the requirement is to have automatic shutdown (battery saving). To achieve this with a 16f628a I have fed the pic via a pnp switching transistor (2n3906) base is pulled up with 4.7k
and connected to porta.1 via 22k. To start up a pushbutton is also connected to the 22k which pulls the base to 0 and switches on the transistor. This works OK ---HOWEVER I wish to use the same pushbutton to change the flashing routine therefore I have to free up the pushbutton and make porta.1 an input. In order to do this I have connected an identical \transistor switch to portb.0 to hold the supply on whilst using porta.1 as an input. This does not work and I can't for the life of me figure out why. The effect that this produces is that the "power" on led in the circuit lights (at very slightly less than full brightness) then when I press the button (i.e. switch on the transistor which is driven from Porta.1) the flashing routine commences but only continues whilst I hold the button down and then after 12 flashes freezes with the flashing led on ! What the devil is going on ? The code I have written is as follows . Hope I have made this clear without attaching the circuit (haven't figured out how to do that yet... will have another look tomorrow. Cheers

[@ DEVICE pic16f628a,intrc_osc_noclkout,mclr_on

x var word
output portb.0
output portb.3
output porta.1
output porta.0
porta.1 = 0
portb.0 = 0

input porta.1

for x = 1 to 12

high portb.3
pause 200
low portb.3
pause 200
next x
end
]

J. Mark Wolf
- 17th February 2012, 16:46
I didn't fully evaluate how your'e doing it, but it sounds suspiciously similar to a circuit I designed several years back, and has worked well ever since.

It should do what you need.

The "gist" of the way it works is the very first button push will switch power on. The PIC must quickly set the "Master_On" signal to keep power on. Subsequent button presses will simultaneously try to power the system up again, but since it is "already" powered up, it will simply toggle the "BTN1" signal.

The PIC must clear the "Master_ON" signal to turn power off.

None of the circuits are critical so feel free to make substitutions, but be sure to use two diodes.


6281

ardhuru
- 18th February 2012, 03:26
Here's a very simple way to do this; http://www.best-microcontroller-projects.com/Rechargeable-Battery-Protection-Circuit.html

I havent tried this myself yet, though.

Regards,

Anand Dhuru

Davidmarks
- 19th February 2012, 13:18
Thanks for the help folks. I'm afaid Marks that your circuit uses devices not readily available to me and is alittle more complex than I wanted - many thanks for your trouble however. Ardhuru -- looked at the site you suggested but can't relate it to my problem ... thanks anyway. I have tried to approach the problem another way i.e. to use the sleep command to minimise power consumtion. Im still having problemas however (brain ain't what it used to be) hence a new post related to interrrupts which I am about to submit.

Acetronics2
- 19th February 2012, 13:44
Hi,

Thinking to it twice ...

some times ago a friend of us from Argentina, called "PEU" asked for help for a hand light device and some kind of automated start/stop sequence like you look for ... was aboard a 12F683.

Alain

Acetronics2
- 19th February 2012, 14:08
Was about end 2007 to 2008 ...

not sure it has been lost ...

Wow !!! got it in my archives ( 04/2008 )



'@ device pic12f675,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off, bod_on
@ __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _WDT_OFF &_BODEN_ON & _MCLRE_OFF & _CP_OFF

'************************************************* ****************************
'Config
'************************************************* ****************************

'OSCCON = %01100110
CMCON = %00000111 ' Disable comparator
VRCON = %00000000 ' disable
ADCON0 = %11100000
ANSEL = %10000000
'************************************************* ****************************
' I/Os
'************************************************* ****************************
GPIO = %00000000 ' All outputs low
TRISIO = %00000000 ' no inputs
'************************************************* ****************************
'Aliases
'************************************************* ****************************
BODbit var GPIO.0
PORbit var GPIO.1
BOD var GPIO.2
LED var GPIO.4
'************************************************* ****************************
' Init vars
'************************************************* ****************************
Selection var Byte
Ton var Word
Toff var Word
'************************************************* ****************************
Coldstart:
'************************************************* ****************************

IF PCON.1 = 0 and PCON.0 = 0 THEN BODbit = 1 'BROWN OUT RESET BIT
IF PCON.1 = 0 THEN
PORbit = 1 'POWER ON RESET BIT
' For debugging purpose only !!!

Selection = 1 'Lights LED @ 25%
ENDIF
PAUSE 1000
GPIO = 0
IF PCON.1 = 1 AND PCON.0 = 0 THEN 'PCON.0 = BOD ;PCON.1 = POR

BOD = 1 'GPIO.1 red led PIN6 shows a BOD state
PAUSE 1000 ' For debugging purpose only !!!
GPIO = 0

Selection = ( Selection + 1 )// 5


ENDIF
PCON.1 = 1
PCON.0 = 1
'************************************************* ****************************
'Program choice
'************************************************* ****************************
SELECT CASE Selection
CASE 0
Ton = 0 ' Stop

CASE 1
Ton = 500 ' 25%

CASE 2
Ton = 700 ' 50%

CASE 3
Ton = 870 ' 75%

CASE 4
Ton = 1000 '100%

END SELECT


'************************************************* ****************************
'Power Drive
'************************************************* ****************************
Toff = 2000 - Ton
IF Ton = 0 THEN ' LED OFF
LED = 0
@ SLEEP ' IF Power = 0 then snore !!!
@ NOP ' and wait for a Power off ...
' That ALSO saves the batt ...
ENDIF

'NOTE : WAKE UP is achieved by Powering OFF the device ... not the classical way !
' !!! WDT MUST be OFF !!!

IF Ton = 1000 THEN ' LED @ 100%
LED = 1

WHILE 1 ' Endless loop until power Off !!!
WEND

ENDIF
WHILE 1 ' Soft PWM @ 500Hz until power OFF
LED = 1
PAUSEUS Ton
LED = 0
PAUSEUS Toff

WEND
END


have fun ...

Alain