Single switch on/off

Thread Starter

geoffers

Joined Oct 25, 2010
520
Hi,
If I could refer to your schematic, I guess you have a stable 12v supply so the divider formed by the resistor before the switch and the pull down, coupled with a 1v drop across the diode mean when the switch is pressed 5v is applied to the pic and the reg. Have I got that right? If I overdrive my pic, when the switch is pressed, as well as more than 5v on the I/O which is configured as a input, there would also be more than 5v on the I/O which is configured as a output. (The one holding up the enable of the reg) Would I need to put a doide there to prevent the pic doing anything unexpected? Or does the fact its configured as a output mean its already protected? I couldn't see in the data sheet anything about the max voltage on the enable pin either. Think I will get one and see what happens.
Thanks again for your help. Geoff
 

ErnieM

Joined Apr 24, 2011
8,415
Yeah I assume my battery voltage is 12-14V, it's a big old lead acid battery. The PIC requires about 1mA for 5V operation and there is no way R1 can supply that current (1mA * 100K ohm = 100V!) so I don't ever run the device off the input power.

Assume everything is off: Button gets pressed, EN of U2 rises to turn the U2 regulator on, that powers the PIC which then sets GP5 to an output to sustain the U2 enable. R1/D2/R2 acts as a voltage divider to put about 5V on enable.

To sense button presses the R1/D3/R3 chain presents about 5V at the GP3 input. Note there is no ESD diode on this input as it is also MCLR and thus a high voltage (12-13V) input. I've found no limit to the digital voltage

D2 and D3 are there to keep enable and button press separate: D2 blocks GP5 from driving GP3 and D3 blocks the programming voltage from MCLR to GP5.

Now your usage uses two conventional I/O pins. I don't think there is anything that stops this scheme from working. I'm not convinced you need those diodes but I'm going to complete my project before I go down that path (they are too similar and my brain gets confused doing that).
 

Thread Starter

geoffers

Joined Oct 25, 2010
520
Hi all,
Havn't had much time recently but have been poking about with this again now! The programme running in my PIC really needs to be interrupted when the button is pressed, like a fool I've already used portb0, and 1 as ouputs for another part of the circuit, I'd change it so I could use them as external interrupts, but I've aready made the board......
Looking through the data sheet for the 18f2523 I saw that the other external interrupts are change on portb, or the HLVD on ra5 which I happen to have free! From my reading of the data sheet I should be able to use a potential divider on my switch to step the 9v battery voltage down to 4v or so, tie ra5 to ground and use the high low voltage dectect when ra5 is raised above say 3v to trigger the interrupt I need? Can anyone see a problem with that? Will let you know how it goes!
Cheeers Geoff
 

Thread Starter

geoffers

Joined Oct 25, 2010
520
Hi all,
Missread the datasheet:( Its when the device experiances a voltage change not the pin! Darn it, back to the drawing board!
 

Thread Starter

geoffers

Joined Oct 25, 2010
520
Hi all,
Finaly got it all together and working!
View attachment on-off-reg.pdf

Hope thats readable?
R1=100k
R2=560k
R3=39k

Plug 1 is, a=pic input
b=pic output
Plug 2 is the push switch

Origninaly R3 was going to be 390k but I messed up my code a little (set the wrong bit in the tris reg!:mad:) and changed it before I realised! D3 might not be needed? Better safe than sorry though! I got around my interrupt prob by poling the input in the isr. Thanks to Ernine M, never would have got it sorted without your help!
Cheers Geoff.

Ps as a aside, what is the best image format to use on this forum?
 

ErnieM

Joined Apr 24, 2011
8,415
Congrats on getting this to work. I can only assist, you have to do the heavy lifting.

Funny, I too had a programming hiccup and changed the hardware before I caught it could be fixed with code. But since the change saved a diode I left it.

For posting images I prefer a simple bitmap or GIF. One trick is to put it in as an attachment, then put the file link from the attachment manager tab into the image box on the post page.
 
Top