Adjustable Looped Timer

Discussion in 'Embedded Systems and Microcontrollers' started by rohitdantkale, Apr 2, 2014.

  1. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Hi Guys,
    I'm very new to electronics, I need to create a looped timer where we can set 6 or 8 or 12 or 24 hrs setting of countdown
    which will run in loop. It should turn on a DC motor at each countdown for the set seconds (should have a option to set duration
    in seconds for the motor to run at each countdown end)
    I have attached a flowchart and a required control system of it.
    Can you please help me in making this, what components I need and where to start from.
    Thanks in advance for the same. :)
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    You have a low number of inputs (I could see using just 7) and a perhaps just single output.

    The code requirements so simple they should fit into the smallest of micros, and I'm including those with just 128 memory locations (I think they come that small... though you may need to do it in assembly to make it fit).

    So go out and get just about any processor you want to start using.

    Since you're just starting out I would recommend a small development system. I use Microchip devices, their entry level system is around 60 bucks. TI has one much cheaper, hopefully someone will post that link.

    And welcome to the forums!
     
  3. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Thanks for your kind reply ErnieM,
    I think there are two inputs, one is about the countdown hours and other about the runtime seconds control. Am I right :-|

    As I told I'm very new to this, can you please give me a breakdown like from where to start and what all components I need to buy to build this.
    And what are the steps of assembly and programming the microcontroller.
    Can I do this on a bread board.

    Once again thank you very much :)
     
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Although it is what Ernie and myself consider a very "simple" project, you may find this to be quite a challenge if you have never worked with microcontrollers before. You will have to learn how to program them, how to connect all the parts, how to debug it when it doesn't work the first 20 times, etc.

    Have you considered just buying a programmable timer from ebay?
     
  5. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Yes RB, I'm planning to buy programmable timer, but dont know what are the options available and which one to pick.
    I know programming but not about microcontrollers, and yes I need to learn how to connect and debug it.
    Is there any alternative option to do a single option of either 6, 8, 12, or 24 hrs rotary switch and then a simple on off switch to activate it?
     
  6. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    No RB, I'm not planning to buy the ready timer switches from market, I got your question now :p
    I want to build my own circuit and learn all this stuff.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Nope ;-)

    The "Try Click" is one button using 1 input.
    The "Set Seconds" needs at least 2 inputs to capture the data in 3 "states."
    The "Loop Hours" is easily done with each hour setting being another input for 4 more inputs. (Why 4 and not 5? You don't need a separate input for "Off." Off is when all 4 inputs are low.

    Plus something for an output.

    Ummm... I can help later on, off to work in a few.

    I don't recommend using assembly when you can download a C compiler for free. While I have done assembler I have not done any in a year or three, so I'll let assembly questions to those working currently with it.

    Seems the development board/programmer I would recommend has moved. I'll find it again and post the new link. What is good is you don't have to buy a thing to try it, the software is free to download and has a simulator so you can test drive sample programs. It has a set of downloadable lesson plans that will teach you how to read buttons and turn things on (just what you need!)


    Yes, it actually should work out well. I've seem many do such. (Personally I use wire and solder but I tend to keep my boards.)
     
    rohitdantkale likes this.
  8. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Welcome to AAC.

    I'll throw in my two cents as another option to consider.

    We (or at least I) need a little more information on how you want this to work.

    You've said you want to set the motor run time for each countdown. Does this mean you want the motor to run for a specific and different time for each countdown (hour setting)?

    Example 1:

    For 6 hour countdown, run motor for 12 seconds
    For 8 hour countdown, run motor for 3 seconds
    Etc.

    Do you want to manually change the motor run time each time, say with a potentiometer? This means the motor run time will be controlled almost directly with the potentiometer, regardless of the countdown. So if the potentiometer is in the lowest position, the motor will run for 2 seconds regardless of the countdown selected.

    Alternately, you could add another button to "program" the motor run time for each countdown. So in "program" mode, you select the countdown value, then "test" the motor run time you want by turning the pot and running it. Once the motor is running for the desired time, you save that run time to memory for that specific countdown, then repeat for each countdown value. By saving this in memory, you don't need to worry about changing the potentiometer to a new position everytime you change the countdown value. This also allows you to change the motor run time for each countdown on the fly.

    If you don't need to change the motor run time for a given countdown, then you can simply put that in the main program and forgo the potentiometer altogether. This means once you've got the motor run time for a specific countdown set, you'll never need to change it.

    If you want to go crazy, you can add two thumbwheel BCD switches to set the motor run time exactly - assuming you'll only ever need whole seconds and not fractions of a second. This would allow you to quickly "see" the run time being set or programmed. This would require more I/O's on the microcontroller however.

    Do you want the motor to run at each countdown throughout the day or only for the one selected? In other words, do you want the motor to run every 6, 8, 12, and 24 hours (presumably with a different motor run time for each) or only one of those? I assume the latter, but I want to be sure.

    Do you want the countdown to start with a button press ("start), as soon as power is applied, or at a specific time like an alarm clock? Again, I assume the first option, but I want to be sure.

    You can also use PWM to change the speed of the motor if needed.

    You can do the above with any microcontroller.

    If you've never programmed a microcontroller, I personally like the PICAXE - this uses free BASIC software (if you can program in C, BASIC will be a piece of cake) and you don't need much more than the IC, a USB to TTL converter, and an inverter. I'd guess $20-$30 for all the parts for this project before shipping assuming you've got a power supply, breadboard, jumper wires, motor, etc. Of course, I could be way off, but it wouldn't take long to hammer out.

    Assuming you want the timing fairly accurate, you could use a DS1307 real time clock to handle the countdown timing.

    If this sounds appealing in the least, let me know and I can work up a parts list, schematic and make up some code to get you started. If you prefer to stick with C, I leave you in ErnieM's very capable hands. :)
     
    rohitdantkale likes this.
  9. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Hi Elec_Mech,
    Thanks a lot for your reply, I have answered you below in **brown,


     
    Last edited: Apr 4, 2014
  10. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Hi Ernie_Mc,
    Yes, you are right with the inputs option but lets make it very simple by using a pot to control power cut off timing for DC motor and its now a seperate addon part, this part is already there with me.
    Lets just crack the main looped part with different hours setting (6,8,12,24), lets hardcode this for on timing of 1 or 2 min, it will supply to pot and then pot will supply to motor for set seconds (maybe 5 sec).
    And ya, if we can make some button which can externally power the try run, or any better option. :rolleyes:

    what you think? :)
     
    Last edited: Apr 4, 2014
  11. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
  12. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Is the following correct?

    1. You preset the motor run time with a potentiometer - once set, it will never be changed and will be same regardless of the countdown selected
    2. With circuit off, end user selects countdown time
    3. Countdown begins as soon as power is applied to circuit
    4. To select a different countdown, circuit is powered off, selection is made, and power is reapplied

    There would need to be a test button or jumper so you could preset and test the motor run time, but nothing accessible to the end user - at least as I understand your description.

    That could work, but then you're limited to an 8-pin PICAXE. I'll need to hash out a design, but an 8-pin might just do it.

    Are you in the U.S., U.K., or elsewhere? I can put together a BOM that would allow you to buy everything you need to program a PICAXE on a breadboard for under $10 USD. If you prefer a pre-packaged kit like the one you referenced, I can make some suggestions, but need to know what country you're in to minimize shipping costs.
     
  13. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Basic flowchart attached.

    I've assumed you want operation to be as simple as possible. With that in mind, there are no buttons.

    Setting Motor Run Time:
    With the jumper removed, when power is applied and the motor runs once for 1 to 20 seconds depending on the position of the potentiometer and saves this value into memory for normal operation. Thus, the potentiometer will have to be adjusted before power is applied each time.

    Normal Operation:
    When a jumper is present and power is applied, the microcontroller (uC) pulls up the motor run time from memory. If the value is outside 1-20, it defaults to 1. It then looks at whatever switch is used to select the countdown duration (6, 8, 12, or 24 hrs) and begins counting down immediately. Once the countdown duration has passed, the motor runs for the set time, then countdown begins again. As shown, the countdown begins after the motor runs, so if the motor runs for 20 seconds, the countdown begins again 20 seconds after the motor starts. If you need the motor to be run exactly every, say, six hours on the mark when the circuit was first powered, this can easily be changed. As laid out, the uC will ignore the countdown duration selector switch after power is applied, so if someone changes the countdown duration while the circuit is running, it will not change.

    You can add buttons to start the countdown after power up, run the motor multiple times in setting the motor time (instead of cycling power), etc. if you so choose. You may want to add an LED to indicate the circuit is powered if nothing else.

    I think you only need two pins for the RTC, a pin for the jumper, and a pin to control the motor. A power LED can be added to the power supply input if desired. So four pins altogether would allow you to do this with an 8-pin PICAXE. If you think you might want to add other features down the road, you might want to look at a 14- or 20-pin PICAXE instead.
     
  14. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Hi, it needs to be user friendly, so should be without jumper options for a user. I'm from Mumbai, india. I would need the cheapest easily available microcontroller to reproduce whener required, so what test kit I should buy and how the
    circuit design would be and what components total required for it.
    I saw your flowchart and only thing I felt is jumper settings would not be good for end user, seconds option user may need to change seconds option on few alternate days as required for the day. So its a reqular changing switch.
     
  15. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    I guess I'm having a hard time understanding how you want this to operate. At first it sounded like you wanted yourself to set the motor run time and only allow the end user to change the countdown duration.

    It would be very helpful if you could list out, step-by-step, how you want this to operate as well as a rough parts list - mostly just how you want the user to be able to use this circuit, e.g., switches, knobs, etc. Here is an example:

    Circuit is composed of:
    • microcontroller
    • 4-position switch (to set 6, 8, 12, & 24 hours) - a 2-position DIP switch would be easiest and cheapest, but this may not be easy for the average user to understand how to set
    • transistor or relay to control 3-5VDC geared motor
    • potentiometer to adjust motor run time from 1-20 seconds
    • switch to force motor to run (to test run time set by potentiometer)
    • switch to start or reset countdown

    Operation:
    1. Apply power to circuit.
    2. Turn potentiometer to estimated run time needed.
    3. Press RUN button (N.O. momentary switch) to run motor in order to test potentiometer setting.
    4. Repeat steps 2 and 3 until satisfied with motor run time.
    5. Turn rotary knob to desired countdown time.
    6. Press START button to start countdown.
    7. Motor runs for set time immediately after start button is pressed - indicates countdown is starting from zero.
    8. Motor runs once every x hours depending on countdown setting when START button was pressed. This continues until either power is removed from circuit or user presses START button again.
    9. To change countdown during countdown, turn countdown knob to desired time and press START button.

    Some questions:
    1. How will this be powered, e.g., batteries or wall power?
    2. What will be the voltage of the incoming power? You mentioned 9-12VDC for testing, will this be the same voltage the users will have to power the circuit?
    3. How will user apply and remove power? Toggle switch? By unplugging batteries or wall cord?
    4. What is the current rating of the motor? Need this to size the transistor or relay to control the motor.
    5. Do you want the user to be able to test the motor while in a countdown? In other words, force the motor to run between countdowns?
    6. Do you want the user to be able to change the motor run time after a countdown has started?

    You originally implied you want it simple and presumably cheap. Having no switches makes it both, but then it is difficult to test the motor run time and have the countdown start as soon as power is applied. If the user has to adjust the motor run time perfectly, then forcing them to remove and reapply power to test the motor run time can be a pain, which is why I added the RUN and START buttons to the above example.

    Think of every scenario and how you want to address it. Do you want the user to change the motor run time during a countdown or do you want it locked in so it won't change if someone turns the potentiometer? Same question for the countdown duration. In the above example, we force the user press the START button after changing the countdown duration so the microcontroller knows to stop the countdown, determine the new countdown duration then start from zero.

    May we ask what this is being used for? Is this for a hobby project, school, etc.?
     
    rohitdantkale likes this.
  16. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Hi,
    The Operation you wrote is perfectly same what I want, regarding components you mentioned, can we use this switch instead of dip switch (http://www.alibaba.com/product-detail/13A-Slide-Switch-used-for-Oven_869277066.html) this seems more user friendly.

    1. This should have option to connect a 12v DC adaptor and instead can also connect a 9v battery, (will also be giving a separate power to some LED light strip from adaptor if connected, its not part of the timer though)
    2. yes, user will have to use our given options only (9v-12v DC)
    3. user will toggle switch and push the start toggle button to start the countdown as u said
    4. we did some tests with a metal cap transistor, dont know its value, around 7mm cap and it worked well, this is it (http://www.alibaba.com/product-detail/used-in-toy-plastic-dc-motor_520702102.html)
    5. yes, it would be nice if the try button can function when countdown is in progress
    6. yes, it should take the updated seconds value even if changed in between of countdown.
    A toggle button would be good for starting the timer rather than a click and reset button, toggle off will turn of the timer and toggle on will start the timer from beginning.

    This is used for my custom auto room freshener, and some similar concepts daily usage things.
     
  17. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Attached is a schematic and revised flowchart.

    The motor appears to use 200mA. I've shown a logic level MOSFET to turn the motor on and off.

    There are a couple ways to read the value for the countdown duration. You can use a 4-position, single-throw switch and attach resistors to create a specific voltage for each position then read that using an ADC (analog to digital conversion) pin. Another way, shown in the box with the dashed lines, is to use a 4-position, double-throw switch. The one you linked to looks more like a 3-position switch, so be careful of that. With a double-throw switch, you can create a binary output using two pins to give you four unique values.

    Using the resistors only requires one (ADC) pin on the microcontroller. Using two pins allows you to save parts. Choice is yours.

    I've added a bridge rectifier for the incoming power. This allows your customer to use 9-12V AC or DC power and you don't need to worry about the DC polarity - it will work both ways. This adds a bit more of a voltage drop, but still works since the voltage is being dropped to 5VDC anyways.

    You can go out and buy a programming cable and development board, but all you really need is a USB-to-TTL(serial) converter and an inverter. You can buy these on eBay for much less than a dedicated cable or development board, but if you'd rather have those, go for it.

    I've shown a 14M2 PICAXE since it has plenty of pins with some to spare. You could also use an 18M2 or a 20M2, but some connections would need to be changed.

    The battery shown connected to U2 only really helps if you were to set the time in the program. Since you'd lose the alarm time in the event of a power failure, you can leave off the battery and connect pin 3 to GND. Alternately, you could write the program to store the time in EEPROM, thus saving the countdown in the event of a power failure.
     
  18. rohitdantkale

    Thread Starter New Member

    Apr 2, 2014
    12
    0
    Thankyou for a detailed study about it, can you please point me to the kit I need to buy for programming and testing it, I mean a link of it.

    Its looking exactly what I need, Is there any simulation software to create it virtually and test how it runs?
    and also how to design the PCB to adjust all the components in the right place within a 4 or 5 sq-cm?
     
  19. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    The programming software is free and available here.

    I've never used it, but you can purchase a simulator for the PICAXE here.

    It sounds like you prefer a starter kit as opposed to doing everything on a breadboard. If that is the case, this should work. You can program the PICAXE, then move it to a breadboard to test your circuit. If you do this, you don't need to worry about getting any of the items under the Programming section of the schematic I posted.

    I think getting everything onto a 4-5 cm square board will be tight, but possible with through-hole components. Easier with surface mount, but I don't know if you want to go that route. Board size will also be affected by the potentiometer and switches you use.

    You will need a PCB program to do so. Most cost start around $75 USD or more. KiCAD is free and allows you to create Gerber files allowing you to send it to any PCB manufacturer (or do it yourself if you're so inclined). Like most PCB programs, it has a learning curve. I haven't had much luck with it the one time I tried it, but many others here have and use it regularly.

    Another option is ExpressPCB. It is easy to use and the software is free. The downside is you can only have the PCBs made by ExpressPCB. After your first PCB order, you can then pay them something like $50-$100 USD to get the Gerber files if you decide to mass produce your boards somewhere else. Alternately, Futurlec will accept ExpressPCB files and costs less, so that is another option.
     
    rohitdantkale likes this.
  20. PicoKit

    New Member

    Apr 10, 2014
    2
    0
    Hi,

    Not sure if I can help at all, but I've made a motor driver control circuit board (for two motors with L293D) which I can sell for $15 as a kit (special price for anyone on this forum), and you can plug in up to 7 other sensors or outputs. This makes a good development platform for small projects like this.

    The PIC is a 16F506 (which is pretty cheap if you want to produce you own circuit later) after finalising your testing.

    The flowchart software is a bit like picaxe but you actually get the ASM code to read and use later on. You can program in Flowchart with PicoFlow Alpha or in C or in ASM with Microchips own MPLABX - Student versions are free. But any hex compiler will do and I've seen them in Basic and other languages.

    The programmer kit is $20, or a premade is $30 (prices in AUD). The software I can do for free for home & student uses, or I do commercial licenses too.

    But I haven't yet got a real time module to test with the software for your application. Does anyone here have a real-time i2c or serial kit they use to recommend for this sort of application?

    Cheers,
    Phil
     
Loading...