Author Topic: ATTiny With Variable Time Delay & Relay Control  (Read 4400 times)

0 Members and 1 Guest are viewing this topic.

Offline cs2000Topic starter

  • Contributor
  • Posts: 13
  • Country: gb
ATTiny With Variable Time Delay & Relay Control
« on: February 27, 2018, 07:54:33 pm »
Hi all,

Hoping I could get a little assistance. I'm trying to design what I’d expect to be a pretty simple circuit, but as this is my first one ive tried to custom design I'm struggling a little. I know the basics of electronics, but the last time I used a 555 timer was in high school!

What I'm trying to do, is design a circuit which can handle 12-14v (for use in a car), can take a specific input signal (like seeing 12v on a particular pin) and then latch a relay. The relay latch time needs be variable and set by a potentiometer, time range between 0.5 and like....3-4 seconds would be fine.

The circuit should only perform this action once each time it sees the 12v input signal.

My initial thought was a 555 timer, for which I've built the following (probably horrifically wrong) circuit using various examples of tutorials ive found.



My issue is (aside from the fact this likely is wrong) is that I need it to latch the relay once, then ignore the command until the 12v signal goes away again, wait for say 5 seconds, and then be ready to listen and perform the action again, I don’t think a 555 timer can do this (just run the instruction set once basically).

I'm aware such a thing is possible to do with an Arduino and a relay PCB, but this isn't desirable as I want a low cost of parts (I don't see the point running a microcontroller like an arduino, when I need fairly simple actions) and also because I want to design a PCB for it all, not have various modules dotted around linked together with jumper wires.

TO make it simpler, what im actually trying to do, is detect when my car is put into reverse, then dip the electronic side mirror for X amount od seconds to aid in paralel parking.

The module needs to ignore the second “Dip” command as theoretically if you kept putting the car in reverse quickly, you could run out of travel on the motor.

Also, as the mirrors are electronically controlled, it would need a way for me to splice in thje existing mirror wiring to allow the OEM controls to still work. There are modules that do this (and are wired up like the below), but the asking price is too hign for something so simple, and it would be fun to build my own!



Any help is appreciated  :)

« Last Edit: March 03, 2018, 12:39:29 pm by cs2000 »
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #1 on: February 27, 2018, 08:30:35 pm »
Is this at all helpful?





As far as "doing this with Arduino" is concerned... you don't need the whole Arduino, just a single ATTiny (same size and pin count as 555) would do the trick nicely, with a few other components for protection from the noisy automotive "12v" supply.
« Last Edit: February 27, 2018, 08:39:16 pm by alsetalokin4017 »
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #2 on: February 27, 2018, 08:31:18 pm »
Another way to illustrate what you require would be a waveform - albeit a very simple on/off high/low one.  You could knock that up in paint.net or anything you like as its just straight lines, with time on the X axis and "signals" on the Y.  In my experience the hardest part of this sort of thing is actually converting the behavior you want into words/diagrams that can help in designing a circuit.

Just to try and repeat what you're after:  a circuit that will turn a relay on for a variable time (0.5 - 4 seconds) when its input is a rising edge (low to high).  If the input drops low for less than 5 seconds, you want the circuit to ignore this (not turn the relay on).  The fact it only response to a rising edge means it will ignore a falling edge (high - low transition).  Is this correct?

A 555 run as a monostable timer is generally triggered by a "low" on its trigger pin.  You can invert this (so its triggered on a high) with a simple transistor.

Check out this page: https://m8051.blogspot.co.uk/2013/02/retriggerable-555-timing-circuit.html

The diagram/waveform there shows the difference between a standard monostable (ignores subsequent triggers while the output is "on) and the re-triggerable (repeated triggers extend the on time - I suspect this isn't what you want).

When talking about putting in some control in parallel with the OEM controls, this may not be as simple as wiring it in.  This depends on whether you are connecting directly to the motor, or if the motor is run off the canbus (likely) in which case it gets much harder.  As that diagram you provided seems to have a separate "up" and "down" wiring, to me that seems like its just signals providing on/off rather than canbus (which would just be two high low signal wires).



 

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #3 on: February 27, 2018, 10:33:38 pm »
In you schematic you do not show a clamp diode on the relay, that
can cause failure of the timer, or other logic.




Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #4 on: February 27, 2018, 11:22:05 pm »
Consider a PSOC 4 solution, see attached IDE screen shot.

1) Debounce of switched inputs for software testing
2) Onchip A/D and reference to measure battery V, same for onboard clock generation
3) Diodes, Rs, Relay external, rest onboard
4) Lots of resources left for other stuff
5) Additional inputs not a problem, I just showed one with input protection as example
5) Relay can be driven off main batt or supply to PSOC
6 You should have a simple 3 terminal reg, or zener and R, to power PSOC
7) In resources used ignore high SRAM usage. PSOC defaults to a large value for mempool,
users regularly reduce that significantly. This is onchip SRAM
8) I forgot you want adjustable delay, thats easy, add a pot and another input to SAR or
use an encoder.
9) Switch inputs can be CapSense if you want

Dev board ($4) -




http://www.cypress.com/documentation/development-kitsboards/psoc-4-cy8ckit-049-4xxx-prototyping-kits


Regards, Dana.
« Last Edit: February 27, 2018, 11:29:25 pm by danadak »
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 

Offline Wimberleytech

  • Super Contributor
  • ***
  • Posts: 1133
  • Country: us
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #5 on: February 28, 2018, 12:11:26 am »
This looked like and interesting problem, so I found the manual for the device in the original post and figured out that this is how the mirror is wired using the Auto Tilt Mirror thingy.

I dont think a 555 is the right solution.  This needs to have pretty accurate timing because the time used to tilt the mirror down needs to be the same for tilting back up after leaving reverse.  Otherwise, your mirror would slowly drift off after multiple reverse-forward operations.

 

Offline Wimberleytech

  • Super Contributor
  • ***
  • Posts: 1133
  • Country: us
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #6 on: February 28, 2018, 01:08:17 am »
Here is an update with a timing diagram that might work.  The switches are DPDT relays.

Simple to make with an Arduino.
 

Offline cs2000Topic starter

  • Contributor
  • Posts: 13
  • Country: gb
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #7 on: February 28, 2018, 11:30:10 am »
Wow really appreciate the replies guys, thankyou. I had started looking down the PIC12F route for chips as i also came to the conclusion that perhaps a 555 wouldnt be right in the end, but i think an ATTiny would be a better fit considering its programable through Arduino IDE.

@Buriedcode - I think, from the way they work (you slide a switch to select the left or right mirror, then use 4 buttons to move them) that its purely connecting a voltage to the mirror motor(s), no CANBUS communication involved as far as i can tell.

Your understanding of what im trying to do is almost correct, ive re-worded it below.

- A circuit that will turn a relay on for a variable time (0.5 - 4 seconds, selectable with a POT) when its input is a rising edge (low to high). 
- Once the input has gone high, the relay should be latched for the time desired.
- Once the input goes low again, the motor needs to reverse for the same timeframe (so perhaps need a second relay here wired into the "up" side of the OEM switch)
- The system then needs a cooldown timer so you cant keep shifting in reverse and make the mirrors keep going down (to ensure you dont exceed their travel) but this is in code and not PCB design id imagine

Would some kind of block diagram/flowchart help or is that clear now?

@Wimberleytech - thanks for that, kinda proves in my head that what im thinking isnt impossible!
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #8 on: February 28, 2018, 02:38:06 pm »
As others have stated, it sounds like this is beyond what a 555 is capable of.  Well, a couple of 555's might do it but also as stated (not taking credit for it) the reverse time must be exactly the same as the first one, so the mirror goes back into place (assuming there's nothing funky going on making the speed of the mirror asymmetrical).

The 555 is a very simple analogue device that isn't very precise but does its job well.  Even with precision resistors and caps its timing will never be that accurate due to tolerances in the parts voltage threshold levels (its internal resistors).  This means the two times will most likely never be equal - making your mirror change position each time.  So Whilst it adds another level of complexity - and would most likely require a decent voltage regulator to deal with being powered by the cars battery power (the power supply from hell) a microcontroller would be best here.  You can control each output very accurately - to within one clock cycle, which can be 50ns - read inputs in multiple ways, like a pot for setting time, or up/down buttons, and the fact its programmable means you can upgrade/modify it whenever you wish.

You're new problem description, long with Wimmberleytech's relay schematic makes a great starting point.

As for which micro, if you are unfamiliar with microcontrollers, then the "best" option will be the easiest - Arduino most likely.  Doesn't have to be the Attiny, a standard UNO (atmega328) will do as well.  At least for prototyping.  As I mentioned, its regulator isn't that great, and the 12V line in cars can spike to 70V+ and is very noisy.  This can kill linear regulators, and the noise can bleed through and reset micro's - causing all sorts of headaches.  Not trying to put you off, just that its something to think about once you have a system that is functional.

As for diagrams, perhaps a timing diagram (again like the one Wimberleytech provided) showing input, its output, and perhaps another line for "cooldown timer" that shows when it should ignore inputs.  Such diagrams help a great deal with writing software because it shows what should happen in a linear/sequential fashion which is often how software on micro's is writing (interrupts can occur at any time, but keep things simple first).
 

Offline cs2000Topic starter

  • Contributor
  • Posts: 13
  • Country: gb
Re: 555 Timer With Variable Time Delay & Relay Control
« Reply #9 on: March 03, 2018, 12:38:59 pm »
Thanks for the comment, have had a busy few days so haven't had much time to work on this, plus as I said its not something I have too much knowledge in, but here is a schematic I THINK would work.

I have chosen an ATTiny85 as they're readily available and cheap.

I'm choosing to go with 2 relays, one for Up movement and one for Down, I'm aware that I could probably do it for one, but this is just how I envisaged it. As for the two relays, ignore the specifics of what they are, just treat then as a bog standard relay that can be activated by 5v but switches 12v, SPDT

The potentiometer is connected to Pin1 of the ATTiny which I think is where the ADC lives so I'm able to translate the resistance/voltage received into some kind of time for the mirrors to move.

The regulator shown may be wrong for my application based on Buriedcode's comments, but ive selected a STMicro L7805ACV, it can take 35v input (so this could also go into trucks with their 24v batteries) and outputs 5v, I'm aware id likely need a heatsink on this too. If this is the wrong part, what would be a better fit here? build a Buck regulator circuit?

In terms of circuit design, does this look sensible, I know the layout is likely down right awful as its the first time ive ever tried to use Eagle/any PCB or layout software!

 

Offline max_torque

  • Super Contributor
  • ***
  • Posts: 1280
  • Country: gb
    • bitdynamics
Re: ATTiny With Variable Time Delay & Relay Control
« Reply #10 on: March 03, 2018, 04:40:02 pm »
If you are "open loop" tilting the mirror, forget it!  After a few times, the mirror will not return to where it was originally set, and that will be 100x more annoying than not having it tilt when you select reverse!

Consider the environmental variances your car operates under, and how you would detect that the mirror was tilted all the way down?

ie, mirror is lets say, set at 50%, to get to "down" it need to, at 25 degC, run the motor for 3 sec to tilt all the way down.

The you set the mirror to say 45%, now that 3sec down tilt time is too long, the mirror hits the bottom stop, (for 5%) and when it tilts back up, it's now at 55% not 45%!

Add in changes in temp, battery voltage, variances in mirror drive friction and about a million other parameters and it just isn't' going to work, sorry........
 

Offline cs2000Topic starter

  • Contributor
  • Posts: 13
  • Country: gb
Re: ATTiny With Variable Time Delay & Relay Control
« Reply #11 on: March 04, 2018, 12:38:44 pm »
Hi there, yes I was planning on using an open loop. The part about "how you would detect that the mirror was tilted all the way down?" I can answer, That's what the potentiometer is for.

In the code, this would be ran through the ADC and converted to a time. Obviously the user would set the time on the pot that gives them the required dipping angle they want, along with making sure the mirror doesn't run out of travel.

I do appreciate what you're saying, but there are products like this already on the market, just well above the value I consider sensible and they work in this same way. Your comments regarding temp, battery voltage, variances in mirror drive friction are all valid, but its not like youre in reverse for 15 mins at a time, I hardly think the time between me selecting reverse and when I come out of it will have caused the motors/gears to heat up at any of the other parameters to change considerable if at all.

Its something I really want to try, I can build a breadboard example I can test fir to my own vehicle, I'm just not accustomed to PCB design, that's the assistance I'm after, lets assume it will work for the sake of this discussion :)
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: ATTiny With Variable Time Delay & Relay Control
« Reply #12 on: March 04, 2018, 02:52:52 pm »
Well before making a PCB you could buy an Arduino UNO clone, a relay board, and some wiring slicing stuff - and just cut the wires to the mirror motor, hook it up to the Arduino and have it run each way for exactly the same time.  After 20 runs you'll notice any drift.  The splicing stuff is to repair your cut wires. 

This way you can do the test in under an hour, so you won't be without your car until then, and it costs £10. Granted getting to the wiring in cars is generally a hassle, but the test itself is relatively simple and would at least give some indication of feasibility.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf