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

0 Members and 1 Guest are viewing this topic.

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: 12855
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: 12855
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: 12855
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: 12855
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: 4099
  • 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: 12855
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: 4099
  • 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: 12855
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: 12855
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: 4099
  • 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: 12855
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: 4099
  • 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: 12855
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: 4099
  • 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: 12855
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf