Author Topic: Chicken Door Opener / 4 AA cells direct to PIC?  (Read 17651 times)

0 Members and 1 Guest are viewing this topic.

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Chicken Door Opener / 4 AA cells direct to PIC?
« on: May 05, 2017, 02:16:09 pm »
I'm knocking up a gadget to add to my chicken house door which already has a door opener

Basically I am just going to intercept the timer wires and add a manual override with an UP and DOWN button.
This could probably have been achieved with a bit of logic but I have loads of bits and pieces in the junk box so I have decided to use...
a PIC18F1320 in conjunction with a 2-coil latching relay and a couple of switches. (The idea being that in normal operation the gadget is off and out of circuit with the normal behaviour through the relay, pressing a button wakes it up, latches the relay and powers the circuit until it turns itself off again some time later)

I'm proposing to just attach the PIC et al direct to the existing battery supply (4xAA) of the chicken door with a protection diode (also giving a voltage drop)

Is this reasonable or should every microcontroller have a voltage regulator?

Thanks in advance
« Last Edit: May 26, 2017, 05:28:52 pm by NivagSwerdna »
 

Offline tszaboo

  • Super Contributor
  • ***
  • Posts: 7377
  • Country: nl
  • Current job: ATEX product design
Re: 4 AA cells direct to PIC?
« Reply #1 on: May 05, 2017, 02:55:03 pm »
4AA is up to 6V, diode drop is not 0,6V but depends on how much current there is, down to 0V. So technically no. Realistically, your PIC will never break, because it works up to 5.5V and to get it damaged, you need power, so some current. Is there any chance it will get the full 6V through a GPIO?
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: ca
Re: 4 AA cells direct to PIC?
« Reply #2 on: May 05, 2017, 02:59:56 pm »
Hi,

Can you tap the battery? That is run the uP from three cells and any power stuff from 4? You may need level shifters (transistors or MOSFETs).

Regards,

Jay_Diddy_B
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #3 on: May 05, 2017, 03:14:07 pm »
Use an HV variant PIC?
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13747
  • Country: gb
    • Mike's Electric Stuff
Re: 4 AA cells direct to PIC?
« Reply #4 on: May 05, 2017, 03:18:19 pm »
More diodes to ensure it can never go over 5v. There's plenty of room to go down before it stops working.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Spuddevans

  • Supporter
  • ****
  • Posts: 68
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #5 on: May 05, 2017, 04:10:56 pm »
Or use 4 Nimh rechargables, ie 4.8V

Tim
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #6 on: May 05, 2017, 04:19:53 pm »
The part, PIC18F1320 is rated to 5.5V.  I don't really want to change the batteries with are currently Alkaline.

One thing I hadn't considered was voltage sag when the door motor is raising... I'll have to measure that otherwise I might be looking at Brownouts.

I thought a diode would drop 0.6V... is that too simplistic/wrong?
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 7733
  • Country: ca
Re: 4 AA cells direct to PIC?
« Reply #7 on: May 05, 2017, 04:36:12 pm »
Fresh brand new alkalines are as high as 1.7v.  That's 6.8v.  For my similar projects, I use 2 silicon diodes in series, 1N400x series, to power my PIC, which runs at 5.5v on the nose with 4 brand new batteries.  Remember, the PIC will run even below 2.5v and as your batteries drain to 1v each, total of 4v, the PIC will still be working receiving 2.6v.
 
The following users thanked this post: NivagSwerdna

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #8 on: May 05, 2017, 04:52:19 pm »
Perhaps you could use an ultra low current linear regulator like the MC78LC00 series, and use a PIC18LF1320 at 3.3V, with your power electronics direct from the batteries?

The MC78LC00 series have a typical quiescent current of 1.1uA, which is about 200 years on a bank of series AAs.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: 4 AA cells direct to PIC?
« Reply #9 on: May 05, 2017, 05:00:40 pm »
i would use 1 cell + MCP1624/1640 boost converter for the micro and keep the 4 cells for the IO. linear regulator has a higher quiescent current, so i wouldn't go that way. those mcp1624/1640 were developed for powering PIC MCUs.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: 4 AA cells direct to PIC?
« Reply #10 on: May 05, 2017, 05:21:53 pm »
The part, PIC18F1320 is rated to 5.5V.  I don't really want to change the batteries with are currently Alkaline.

One thing I hadn't considered was voltage sag when the door motor is raising... I'll have to measure that otherwise I might be looking at Brownouts.

I thought a diode would drop 0.6V... is that too simplistic/wrong?
A diode will drop is less than 0.6V at low currents or high operating temperatures, look up the diode equation.

The MCU is rated to operate up to 5.5V, so irrespective of whether specified or not on the datasheet, it can withstand higher voltages, without any damage. Even more so, if you're not planning to operate it anywhere near the maximum temperature rating of 125oC. Running close to or slightly above the maximum specified voltage rating, might not be ideal and could potentially shorten its life slightly but this is only a hobby project and not a high reliability application then it will be fine.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #11 on: May 05, 2017, 07:54:14 pm »
Note the specs for F version of the device are 4.2-5.5V, which is why I was suggesting a low Iq 3.3V LDO instead of a diode and the LF version which runs at 2.0 to 5.5V, although you need to take care of the clock speed limitations at lower voltages, not a problem I'd have thought in this application.

My concern is over running power electronics with an MCU on an unregulated supply, as glitches on the supply can cause a lot of unwanted headaches. I learned that lesson sometime in the mid 70s when a voltage regulator was a week's pocket money, so I tried without, and it scarred me for life!
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #12 on: May 22, 2017, 09:29:21 am »
It was going quite well... I have the switching relay working and with a 100uF capacitor to keep the PIC alive long enough to fully switch the relay off it can turn itself off.

However, I have a slight unexpected problem and I'm a bit stuck at how to solve it (and I apologise in advance to all those who thought I should keep the PIC alive but in sleep)

The circuit basically has two in contacts that lead to two out contacts.  The in contacts are connected to a timer which is open most of the time but closed some of the time to close the door, my circuit effectively goes in between.

When asleep the idea of my circuit was that it would be completely out of circuit however I have one point where I ran out of switch contacts... the door sense input pin is permanently wired from the input to RB1.

I did a test where the output was connected to an LED via a limiting resistor to the +ve rail, it works perfectly BUT when the circuit is in straight through mode there should be zero current and the LED should be off (I think the actual output goes into a part of the door opener that charges a capacitor that operates a FET), however instead there is a very faint glow.  It appears that a very small current is going through RB1 to ground even though the PIC is powered off.  (PORTB had pin-ups enabled and RB1 was configured as an input when the PIC lost power)

300k into 5V... is actually quite a big current... 17uA? 

Any suggestions on how I could reduce this leakage current or do I need to go back to the drawing board?

Thanks in advance
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: 4 AA cells direct to PIC?
« Reply #13 on: May 22, 2017, 10:30:07 am »
4AA is up to 6V

With fresh alkaline batteries, significantly more, you should design for at least 1.65V/cell = 6.60V, which is way over the absolute maximum rating even with a single series diode, and I wouldn't rely on the DCR of the AA cells combined with increased leakage in the PIC before the destruction; fresh, high-quality cells can and definitely will damage a 5.5V rated PIC except by pure luck.

Was there a problem using 3 AA cells? That would be the standard way. Otherwise, a bunch of series diodes (normal PN diodes, not schottkys) can be pretty much trusted to drop at least about 0.3-0.4V each, even at miniscule currents caused by leakages. So you need absolute minimum of three, preferably four.

But a simple 3V3 LDO may be easier and cheaper than four diodes in series.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: 4 AA cells direct to PIC?
« Reply #14 on: May 22, 2017, 10:51:08 am »
4AA is up to 6V

With fresh alkaline batteries, significantly more, you should design for at least 1.65V/cell = 6.60V, which is way over the absolute maximum rating even with a single series diode, and I wouldn't rely on the DCR of the AA cells combined with increased leakage in the PIC before the destruction; fresh, high-quality cells can and definitely will damage a 5.5V rated PIC except by pure luck.
The over voltage might explain the increased leakage but you're be very unlucky if you destroy the PIC. It will be able to withstand 6.5V and the diode will drop some voltage, even at low currents. Perhaps if it's operating at its maximum temperature rating, whilst being subjected to the absolute maximum voltage, then there's a real risk of damage, otherwise it's highly unlikely.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #15 on: May 22, 2017, 11:12:03 am »
I'm currently using a 5V bench supply.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8172
  • Country: fi
Re: 4 AA cells direct to PIC?
« Reply #16 on: May 22, 2017, 11:35:57 am »
The over voltage might explain the increased leakage but you're be very unlucky if you destroy the PIC. It will be able to withstand 6.5V and the diode will drop some voltage, even at low currents. Perhaps if it's operating at its maximum temperature rating, whilst being subjected to the absolute maximum voltage, then there's a real risk of damage, otherwise it's highly unlikely.

Maybe we are reading different datasheets, but the one in front of me(*) says +5.5V on the Vdd pin respect to the Vss pin is the absolute maximum rating.

And in my experience, exceeding datasheet absolute maximum ratings, often even slightly, have the tendency to blow the parts up very quickly, or worse, do some sneaky damage that will cause undefined, hard to debug behavior later on.

Maybe this particular part is different for one reason or another, I don't know, but extraordinary claims require extraordinary evidence, and without such evidence, I would not speak about blowing it up would be unlikely.

In any case, trusting the prior experience on particular PIC parts surviving and working properly even after severely exceeding absolute maximum ratings is a stupid engineering decision, since the manufacturing process for the parts can change at any point of time without prior notice. This is especially dangerous advice for a noob, since noobs will have enough strange issues to solve in the vast world of MCUs already; overvoltage damage is easy to avoid by not applying overvoltage on purpose.

Get the power supply within specs with ample margin, decouple with a lossy electrolytic, and apply proper ceramic decoupling right next to the MCU power pins, take basic ESD precautions, and you can expect that any strange behavior is most likely due to bugs in code.

(*) http://ww1.microchip.com/downloads/en/DeviceDoc/39605F.pdf
« Last Edit: May 22, 2017, 11:39:53 am by Siwastaja »
 
The following users thanked this post: janoc

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #17 on: May 22, 2017, 11:42:54 am »
I have never exceeded 5V with this part.... seems the over-voltage police are out in force today.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #18 on: May 22, 2017, 12:01:13 pm »
Make sure external /MCLR and INTOSCIO (if available) are enabled in the CONFIG. Power the PIC with 5.0V +/-5%.  Jumper /MCLR to Vss to hold the PIC in reset.  That forces all I/O pins to be inputs.  If the leakage current for any of them is greater than the maximum limit in the datasheet electrical characteristics section, AND the pin voltage is between the Vdd and Vss rails (inclusive) the PIC is damaged, probably due to ESD.   If the problem goes away when the PIC is held in reset, there's something wrong with your code . . . .

I'm with those who say NEVER over-voltage a MCU.  Although there are anecdotes about PICs surviving excessive voltage up to maybe 12V and apparently working afterwards, you never see a proper followup where the PIC was tested to see if it still met its datasheet specs etc.   They are the MCU equivalent of a "Man bites Dog" news story.  A low power 5V LDO regulator isn't grossly expensive, you need Vdd decoupling anyway, so with its input cap its only two extra parts for in-spec Vdd and peace of mind.
 
The following users thanked this post: NivagSwerdna

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #19 on: May 22, 2017, 12:13:00 pm »
If the leakage current for any of them is greater than the maximum limit in the datasheet electrical characteristics section
I assume the datasheet limits are intended for when the device is powered?  So in my case the PIC isn't powered (except via the protection diodes???)...
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #20 on: May 22, 2017, 12:17:31 pm »
It appears that a very small current is going through RB1 to ground even though the PIC is powered off.  (PORTB had pin-ups enabled and RB1 was configured as an input when the PIC lost power)

300k into 5V... is actually quite a big current... 17uA? 

I may well have misunderstood, but if the PIC's not powered but there is voltage on a non-power pin, the protection diodes on that pin will effectively supply power the PIC.

Having said that, RB1 is also an analogue pin so there may not be a Vdd protection diode. This doesn't mean you should ever apply a voltage above Vdd or below Vss except in very specific case like programming.

From the datasheet:

Code: [Select]
Voltage on any pin with respect to VSS (except VDD, MCLR and RA4) .......................................... -0.3V to (VDD + 0.3V)

Apologies if I've misunderstood what's happening here.

(Edit: sorry, I started writing this about 90 mins ago, others have since jumped in).
« Last Edit: May 22, 2017, 12:19:06 pm by Howardlong »
 
The following users thanked this post: NivagSwerdna

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #21 on: May 22, 2017, 12:26:13 pm »
You cant do that.
Quote from: Absolute Maximum Ratings
Voltage on all other pins with respect to VSS ......................................... -0.3V to (VDD + 0.3V)
When unpowered, Vdd=Vss=0V, so voltages on I/O pins *MUST* be limited to +/- 0.3V.

If you need to turn a PIC 'off' while maintaining logic levels on input pins, you need to use SLEEP mode.   Done right, the quiescent current consumption is negligible - e.g a CR2032 coin cell could power a sleeping PIC till the end of its shelf life and still have charge left.  Done wrong (unnecessary peripherals left enabled,  outputs loaded or floating inputs), it could drain the same coin cell in days or weeks.
 
The following users thanked this post: NivagSwerdna

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #22 on: May 22, 2017, 12:30:11 pm »
When unpowered, Vdd=Vss=0V, so voltages on I/O pins *MUST* be limited to +/- 0.3V.
Ah.  Now that could be a problem.  Vdd is flapping in the breeze.  RB1 is at the end of the current limiting resistor so being pulled up (not sure how far).
So... back to the drawing board... or put a common drain source follower in front??  I need some way of isolating RB1 as an input when the PIC is unpowered.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: 4 AA cells direct to PIC?
« Reply #23 on: May 22, 2017, 12:57:41 pm »
The over voltage might explain the increased leakage but you're be very unlucky if you destroy the PIC. It will be able to withstand 6.5V and the diode will drop some voltage, even at low currents. Perhaps if it's operating at its maximum temperature rating, whilst being subjected to the absolute maximum voltage, then there's a real risk of damage, otherwise it's highly unlikely.

Maybe we are reading different datasheets, but the one in front of me(*) says +5.5V on the Vdd pin respect to the Vss pin is the absolute maximum rating.

And in my experience, exceeding datasheet absolute maximum ratings, often even slightly, have the tendency to blow the parts up very quickly, or worse, do some sneaky damage that will cause undefined, hard to debug behavior later on.

Maybe this particular part is different for one reason or another, I don't know, but extraordinary claims require extraordinary evidence, and without such evidence, I would not speak about blowing it up would be unlikely.

In any case, trusting the prior experience on particular PIC parts surviving and working properly even after severely exceeding absolute maximum ratings is a stupid engineering decision, since the manufacturing process for the parts can change at any point of time without prior notice. This is especially dangerous advice for a noob, since noobs will have enough strange issues to solve in the vast world of MCUs already; overvoltage damage is easy to avoid by not applying overvoltage on purpose.

Get the power supply within specs with ample margin, decouple with a lossy electrolytic, and apply proper ceramic decoupling right next to the MCU power pins, take basic ESD precautions, and you can expect that any strange behavior is most likely due to bugs in code.

(*) http://ww1.microchip.com/downloads/en/DeviceDoc/39605F.pdf
There must be an error in the datasheet. They specify it to work up to 5.5V, yet also state it's the absolute maximum rating. Making the maximum operating voltage equal to the maximum rating would be a very bad idea and is generally not done. In light of this information, we need to refer to another datasheets for another PICs in the same family, which will be made using the same process therefore have the same tolerance to over-voltage.

http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/39689f.pdf
http://ww1.microchip.com/downloads/en/DeviceDoc/39758D.pdf

The all say 7.5V as the absolute maximum voltage applied between VSS and VDD. I only guessed 6.5V because it's what the older 5.5V parts such as the old 12F509 are rated to.
 
The following users thanked this post: pelud

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #24 on: May 22, 2017, 01:16:18 pm »
Lets see a schematic of what you have so far.
I suspect the mistake is trying to power down the PIC without also powering down *EVERYTHING* connected to it.  As its max quiescent current is under 5uA (in SLEEP mode, all peripherals shut down etc.), if you leave it powered, it will  use under 2% of the capacity of a battery of Alkaline AA cells in their 7 year shelf life - negligible compared to the expected 20% self-discharge.

 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #25 on: May 22, 2017, 01:17:17 pm »
To be fair the device I am currently using is 18F1320 (which I had lying around)...

Voltage on VDD with respect to VSS ... -0.3V to +5.5V
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #26 on: May 22, 2017, 01:18:41 pm »
Lets see a schematic of what you have so far.
Good plan.  I'll draw something up.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #27 on: May 22, 2017, 02:01:33 pm »
OK... posting my circuit (from memory)... only on the basis that you all promise to play nicely.... (I know I should probably use a LDO and sleep mode)... The gadget will be on for approx 3 hours per month.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #28 on: May 22, 2017, 02:39:28 pm »
The kindest thing I can say about that schematic, is that the design was obviously an evolutionary process.   Your choice of an optocoupler for non-isolated output is unusual and rather power-hungry.

You could futz around with another 2N7000 MOSFET to disconnect the IN signal from RB1, with a pullup to Vss on the RB1 side, or even with a diode so IN can only pull the pin low, but IMHO the best option would be to ditch the relay and start over with the buttons and IN signal on interrupt capable pins so they can wake the PIC from sleep, and have it always powered and 'in the loop'.  IN would need to be on an IOC capable pin (RB4 or RB5 assuming you want to keep the ICSP/ICD pins free) so you could wake on both edges, but the buttons could be on ordinary INT pins (RB0-3) as you only need to wake when they are pressed.   If the wakeup was a button push it would perform whatever action you require, but if it was an IOC from the IN signal and it wasn't already performing a button action, it would simply repeat that to the OUT.

We'd need a few more details about the IN and OUT signals to decide on the best interface for each . . . .





 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #29 on: May 22, 2017, 02:56:53 pm »
The kindest thing I can say about that schematic, is that the design was obviously an evolutionary process.
:)

   Your choice of an optocoupler for non-isolated output is unusual and rather power-hungry.
Hm.  The intention was that when active the output would be isolated. When the latch is latched the OUT is driven by the Opto and not connected to anything else but they do share ground.  On reflection I guess that could just be a 2N7000.  I didn't want to sink the current directly at the PIC since it could be >5V.  I also don't know the lower bound of the door terminal so if it was very low... that might not be good for VDS in a FET solution? Ideally I would not have the shared ground.. but I wasn't sure how to do that without more switching!

You could futz around with another 2N7000 MOSFET to disconnect the IN signal from RB1, with a pullup to Vss on the RB1 side, or even with a diode so IN can only pull the pin low, but
Yeap. I was wondering that.

IMHO the best option would be to ditch the relay and start over with the buttons and IN signal on interrupt capable pins so they can wake the PIC from sleep, and have it always powered and 'in the loop'.  IN would need to be on an IOC capable pin (RB4 or RB5 assuming you want to keep the ICSP/ICD pins free) so you could wake on both edges, but the buttons could be on ordinary INT pins (RB0-3) as you only need to wake when they are pressed.   If the wakeup was a button push it would perform whatever action you require, but if it was an IOC from the IN signal and it wasn't already performing a button action, it would simply repeat that to the OUT.
Definitely the simplest.. but I'm not sure exactly how to drive the outputs...

We'd need a few more details about the IN and OUT signals to decide on the best interface for each . . . .
OK... it's like this... the existing door opener has two terminals which connect to a timer.  The timer is normally-open but goes to closed during the door closed interval.  The terminals don't have any definition of their polarity and/or relation to ground or battery.  With a multimeter it appears that one of the terminals is directly connected to the same terminal that the battery -ve arrives from. i.e. the door closes then the door terminal is shorted to ground.
So for my gadget I have two input terminals for the timer... this is normally open but closed when the timer demands door close.  On the output it seems I need only one terminal since ground is really shared... on that terminal I need to be able to short it when I want the door closed and leave it open when I want the door open.
The idea of the gadget is that it holds the door open/closed as per user request until the timer matches the desired state at which point it goes to sleep.
A look at the door opener circuit itself suggests that there is a positive potential on the door timer terminal which when grounded either charges up the gate of a FET or allows a current to flow and turns on a BJT... not sure which... it's a black box to me.
The gadget is very rarely used... hence the desire for low to zero quiescent power demand.

Thanks for the interest  :)
« Last Edit: May 22, 2017, 03:32:00 pm by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #30 on: May 22, 2017, 03:47:42 pm »
I think I get that - the existing door motor box has an input that is continuously monitored.
If it transitions to grounded, the door closes then the motor shuts off.  If it transitions to open, the door opens then the motor shuts off.   The existing timer has volt-free contacts that shorts that input to ground when the door is scheduled to be closed.



As is, even with the relay, it has to maintain its output until the timer 'catches up'.  The drive current for the 4N24 is killing your power consumption.  Even at only 1mA (and I suspect you are using far more,) that's equivalent to a weeks power for a PIC in sleep mode, worst case, and probably something like 6 weeks to 2 months power if the typical figures are to be believed.

Interfacing to the door motor without extra quiescent current  isn't a problem - a N-MOSFET can do that easily.  The problem is the timer output - its grounded for the entire door closed period, so if you simply use a pullup resistor it will be drawing current whenever the door is closed.  You can mitigate that by using a high value pullup, but that increases the sensitivity to noise, and although you can use a debouncing algorithm to ignore the noise, the increased average current consumption due to unwanted wakeups during the door open period could be worse than the pullup resistor consumption during door closed.
If the pullup is under about 400K you'd do better to enable the watchdog timer (using SWDTEN), and use it to provide a  wakeup every minute or two, during which you enable the pullup (by setting an output pin driving the other end of the pullup to '1'), poll the IN signal and then turn the pullup off (actually turn it into a pulldown, by setting its control pin to '0'), all within a few ms.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #31 on: May 22, 2017, 04:07:52 pm »
The existing timer has volt-free contacts that shorts that input to ground when the door is scheduled to be closed.
This is actually an assumption that has always bothered me.  The existing timer shorts two contacts.  The definition that one is ground was by observation... ideally I would not assume that and just short or non-short two contacts without any particular reference to voltage or polarity but I don't know how to do that... I'm just ignorant in that respect.  I thought an Optocoupler might be a place to start but then ended up with common grounds since I wanted the gadget off state to be pass-through and only one side was switched. (And the opto has a specific polarity).

The drive current for the 4N24 is killing your power consumption.
It's a few mA which is BIG in the scheme of things but I'm also flashing the LEDs on the buttons so it is reasonably power hungry when operating.  e.g. You press DOWN and the DOWN button flashes intermittently until DOWN matches timer DOWN and then it turns off.  It does look nice though.  ;)  I also have a stay open/shut mode.. after a long-press... which leaves the door open/shut with the respective button permanently illuminated (until another press).
« Last Edit: May 22, 2017, 04:10:15 pm by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #32 on: May 22, 2017, 04:45:11 pm »
The existing timer has volt-free contacts that shorts that input to ground when the door is scheduled to be closed.
This is actually an assumption that has always bothered me.  The existing timer shorts two contacts.  The definition that one is ground was by observation... ideally I would not assume that and just short or non-short two contacts without any particular reference to voltage or polarity but I don't know how to do that... I'm just ignorant in that respect.  I thought an Optocoupler might be a place to start but then ended up with common grounds since I wanted the gadget off state to be pass-through and only one side was switched. (And the opto has a specific polarity).
If you really need a volt-free contact output with minimal power consumption, we are back to latching relays.  You couuld use a photo-MOSFET optoisolator like the TLP175A to provide a volt-free output that doesn't mind the polarity, but it needs 5mA of drive current for its LED, not exactly ideal when it could be required to sustain it for hours.

However, once you have confirmed that one terminal of the door motor box timer input is actually ground there is absolutely no reason to go the the extra expense and complexity compared to using a simple transistor output. 

You should measure the input current with the timer disconnected and the input terminals shorted via a DMM on mA, and also check the terminal voltage relative to battey 0V with the input open.  That would give you enough to be certain of your output requirements.

The drive current for the 4N24 is killing your power consumption.
It's a few mA which is BIG in the scheme of things but I'm also flashing the LEDs on the buttons so it is reasonably power hungry when operating.  e.g. You press DOWN and the DOWN button flashes intermittently until DOWN matches timer DOWN and then it turns off.  It does look nice though.  ;)  I also have a stay open/shut mode.. after a long-press... which leaves the door open/shut with the respective button permanently illuminated (until another press).

I'd use low duty-cyle flash pattens for both.  1/10 second on every ten seconds is still highly visible, but it reduces the average current by a factor of 100.   Even if you use a double flash to indicate the stay open/shut mode, that's still a factor of 50 better than just leaving the LED on all the time. 


 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: 4 AA cells direct to PIC?
« Reply #33 on: May 22, 2017, 10:33:40 pm »
To be fair the device I am currently using is 18F1320 (which I had lying around)...

Voltage on VDD with respect to VSS ... -0.3V to +5.5V
But that's the range of voltages the MCU is supposed to survive. There's no guarantee it'll work over that range. It's specified to work from 2V to 5.5V. This is because under abnormal conditions, e.g. voltage spikes on the power supply, the voltage may be outside the design range, which may cause it to fail meet its specifications, not destruction of the device.

There's an error in the data sheet for the 18F1320. The absolute maximum voltage range is always wider than the operating voltage range. For example if we look at a data sheet for the 18F1330 which is very similar to the 18F1320 and manufactured using the same process, the voltage range on VDD with respect to VSS is -0.3 to +7.5V. In fact the maximum ratings for temperature, currents, power dissipation and other voltages are exactly the same as the 18F1320, the only exception being the upper bound on VDD.

http://ww1.microchip.com/downloads/en/DeviceDoc/39758D.pdf

So what does this mean? Your MCU will be able to withstand 7.5V for a short period of time, even though its only designed to work up to 5.5V. It may not meet all its specifications when run above 5.5V and isn't good design practise to run it outside its specification but it won't blow up when connected to four fresh AAs via a diode.

Sorry for going off on a tangent. You're currently running it of 5V, which is well within the specification.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #34 on: May 22, 2017, 11:08:34 pm »
You could futz around...or even with a diode so IN can only pull the pin low
I was out tonight but a few minutes tinkering before bed.... I added a diode at RB1 and that solves the original problem, in fact functionally it actually seems to work now.
When I have time I will swap out the 4N25 for a 2N7000.  Power consumption when driving ON is currently up to 25mA (there are three LEDs, one on the button, one to indicate the door and one for luck I added earlier), using a FET will probably halve that and then I can lose the extra LED at some point.
I also need to reduce the duty flash cycle for forced up/down.
I will probably call that Mk 1 design and give it a test in situ and see if it actually works.
One issue I can foresee is power supply sag when the motor is lifting the door.
« Last Edit: May 22, 2017, 11:10:19 pm by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #35 on: May 22, 2017, 11:28:58 pm »
One issue I can foresee is power supply sag when the motor is lifting the door.
Yes, that might not be so good.   You could add 5.5V supercap after the diodes to keep Vdd up while the motor's running - just keep the LEDs off for long enough for full door movement so you only have to power the PIC through the brownout.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #36 on: May 23, 2017, 12:16:20 pm »
Just as well I added the diode... when in straighthrough mode the RB1 input gets connected to OUT.  OUT has unknown potential...
Might have to re-think this with much more isolation and perhaps a seperate supply for the gadget.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #37 on: May 23, 2017, 09:58:50 pm »
Back late... and out to the shed...

I measured the voltage across the battery terminals... 6.37V... when the door is lowering it drops to 6.28V and when raising it drops to 6.20V so the sag isn't too bad.

I measured across the timer outputs... it had 0.565V across it... didn't expect that.   Resistance measures 27kOhms in one direction, infinity in the other... I think that is telling me something..   Open Collector Output Transistor.

When the timer is across the door contacts it has a constant 0.012mA current flowing through it.

I think the Mk1 door opener should work... it might have to wait until the weekend to try it in anger.... I'm already considering Mk2... perhaps a 74HC4053 and a LDOed PIC.... any other suggestions or do you think Mk1 was really optimal  ;)
« Last Edit: May 29, 2017, 08:49:18 am by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #38 on: May 23, 2017, 10:52:05 pm »
That current and measured voltages would imply the door opener probably has a 470K pullup.     I think MkII can be simplified to one PIC that's in the loop all the time + a 2N7000 to interface to the door opener, with a 470K pullup on the PIC's input from the timer + any LEDs you want on separate pins.  You'll be hard-put to beat the two diodes to drop the voltage as it can be difficult to find LDO regulators that have less than 10uA quiescent current even when their input voltage isn't enough to maintain the output.   Its probably worth staying at a nominal 5V Vdd as going down to 3.3V would mean you'd need to replace the 2N7000 with a low Vgs threshold MOSFET.

A total quiescent current of under 20uA should be possible, which would have a negligible impact on AA battery life.
 
The following users thanked this post: NivagSwerdna

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #39 on: May 23, 2017, 11:02:23 pm »
...but the buttons could be on ordinary INT pins (RB0-3) as you only need to wake when they are pressed.
...
A total quiescent current of under 20uA should be possible, which would have a negligible impact on AA battery life.
The buttons would need pull-ups (or downs)... looking at the datasheet the power budget for PORTB pull-ups is somewhere between 50 to 400 uA.... which is >>20uA... are you proposing sampling rather than wake on interrupt?

 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #40 on: May 23, 2017, 11:17:30 pm »
No. because you cant control the internal pullups individually on this PIC, use external pullup resistors.  Try 470K with 1nF capacitance to Vss at each pin to make them less sensitive to noise.   The only pullup that will draw current continuously is the timer input one, when the timer is commanding door closed.  The button pullups wont draw current unless the button is pressed so they could be 100K with no issues.

Some comments on the power budget:
An Energiser E91 (AA) Alkaline cell has an approximate capacity of 2800mAH, and a shelf life of 7 years to 80% remaining capacity.   The self-discharge is therefore 80maH/year, which is equivalent to a 9uA drain.     An extra drain that left the batteries at 50% capacity after 7 years would have negligible impact on their life in any application so you've got about 14uA to play with, or far more if you replace them at least annually with freshly purchased ones.
« Last Edit: May 23, 2017, 11:30:04 pm by Ian.M »
 
The following users thanked this post: NivagSwerdna

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #41 on: May 24, 2017, 05:44:47 am »
Not withstanding others' valuable contributions, and for fear of flogging a dead horse ;-)

As I recommended above, LDO regulator MC78LC00 series. 1.1uA Iq, Vin up to 12V (note many low Iq regulators do not have a reasonably wide Vin).

Using an unregulated power supply, especially relatively high internal resistance dry batteries with intermittent inductive loads and high current draw, is almost certainly going to take your PIC outside of its operating envelope (4.5-5.5V).

Use the LF version and a 3.3V regulator such as the MC78LC33. This will give you sufficient headroom for voltage drop. No need for any super caps. Regulators aren't just there for voltage drop, they're there to remove excesive power input fluctuations.
« Last Edit: May 24, 2017, 05:55:56 am by Howardlong »
 
The following users thanked this post: NivagSwerdna

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #42 on: May 24, 2017, 07:25:31 am »
Not withstanding others' valuable contributions, and for fear of flogging a dead horse ;-)
Your horse is well alive, and your suggestions are well taken and much appreciated. 
I have a LM2936BM-3.3 sitting next to me, MC78LC00 looks interesting. (I also have some MCP1703A somewhere).
I don't have any PIC LF types knocking about.... Might try a PIC12LF1571 although the AT Tinys (for which I don't have an ICD) look pretty interesting for this application. I think my 2N7000 will operate at the lower voltage... I've got a few of those.



 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #43 on: May 24, 2017, 08:35:10 am »
You need to look at LDOs considering multiple facets, but in your application you are looking for:

o Low Iq (say <2uA) for prolonged battery life. LM2936 looks about 15uA :-(

o Low drop out voltage (say <200mV for your max PIC operating current)

o Reasonably high Vin max (say >7V) especially as ISTR you may have an inductive load on the unregulated side

o Sufficient current (>=50mA)

o Low enough output voltage to allow for operation with partially depleted batteries even when batteries under load.

o Output voltage within PIC spec

Note that some more modern PICs in the standard F versions operate from about 2.5V to 5V. The PIC18F1320 is quite old in this respect, only operating from a fairly narrow range of 4.2 to 5.5V.

The PIC12F1571 is 2.3 to 5.5V, while the PIC12LF1571 is 1.8 to 3.6V, both with a slightly higher Vmin of 2.5V for Fosc>16MHz.

I would still recommend a low Iq LDO even with the PIC's extended voltage range, to mitigate voltage transient effects on an unregulated rail. Such transient effects are often very difficult to track down, you might as well deal with them ahead of time.

There is a negative about using a lower PIC voltage such as 3.3V and that is that the Vgs to switch on the MOSFET might not be sufficient to fully switch on a 2N7000 depending on its load. At this point, it's time to choose an alternative MOSFET or use a bipolar transistor instead (Si bipolars switch on at ~0.7V, but check the DS for the collector/emitter leakage current when off!).

(Edit: just saw Ian.M already addressed the 2N7000 Vgs issue).
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #44 on: May 24, 2017, 08:37:58 am »
Don't forget back EMF diodes across your inductive loads (i.e., relay or solenoid coils).
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #45 on: May 24, 2017, 09:34:28 am »
At this point, it's time to choose an alternative MOSFET or use a bipolar transistor instead (Si bipolars switch on at ~0.7V, but check the DS for the collector/emitter leakage current when off!).
(Edit: just saw Ian.M already addressed the 2N7000 Vgs issue).
You're not going to like this... According to the datasheet I actually think the 2N7000 would continue to provide sufficient drive even at the lower voltage.
I'm open to suggestions and not fussy about through-hole versus SMD. 2N7002? BSS138?

Don't forget back EMF diodes across your inductive loads (i.e., relay or solenoid coils).
I'm rapidly running out of diodes.  ;)
« Last Edit: May 24, 2017, 10:10:41 am by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #46 on: May 24, 2017, 11:07:13 am »
You definitely need a PIC that can operate well below 4.5V.   However a trap for the unwary with older PICs that can run below 4.5V, as well as at 5V, is that many of them require >=4.5V for chip erase, so if you run them from a 3V battery or from a 3.3V regulator that cant tolerate its output being taken to 5V while programming (or with other non-5V tolerant devices on the same rail), then you can only program them in circuit *ONCE*.   That's OK for production, but not so much fun for development.   Younger players who aren't obsessive about reading the datasheet  often discover this the hard way with much wailing and gnashing of teeth when something expensive on their 3.3V rail lets the holy smoke out when they attempt a chip erase with the programmer supplying target power.

I would question the selection of PIC12 parts for a one-off project that isn't space or weight constrained.   Although its possible to use the ICSP pins for general I/O, doing so makes it impossible to debug in-circuit (if the PIC12 in question even has built-in debug support) without an expensive debug header, so if you need more than 3 I/O pins then there is a clear case for using a debug capable PIC16 with enough pins to avoid the need to use the ICSP pins in the application circuit.

@NivagSwerdna: What PICs do you actually have in stock (ignoring >28 pin ones)?  You may have one with a better operatig voltage range . . . .
« Last Edit: May 24, 2017, 11:13:47 am by Ian.M »
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #47 on: May 24, 2017, 11:43:18 am »
Younger players who aren't obsessive about reading the datasheet  often discover this the hard way with much wailing and gnashing of teeth

Agreed, I am not sure it's even possible to be over-obsessive about the DS parameters, and also add to that the errata: you should at least have scanned the errata to at least be aware of any gotchas that may affect your design at an early stage.

It's also not unusual to find yourself re-reading portions of the DS several times in an effort to try to make sense of things.

Ignore the DS & errata parameters at your peril, the devil is in the detail.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #48 on: May 24, 2017, 08:04:53 pm »
@NivagSwerdna: What PICs do you actually have in stock (ignoring >28 pin ones)?  You may have one with a better operatig voltage range . . . .
These are the LFs I have lying around...

PIC12LF1840-I/P

PIC16LF18313-I/P
PIC16LF1939-I/P
PIC16LF1824-I/P

The PIC16LF1824 looks quite fun.  Has some kind of SR Latch

And the F's

PIC10F322-I/P
PIC12F1572-I/P
PIC16F1509-I/P
PIC18F4450-I/P
PIC16F18323-I/P
PIC24F16KA101-I/P

PIC16F648A-I/P
PIC18F1320-I/P

That's all folks.  (The others have a lot more pins)

I also found a couple of MCP1703A-3302
« Last Edit: May 24, 2017, 10:05:14 pm by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #49 on: May 24, 2017, 08:57:47 pm »
Quite a lot of F parts work down to 3V.   e.g. PIC16F1824 has an operating range of 1.8V-5.5V.   So please don't limit your list of what's on hand to just the LF parts.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #50 on: May 24, 2017, 10:08:14 pm »
Quite a lot of F parts work down to 3V.   e.g. PIC16F1824 has an operating range of 1.8V-5.5V.   So please don't limit your list of what's on hand to just the LF parts.
Updated list. PIC16F648A now that brings back some memories.  :)  I probably would need to check the errata on that one!
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #51 on: May 24, 2017, 10:42:45 pm »
I wouldn't go and buy a PIC16F648A new for this as there are cheaper better choices, but its plenty good enough for the job. It will run down to 3V although it cant be erased reliably below 4.5V.  Its errata aren't objectionable.  The only major one is EEPROM write can result in incorrect instruction execution on pre rev A5 silicon - there is a workaround and AFAIK you don't need to use the EEPROM anyway.

However the PIC16F1509 is a better choice - its got an operating range of 2.3V to 5.5V, individually controllable pullups and IOC on ports A and B, and is debug capable.  Also its CLC (configurable logic cell) could be used to implement pass-through of the timer output to the door controller input while the PIC stays asleep.
« Last Edit: May 24, 2017, 11:01:59 pm by Ian.M »
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #52 on: May 24, 2017, 11:31:57 pm »
However the PIC16F1509 is a better choice - its got an operating range of 2.3V to 5.5V, individually controllable pullups and IOC on ports A and B, and is debug capable.  Also its CLC (configurable logic cell) could be used to implement pass-through of the timer output to the door controller input while the PIC stays asleep.
I feel a bit guilty putting such a capable device to such a purpose.  It seems to be £1.31 so is an expensive solution if cost were important, which it isn't.  I haven't used CLC before... that might be a lot of fun.... now to see if I can actually find the thing!
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: 4 AA cells direct to PIC?
« Reply #53 on: May 25, 2017, 11:42:19 am »
I haven't used CLC before but this seems pretty straightforward....

DEMAND = What the user wants
DRIVEN = Whether driven by user or straight through
IN = from timer
OUT = out to motor

DEMAND_MET = interrupt to wake PIC to tidy up after timer has caught up with demand.

Logic attached
« Last Edit: May 25, 2017, 11:48:43 am by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: 4 AA cells direct to PIC?
« Reply #54 on: May 25, 2017, 12:12:52 pm »
Yes, with four cascadeable CLCs, you could probably implement most of the algorithm as logic,
e.g. button inputs as Set and Reset to a clocked D type latch fed by the IN signal and generating the (inverted) OUT gate drive signal, with its clock derived from edge detecting the IN signal

However it will be a LOT simpler to only configure the CLC for the inverting passthrough to the gate drive so you can effectively shutdown the PIC when the timer is in control.  When your program needs to override the timer it can disable the CLC output (leaving it set up) using the CLxCON.LCxOE bit so it can set the desired pin state, then reenable it later when the current and timer commanded states are back in sync.

Either way some exoerimental breadboarding is advisable . . . .  :popcorn:
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #55 on: May 27, 2017, 09:54:24 am »
Well this is a bit sad, and definitely a beginners question...

I decided to put Mk 1 circuit in the shed as it is basically complete... (I will do Mk 2 in due course, promise!) it works fine (although out of spec at 6.5V) except.. the timer interface does not work at all... it senses that the timer is always open circuit indicating that the door should be open... this is a problem!

When prototyping I had assumed the timer was a voltage free contact and this worked well on the bench but in the shed with the real timer I get no joy. 

I do know that when the timer wants the door open, it is open circuit, and when it wants the door closed it conducts (measurements given earlier)

I don't really know the standard approach for interfacing with this timer but my assumption is that the internal pull-up isn't strong enough however due to the convoluted design that is Mk1 I also have a diode to contend with.

I'm planning to try putting a 10k pull-up to (switched VCC) on the RB1 side of the diode but I would be interested to know why it doesn't work in this form.

Also... on reflection I don't like this interface at all, it looks inefficient... is there a better way to interface that would take less current when in steady state?  e.g. charging a capacitor and then sensing voltage rather than current?

You can tell I do mostly software nowadays  :)
« Last Edit: May 27, 2017, 09:56:59 am by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #56 on: May 27, 2017, 10:56:37 am »
Until you can identify what the timer output characteristics actually are, this whole project is dead in the water, unless you want to add a 32.768 KHz crystal and make the PIC totally replace the timer.   

Is the timer identifiable so maybe we can find a datasheet for it?  Or is a non-destructive teardown possible?
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #57 on: May 27, 2017, 03:28:36 pm »
add a 32.768 KHz crystal and make the PIC totally replace the timer.
It's a really sweet looking timer but that point is not lost on me.  The project makes sense much more as a timer replacement but... keeping going for now.

I removed the timer and took a few photos.  The back even says Open Collector so that fits with observations.  It also says 2mA... not sure of the significance of that.  The timer has five pins but only pin 3 and 4 are connected; it is powerd by 2xAA that live behind the flap.

I'm guessing that my issue is the pull-ups inside the PIC will not drive the timer circuit hard enough.  I need to pull it up harder to +ve?

Inside the timer is potted.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #58 on: May 27, 2017, 05:49:44 pm »
OK... so I put a 600k pull-up on the RB1 side just in case... and did some measuring...

When the timer contacts are 'open' RB1 floats high so is logic 1... when the timer contacts are 'closed' the value drops to around 1.3V.  1.3V is not considered logic LO so I get the wrong result, the PIC thinks the timer is still 'open'.  Decreasing the pull-up makes the problem worse, but surprisingly making the value much bigger doesn't seem to help much.

It seems that the timer is still pretty high resistance even when in its closed state.


« Last Edit: May 29, 2017, 08:54:52 am by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #59 on: May 27, 2017, 06:06:56 pm »
Well that was difficult to find: https://gb.axt-electronic.org/uk_shop/shop/vsb/283/bs-d-digitale-batterie-zeitschaltuhr-quasianalog-zubehoer-vsbb?c=51
Manual: https://gb.axt-electronic.org/media/pdf/GB-2T.pdf
and about as clear as mud!

Its obviously got some sort of transistor output and I'd treat that 2mA as an abs max current rating.   
The question is:  *WHY* is the emitter brought out separately?
I would expect a normal OC timer to have three connections - power, ground and OC output.

Is there any voltage on the transistor E or C pins with nothing else connected to them? Test both timer output states.
 
Try connecting a 4K7 resistor between the emitter and ground and another the same between the collector and +6V and check voltages as above.   (4.7K because no matter what its under the 2mA max current).

I *suspect* it wasn't pulling low enough for your PIC to detect as logic '0'
Edit: confirmed.

I'd still like the above measurements so we know what we are up against.
« Last Edit: May 28, 2017, 07:13:22 am by Ian.M »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #60 on: May 27, 2017, 06:36:24 pm »
Decreasing the pull-up makes the problem worse, but surprisingly making the value much bigger doesn't seem to help much.
This is curious. What kind of diode are you using? If you must have a rectifier, here, perhaps the FVD is your limiting factor. Have you tried a shottky with max current rating circa 300mA or less? 

You didn't draw the power rails in the schematic. Longshot, but if you have them running off different power source, you didn't forget to connect the ground rails, by chance?
« Last Edit: May 27, 2017, 06:41:20 pm by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #61 on: May 27, 2017, 06:41:29 pm »
I suspect the timer has something like a Darlington + series reverse polarity protection diode, with the base driven via a resistor from a rail-to-rail low power CMOS output.  That could be wired as either a high side or low side load switch and would account for the high voltage drop (0.65V Vbe + Vce_sat of the driver + a possibly Schottky diode Vf drop)
« Last Edit: May 27, 2017, 07:09:45 pm by Ian.M »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #62 on: May 27, 2017, 07:00:34 pm »
^That sounds likely. Regardless of the exact innards, a couple of transistors later and you should be back in business, no? 
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #63 on: May 27, 2017, 07:09:00 pm »
^That sounds likely. Regardless of the exact innards, a couple of transistors later and you should be back in business, no? 
Yes but keeping the extra current down low enough not to significantly impact battery life without making it excessively sensitive to RFI may be difficult.

@NivagSwerdna: How often do you have to change the door opener batteries?


To interface it to a TTL compatible logic input without incurring extra battery drain :-/O is challenging.  I'd try using a Schottky diode AND moving it to RA4/T0CKI as that pin has a Schmitt trigger input with a trip point typically near 1/2 Vdd (though all the datasheet guarantees is that its between 0.2 and 0.8 of Vdd).   The pin can be used to generate an interrupt on either edge - set up Timer 0 in 8 bit mode, external clock, no prescaler, preload it with 0xFF then set T0CON.T0SE for the edge you want, clear the interrupt flag INTCON.TMR0IF and finally enable the timer.  However as its synced to the core clock, it wont work to wake from SLEEP mode - you'll have to settle for the lowest current (31Khz) RC_IDLE mode.
« Last Edit: May 27, 2017, 07:10:39 pm by Ian.M »
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #64 on: May 27, 2017, 08:22:34 pm »
I have taken some measurements... first with a DMM first one way and then the other polarity with no other circuit attached.

Then I attached to a 6V source and had two resistors as suggested... I had 38.2k to hand but I hope that is OK. (Oops I misread 4.7k as 47k so thought 38k was close... sorry, please let me know if I need to do this again)

When Open there is no noticeable current... so no current... no voltage across the resistors.  At 6V the voltages go... 0, 2.58, 3.42, 6.0, I also tried this at 5V and got 0, 2.12, 2.89, 5.0.

I have absolutely no idea how to interpret those numbers!  Thanks
« Last Edit: May 27, 2017, 08:32:01 pm by NivagSwerdna »
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #65 on: May 27, 2017, 08:27:42 pm »
@NivagSwerdna: How often do you have to change the door opener batteries?
The timer has 2xAA... I'm not sure I have ever changed them.... i.e. they could be 5 years old, the Door opener has a separate 4xAA battery pack, I have changed those once every 2 years, but I think they were not flat at that time.  The door is a sliding bit of Aluminium (not sure of mass) and moves about 40cm up and 40cm down each day.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #66 on: May 27, 2017, 08:38:55 pm »
You didn't draw the power rails in the schematic.
The power sources are isolated in the sense that one has a 2xAA battery compartment and the other has a 4xAA one.  There is no obvious common ground connection in the original set up, just two wires (pin 3 and 4 here) go between the units.
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #67 on: May 27, 2017, 08:42:19 pm »
To interface it to a TTL compatible logic input without incurring extra battery drain :-/O is challenging.  I'd try using a Schottky diode AND moving it to RA4/T0CKI as that pin has a Schmitt trigger input with a trip point typically near 1/2 Vdd (though all the datasheet guarantees is that its between 0.2 and 0.8 of Vdd).   The pin can be used to generate an interrupt on either edge - set up Timer 0 in 8 bit mode, external clock, no prescaler, preload it with 0xFF then set T0CON.T0SE for the edge you want, clear the interrupt flag INTCON.TMR0IF and finally enable the timer.  However as its synced to the core clock, it wont work to wake from SLEEP mode - you'll have to settle for the lowest current (31Khz) RC_IDLE mode.
I'll dig out a Schottky tomorrow... but I'm thinking about just bodging this... when in driven mode I could just use RB1 as AN5 and point this at the ADC.  Then when the value is <50% consider it a low.  I need not convert very often... perhaps once every 10 seconds... and this would only be active during the override period.. the latching relay then saves the day for normal operation.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #68 on: May 27, 2017, 09:03:06 pm »
I'd interpret them as verifying the timer output stage is a Darlington, probably without a reverse polarity protection diode, driven by a weak MOS rail-to-rail output as described.   Checking with lower value resistors would probably not tell us much.  One test that would be helpful would be to try a single 100K resistor between +6V and the collector and check voltages with the emitter open circuit and the timer on.  Repeat with a single resistor from emitter to ground.  That should pick up if there is actually a DC base drive to the output Darlington or if its actually isolated  e,g. photo-darlington, or maybe something exotic like an AC coupled charge pump feeding the base.

For the final design, this means the PIC input should probably be fed from the timer emitter, with a pull-down, for better compatibility with the TTL input thresholds.

For now, yes bodge it - do an ADC conversion whenever a button is pressed or at periodic intervals while in override mode.  You can use the watchdog timer for wakeup from SLEEP to save power - set its period to the desired LED flash rate, do a conversion and any other housekeeping tasks, delay for the desired flash duration and go back to sleep till the next flash.  However it may be good enough to just amble along at just under 0.008 MIPS in 31.5KHz  INTRC_RUN mode.
 
« Last Edit: May 27, 2017, 09:12:40 pm by Ian.M »
 
The following users thanked this post: NivagSwerdna

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #69 on: May 28, 2017, 05:49:40 am »
I forgot what PIC you're using. The advantage of the comparator (if present) vs ADC is that the comparator can trigger an ISR/wake. I'm not sure the power comsumption difference without looking deeper, though.

(I still don't understand why not just drive signal PFET with a 3k ohm gate resistor to signal NFET to micro input pin with internal pullup. The frequency is super low, right? Once or twice a day? And switching-speed/signal-latency isn't a factor, is it? And bodging that up is a lot faster to me than writing ADC code. But I admit I haven't looked over all the schemmies.)


« Last Edit: May 28, 2017, 06:18:57 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #70 on: May 28, 2017, 06:08:21 am »
I believe N.S. is currently using a PIC18F1320, so no comparator.  It does have low voltage detect with an external input capability other than Vdd, but the reference threshold for that is 1.2V and its interrupt is falling edge only so its no help.

If he sticks to the current plan MK2 will be a PIC16F1509 part with CLC and comparators, however if possible it will be desirable to avoid using the comparator for the timer interface due to the increased quiescent current from having that module and its reference active.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #71 on: May 28, 2017, 06:24:50 am »
^Ahh, yeah.. I thought of that while you were posting. If this is just once or twice a day, comparator watching all day is a waste... :) But ADC can't wake PIC.

For minimum consumption, you could sleep the PIC and wake it up with the watchdog timer, every twice a second,* take and ADC reading, and go back to sleep.

*plus or minus, depending on what kind of latency is acceptable.

But I still don't see how this would necessarily beat 2 FETs and wake on IOC.

And compared to the drain of the motor and relays, isn't all of this academic? I'm assuming this is why 4xAA cells are used... or is there a third power supply for this stuff?
« Last Edit: May 28, 2017, 06:33:59 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #72 on: May 28, 2017, 06:39:35 am »
That depends on the PIC's power source.  Currently it draws from the 6V door motor battery pack.  However it it can be miniaturised enough to fit in the spare space in the timer enclosure, putting all the controls in one place, it would make more sense to draw from the timer battery, and as that's changed far less often, getting the quiescent drain down to the same sort of level as the self-discharge will be fairly important.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #73 on: May 28, 2017, 07:05:42 am »
Ok, but if you use two FET (or BJT PNP, since you're gonna run off 3V and have -1.6 gate/base drive) and IOC... and if frequency is once or twice a day... and if you go crazy and once woke you turn off the pullup and only intermittently turn it back on to check until signal is gone.... isn't current drain going to be nearly nothing?
« Last Edit: May 28, 2017, 07:17:02 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #74 on: May 28, 2017, 07:25:28 am »
N.S. said the timer uses 2x AA and they've (probably) lasted 5 years.   That means the timer's draw must be less than 55uA.   It would be a PITA to have to change the timer batteries more frequently than annually so there is an upper limit of about 220uA average current to play with.  If two year battery life is a requirement, the power budget is only 80uA.  As it will be in timer pass-through mode most of the time, the timer interface and PIC quiescent current are likely to be the two main contributors to the quiescent current.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #75 on: May 28, 2017, 07:33:34 am »
Quote
As it will be in timer pass-through mode most of the time
And if this is the case... instead of doing ADC readings throughout all this time, which each draw a little current, you could have PIC sleeping the entire time on lowest clock setting. Waiting for IOC.

The 2 trannies will have zero quiescent current until the open collector output is switched on. And only need very little draw while the signal is active. Just a trickle of the base of the small signal PNP. And a trickle thru the pulldown for the small signal NFET. And essentially nothing thru the drain of the NFET, if you turn off the pullup after wake. And still, this is simpler on the code end.  :-//

You could even put the emitter of the signal PNP to an output pin on the PIC, and turn the entire thing off after wake. :)
« Last Edit: May 28, 2017, 07:43:15 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #76 on: May 28, 2017, 07:56:44 am »
The timer doesn't provide separate open and close pulses. instead its output is on ALL the time the door is to be closed for.  The ON time of the timer is therefore a significant contribution to the average quiescent current  Assuming its being used with a light sensor on the main unit so is only on from 4AM to 9AM to keep the chickens in in the morning till everyone's up and about, averaged over 24H, that's still 21% of its on-state current.

That's why I suggested testing if its possible to drive the PIC input off the timer emitter - the levels should be compatible on a TTL digital input pin, and the pull-down resistor can be large enough that the quiescent current is lower than running the watchdog to poll the pin.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #77 on: May 28, 2017, 08:02:47 am »
Quote
21% of its on-state current.
K, I didn't think of it like that. I was thinking it was on only when the door was opening/closing, or whatnot. I see where you are coming from on that end, and I agree with the reasoning.  :-//

« Last Edit: May 28, 2017, 08:15:31 am by KL27x »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #78 on: May 28, 2017, 08:14:12 am »
Its worse if N.S. isn't using the photosensor.  Average hours of darkness over the year will be 12, and you'll want to extend that in the morning a bit so it could be as much as 60% of the on-state current.

The idea was to make the PIC CLC handle the pass-through.  The PIC stays asleep and you avoid the cost and complexity of the latching relay and its drivers. That means you dont have much power budget for the interface between the timer and the PIC.
« Last Edit: May 28, 2017, 08:17:19 am by Ian.M »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4102
  • Country: us
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #79 on: May 28, 2017, 08:30:04 am »
Hmm, that CLC sounds too cool. I have to get my hands on these newer PIC. Yeah, sorry I just edited last post. I see where you are already 2 steps ahead of the whole relay idea. But yeah, as usual, I end up learning something in the end. :)
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #80 on: May 28, 2017, 08:50:53 am »
Yes, its fairly cool - each can do a lot of four input logic functions, including several typoes of flipflop, with invert/non invert options for all signals.  However now Microchip have Atmel's programmable logic designs, if we are lucky we may yet see an enhanced midrange core paired with a GAL equivalent RAM based logic fabric
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #81 on: May 28, 2017, 05:49:49 pm »
So... swapped the diode for another one I had lying around (not sure if it was shottky)... no significant change....

... anyway... changed the software to use AN5 and ADC... it does a conversion and then has 1.5s of conversion quiet time during which no conversions are done and then converts again.  Conversions only occur when in active mode.  The 1.5s polling interval is not an issue.

I've also changed the LED flashing as per suggestions.

Works nicely.



That was meant to be an afternoon project... it's taken me weeks!  Thanks for your help.  I will add Mk2 to the projects list... really looking forward to try the CLC approach.

(For the record.... the PIC is definitely out of spec here... the diode drop doesn't get you down to 5.5V so therefore a regulator should really be used, this could be added to this design to give Mk 1.5.  Ultimately the LDO and CLC design makes much more sense as the latching relay and ancillary components add significant cost/complexity. Finally in retrospect the actual functional requirement seems a bit off... it would make much more sense to just buy/build a new timer with the override functionality, the LCD glass and UI on the existing timer is really nice though, direct LCD drive is something PICs do well)
« Last Edit: May 29, 2017, 09:15:13 am by NivagSwerdna »
 

Offline NivagSwerdnaTopic starter

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: Chicken Door Opener / 4 AA cells direct to PIC?
« Reply #82 on: May 28, 2017, 06:18:15 pm »
Its worse if N.S. isn't using the photosensor.  Average hours of darkness over the year will be 12, and you'll want to extend that in the morning a bit so it could be as much as 60% of the on-state current.
I don't use a photo-sensor.  Although the principal is roughly day light hours in practice you want it a bit after dawn and then around dusk.  During spring you want to delay opening to avoid foxes that are up and about a bit latter than dawn during cub season.
« Last Edit: May 29, 2017, 10:43:24 pm by NivagSwerdna »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf