Saturday, June 30, 2012

Time Switch_3: Designing a clock I


Now that we have the equipment list on mind we will start programming the PIC. The softwares that I will be using for this project include 'Proteous' and 'MicroC pro for PIC'. To understand the coding a prior knowledge in C will be needed. I will try to elaborate the best I can.

Time switch is a product which deals with time. So we must have a mechanism to measure or count time. If we have that, then the rest of the project is just some coding. How can we count a second in PIC16F628A? Or what are the methods available?

  1. We can use the command 'delay_ms(1000);' in MicroC to generate a delay of 1000 milliseconds.
  2. We can use Timer modules in the PIC and use its overflow interrupts to count time.

Method 1:

This is straight forward and easy. What actually happens inside the PIC when we execute this command will give us a better insight of its capabilities.

You should be able to understand the PIC architecture in order to interpret any command.



Figure 1: How a delay is generated in a PIC.

Above flowchart explains a method to generate a delay in a micro-controller. By using appropriate values for A, B and C variables we can generate a delay. But in this method the processor will always be busy updating registers so that the user will not be able to change any configuration without interrupting the delay process. That means the processor will not be able to multi-task without interrupting the delay. Therefore I prefer not using this method.

Method 2: [Please go through PIC16F628A datasheet]

To use this method you must know about the 'Timer' modules available in the PIC. There are 3 modules 'Timer0, Timer1 and Timer2'.

'Timer0' is a 8bit register and it can be connected to the device clock with or without a pre scalar. When ever there is an overflow in the Timer0, it will generate an interrupt. By handling interrupts we can easily do the job. The user will also able to interact with the system through multi-tasking.

That is Timer0 will overflow every 51us.
(system clock = 20MHz, instruction clock = 5MHz, 255/5MHz = 51us)

So it will overflow approximately 19600 times per second.
(1 / 51us = 19600)

Let us assume that the interrupt handling will take 10us. So all together 61us ;(51+10), will be consumed per overflow which gives us around 16400 overflows per second. This will give user a window of 0.84seconds to do interactions with the device and it will not interrupt with the time counting processes.
(51us * 16400 = 0.84seconds)

If this sounds Greek. I am truly sorry, but going through the datasheet and understanding the micro-controller will solve the problem. In the TS device I will use the Method 2 to count seconds.

Next step will be coding. :)

Time Switch_2: Selecting equipment.

In any product design this step is of utmost importance. This is due to several factors. First one is that the performance of the system you design will be depending on the equipment/components you use to create it. Next is that you should purchase the equipment keeping at least one from each critical components redundant. So if you have mistakenly broken one critical component you can use the spare. Another reason is that some equipment needed to be purchased directly from the manufacture so it will take some time to reach you due to shipping, so you will be able to order components keeping a time cushion for safety and you will be able to meet the deadlines.
What are the most critical equipments in the TS?
First is the processor. Here I used a PIC16F628A. This is one of the very basic micro-controllers that you can purchase for around 1$. Due to the simplicity of the project, we don’t need to buy any sophisticated micro-controller. This is just a choice. This can be done by using any other processors (Atmel AVR, etc.).
The tasks that I want to accomplish using this micro-controller are quite simple. I want to of course drive around five switches (the number of switches will be decided later, for now we’ll plan for five). I want a LCD display to control these switches. I want a keyboard/keypad to insert commands.
We’ll forget about power supply for now and just think about the main board. I need relays to drive AC switches. I need transistors to drive the relays since they need high current (output current of a PIC is limited, so we need a current driver to drive the relays). Those are the most critical parts. Some capacitors, resistors and diodes will also be needed.
All the equipment I stated above are available everywhere.
Relays should be able to be driven by a mere 5V. That should be kept in mind. And the LM016L LCD display will be used here. I chose it because I have it with me :) and also it is available in the market for around 5$.
With those equipments in mind we’ll proceed to the next step.
:)


Friday, June 29, 2012

Time Switch_1



This is a project which will use simple methods to design a time switch. Time switch is the name I have given to the product. What this time switch(TS) does is, it will switch off or switch on a device/ or many devices which is/are connected to AC power after a given interval. It is a very simple task, but I want to design one myself and use it for my needs. I should provide that this equipment is already available in the market.

To start with I needed a logical design to track my progress as well as to make the designing process efficient. I prefer modularizing the design and implementing one by one in order to reduce the complexity of the design. This logical design may be and will be changed according to the practical scenarios that I will be facing later in my designing stages (which is the case in almost all the designs which are done by individuals).

Following is my initial logical design,



Figure 1 : Initial logical design of the TS.


The figure itself is self explanatory so I will not go in detail about it. To understand the process correctly, some prior knowledge is needed on PIC based micro-controllers, relays, rectifiers, etc.. If you don't have any knowledge on these things, don't panic because problem based learning is the best way to do. Just google what you don't understand.

Figure 1 is the design that we are going to make, next task will be to generate a design flow. The flow for this particular design can be different from one person to the other, due to his/her personal knowledge. Some of the steps can be skipped, or else some additional steps maybe required. But the intention should be to generate milestones along the way so that you can track where you are. Moreover, the flow should be in such a manner that you will be able to modularize the process. Now the design and the flow both are modularized, so you can easily design one by one and finally integrate them together (which becomes the hardest task in almost all the cases).

Figure 2: Design flow of the TS

Figure 2 is what I think the best way to develop the product, and there can be many subprocesses for each step. I will keep these as milestones and develop the project.

:)