Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Wednesday, 17 February 2016

DIY Mini Drill Controller

Scene-1: The Cause

I was using a small MiniCraft drill machine for drilling holes into my home made PCBs and also for some cutting activity with some attachments. The problem that I had was that when I bought the drill it didn't come with any sort of controller. I used to use it with direct connection to battery.

It was difficult to every time remove the drill once it got stuck, because there was no way to reverse.

Scene-2: The Idea

So one fine Sunday I thought of building this drill controller.

The basic concept was that I have to build a controller circuit for :

  1. Speed Control; so that if there is any delicate job to be done then I can start slowly and increase the speed as and when reuired.
  2. Direction Control; for when the drill would get stuck/jammed I could reverse easily by the push of button.
  3. It should have a Power ON-OFF control.
  4. And finally everything should fit into a Compact box and all the controls should be user friendly and easily accessible. (don't want any tricky controls when you are handling a high speed sharp tool right :D )

Scene-3: Component Selection

To achieve this I thought of a simple idea which is to use motor-driver IC for reversing the direction and controlling the speed and a microcontroller to control the motor-driver.

I initially thought of using relays to control the direction, but then it could have become bulky and speed control would anyhow raise the need of some linear components.

Finally I ended up with L293D, which has 4 individual PUSH-PULL driver and every two of them can be paired to form a H-Bridge channel. It has a current capacity of 600mA per channel with in SOA (Safe Operating Area), beyond which it would require a heatsink (which I don't intend to provide, lack of space).


So I coupled 2 channels which would effectively double the current capacity now to 1.2A. 

The goal was to control the direction of the motor by Input signals of L293D  and speed by providing PWM to L293D input. Both of which would be from a simple low cost microcontroller, and nowadays we can pick up a cheap arduino-pro mini clone for around 200 INR, which is relatively cheap.

The advantage of using a pro-mini kind of board is that all the essential circuity for the microcontroller like clock, power are already present on board and it is quite sleek to fit into my box, and why not go for a pro-micro-328p board for 200 INR when a DIP atmega328p would cost 150 INR.

For speed control I used a 10k POT generally available in market.

I also used two tactile switches:
  1. For toggling direction.
  2. For turning it ON or OFF.
Other components used are a couple of leds, resistors, a plastic knob for POT and a DC barrel Jack.

Scene-4: Realization and Testing

The schematic of the circuit is shown below:


I have added a mechanism to detect Over-current, by which I can prevent L293D from Over-heating, if the motor really gets jammed.

Since it is a brushed motor if the rotor gets stuck then current starts continuously flowing from the same part of the coil which eventually heats-up the armature and reduces its life, and also the Motor-driver can get damaged because of high-current flow, remember the peak limit is 1.2A even when both channels are combined.

So for that I used a shunt resistor of 0.08Ohm and used to measure the voltage drop across it using ADC of atmega328p. So when voltage across it reaches 96mV (1.2A x 0.08Ohm) then we should disable the L293D in the program.

I also added a functionality to prevent transients which is called Soft-start (mostly used for powering high-current loads), which is basically slowly increasing speed (using PWM) during POWER-UP instead of instantly supplying full power.

All these and other features are present in the program.

Click the link below to get the design files (schematic) and program for it.
Code and Schematic

I have written the program using Atmel Studio, however it can be easily adapted for use with Arduino.

The programming is almost complete however there are a few glitches which I am not getting time to resolve (documented in the Readme file). Feel free to make any changes and customize according to your needs.

Scene-END: Result

Below is the result of what I built :)



The demo can be seen in the video below :



CAUTION: DO NOT PLAY WITH HIGH-VOLTAGE AND CURRENT. USE EXTREME CAUTION WHILE HANDLING POWER TOOLS.

DISCLAIMER: ALL THE INFORMATION PROVIDED IN HERE IS AS IS, WITHOUT ANY WARRANTY. THE AUTHOR IS NOT LIABLE FOR ANY LOSS WHAT SO EVER ARISING FROM THE USE OF THIS INFORMATION. USE AT YOUR OWN RISK.

Wednesday, 3 December 2014

3 wire interface for 16x2 or 8x2 or any other HD44780 based LCDs.

When interfacing with Micro-controllers a LCD display could be a very useful tool either for debugging or displaying messages or to show result of a calculation or some other information.

In embedded World the most popular LCD is a 16x2 display i.e. 16 characters per line and 2 lines on the display. However there are other variants like 8x2 or 20x4 etc. These Displays are run by the very popular lcd controller Hitachi HD44780.



This display controller is the most widely used one and has lot of documentation available on the web. However while interfacing it with micro-controllers one problem arises very often. The scarcity of pins.

The HD44780 operates on a 8bit or 4bit wide bus and requires at-least 2 extra control pins(3 to be exact). So the minimum number of pins required to interface such a display is 6.

So to add a lcd to our micro-controller system we will have to sacrifice at-least 6 pins of our micro-controller. If we are using 40pin ICs like ATMEGA32 or 89C51/89S51 or 40 pin PIC then it is not much of a concern.




But if our chip has about 20 or less than that pins for IO? lets take Arduino UNO for example we have only 14 digital + 6 Analog/Digital pins. Reserving 6 pins for LCD is very tragic.

But what if we could reduce the number of pins required. This can be achieved by a very simple and effective digital logic chip : A Serial in Parallel out shift Register.

So by using a shift register either CD4094 or 74HC595 we can interface the Lcd with the help of only 3 pins.

A serial-in-parallel-out shift-register takes data-in using essentially one pin only(however another pin CLK is required to synchronise the transfer) and it has in general a 8 bit output(i.e. 8 output data pins).




So we send the data using only one pin of the micro-controller and then as usual the 4bit or 8bit data is given to the LCD controller by the Shift-register.

However another pin Strobe is required to enable or disable the output of data on the pins. Because if we keep continuously sending the data and data keeps travelling on the shift-register's output pins continuously then the lcd controller can get mad.

So what we do is we actually hold the outputs until the whole 8 bits are sent into the shift register. Then we release the output pins and data goes into the lcd controller.


But remember since we still need to control the RS(register select) and E(enable) pins of the LCD controller and that is also accomplished by the help of shift-register. 

So what i did was that i connected the RS and EN pins of the LCD to the shift-register output pins and sent the same data or control byte twice; once with EN set(1) and again the same data content and RS value but EN pin value cleared(0).

In this way the EN pin was provided with CLK.

Since i was using 4bit data bus so i had to send 4 nibbles while using Shift-register as opposed to the 2 nibbles when directly connected.

I have made a project to demonstrate this on AVR micro-controller you can get it here. This project also contains an arduino sketch with the same functionality. 

However i have also made a ready made library to to integrate it with your existing programs. Here is the link to the library. You just need to keep two files sipolcd.h and ds.h in the folder of your <main_program>.c file and and before including sipolcd.h  you need to define SIPO_PORT possible values are A,B,C,D or whatever ports your AVR has.

And then SPIN which is the DATA pin of Shift-register, STB i.e. strobe, and CLK is CLOCK.

Let me put an example here.

You can find other keywords in the keywords.txt file in the above mentioned library.

And finally here is the code in action.




We know that to be able to use the LCD with only 3 wires is cool but there are some people who have made it possible to use a lcd with Only 1 wire, That's right only 1 wire is enough. But it is a little tricky and you will have to go a little deeper with R-C time constants and frequencies etc. Here is the link to the Shift1_System.

So as usual guys if you have any suggestions or questions feel free to post a comment.