sâmbătă, august 29, 2015

Controlul unui motor folosind o punte H

Salut,

In acest articol voi prezenta modul in care un motor poate fi controlat cu ajutorul unei punti H.

O punte H este un circuit construit din 4 tranzistoare care actioneaza ca niste intrerupatoare, iar pozitia acestora determina sensul de rotire al motorului.

Punte H
Punte H
 
In stanga figurii de mai sus comutatoarele A1 si A2 sunt inchise si curentul va trece prin ele iar sensul va fi prin A1-motor-A2 si motorul se va roti in sensul acelor de ceasornic.

In dreapta figurii de mai sus celelalte doua comutatoare B1 si B2 sunt inchise si curentul va trece prin ele si prin motor iar motorul se va roti in sens invers acelor de ceasornic.

In total exista 2^4=16 pozitii posibile ale comutatoarelor. In general se folosesc doar 4:
  • toate deschise --> motorul este in standby
  • A1,A2 inchise, B1,B2 deschise --> motorul se invarte in sensul acelor de ceas
  • A1,A2 deschise, B1,B2 inchise --> motorul se invarte in sens invers acelor de ceas
  • cele de sus inchise, cele de jos deschise sau invers --> motorul este franat
ATENTIE: Niciodata comutatoarele de pe o latura a puntii (A1+B1 sau A2+B2) nu trebuie inchise simultan deoarece se face scurtcircuit (curentul trece direct de la Vdd prin tranzistoare spre Gnd si se vor arde tranzistoarele).
Pentru a impiedica acest lucru, in practica se comuta tranzistoarele de pe o latura simultan (unul off si celalalt on), legand intrarile celor doua tranzistoare intre ele, de regula tranzistoarele de sus (high side) fiind PNP iar cele de jos (low side) fiind NPN. In figura de mai jos este exact invers. :)


Punte H cu tranzistoare bipolare
Punte H cu tranzistoare bipolare

Legand intrarile de pe o parte si cealalta, lucrurile se simplifica, ramanand astfel 2 pini ce trebuie comutati on-off, avand doar cele 4 combinatii descrise mai sus.

Acest design explica cel mai bine principiul de functionare al puntii H. In practica design-ul folosind componente discrete este destul de costisitor, si consuma foarte mult spatiu pe o placa PCB. De aceea se pot folosi circuite integrate specializate, ce pot oferi un curent de iesire destul de ridicat (de ordinul amperilor). Ex: L293B/D.

Punte H L293
Puntea H L293

In figura se observa ca integratul are 4 intrari (input) logice (0V sau 5V) si 4 iesiri (output) de putere (0V sau 12V).
Fiecare iesire corespunde fiecarei intrari. Astfel, daca Input_1 = 0V --> Output_1 = 0V, iar daca Input_1 = 5V --> Output_1 = 12V.

Practic se obtine o translatare a nivelului logic 0-5V in nivelul logic 0-12V. Acesta din urma poate oferi atat o tensiune mai mare (12V), cat si un curent mai mare (0.6A---1A in functie de capsula).

De asemenea, exista si doi pini de Enable (EN1 pentru Output1 si 2, EN2 pentru Output3 si 4) folositi pentru a valida cele 4 iesiri. Acesti 2 pini, impreuna cu cei 4 pini de Input se conecteaza la un microcontroller care gestioneaza actionarea acestora.

Sunt doua modalitati de folosire:

1. Pinii de ENable conectati fizic la +5V --> Iesirile sunt validate permanent si controlate doar prin cei 4 pini de input conectati la microcontroller.

2. Pinii de ENable sunt conectati la microcontroller. Avantajul este ca prin acesti 2 pini se poate comanda turatia motoarelor prin PWM (Pulse Width Modulation).
De obicei un microcontroller are un numar limitat de iesiri PWM.

Astfel, variind factorul de umplere intre 0% si 100%, putem obtine orice tensiune intre 0 si 12V.
Factor de umplere PWM
Factor de umplere PWM
In graficul de mai sus, se observa 3 cazuri, primul in care obtinem 25% din tensiunea de alimentare, adica 0.25*12V=3V. Pentru 50% obtinem 6V, pentru 75% obtinem 9V etc.

Pe langa factorul de umplere, trebuie sa folosim o frecventa care sa influenteze cat mai putin modul de lucru al motorului. De obicei, o frecventa de 25KHz este suficienta pentru un motor.
In graficul de mai sus, f=1/(Ton+Toff)=ct=25KHz, unde Ton este timpul in care EN este pe 1Logic=5V, iar Toff este timpul in care pinul de EN este pe 0Logic=0V.

Spor la controlat motoare folosind o punte H, fie cu tranzistoare discrete, fie cu circuite integrate!

vineri, iunie 19, 2015

Controlul turatiei unui motor in functie de luminozitate folosind o fotodioda si un microcontroller

         Acesta este un proiect realizat in anul IV de facultate (2013) la cererea unor colegi mai neinitiati in ale electronicii.
         Desi pe piata au aparut de ceva timp module de senzori (shield), am preferat la acel moment sa  construiesc unul propriu: preiau tensiunea captata de o fotodioda expusa luminii ambientale si o amplific cu un AO cu amplificare foarte mare (100.000).
Senzor de lumina
Senzor de luminozitate + comanda motor
         Semnalul analogic furnizat de senzor este apoi citit cu un microcontroller (PIC de la Microchip, evident https://s.yimg.com/pu/emoticon/v2/4.gif), scara de masurare fiind 0-5V folosind un ADC pe 10biti (1024 de valori intermediare intre 0-5V).
         Pentru a controla turatia motorului am folosit un semnal PWM (Pulse Width Modulation) pe 10biti generat de microcontroller. Semnalul intra in baza unui tranzistor care are drept sarcina in emitor un motor de curent continuu cu perii (brushed DC motor).
Programare PIC16f887
PIC16F887 - conexiuni
          Iesirea senzorului se conecteaza la unul din pinii GPIO analogici (RA2 de ex) iar semnalul PWM se obtine din pinul RC1 (CCP2).
          Atat semnalul analogic captat de microcontroller, cat si semnalul PWM generat sunt pe 10biti, astfel ca factorul de umplere al semnalului PWM este chiar valoarea numerica pe 10biti a semnalului analogic.

          Programul a fost scris in mikroC for PIC si este extrem de simplu. Practic se foloseste o variabila pe 10 biti in care stocam tensiunea citita de la senzor si setam factorul de umplere al semnalului PWM cu acea valoare.
          Pentru scrierea programului in microcontroller am folosit un PICkit2 (Microchip).
          Rezultat:
         
            Este un proiect simplu dar din care am invatat cateva lucruri la vremea respectiva. Acesta era si motivul pentru care ma ofeream sa ajut colegii cu diverse proiecte, partea financiara fiind doar un detaliu minor https://s.yimg.com/pu/emoticon/v2/4.gif. Cel mai important pentru mine era sa capat experienta si dexteritate.

sâmbătă, februarie 14, 2015

Life of RaspberryPI: Remote Desktop through VNCViewer

Hi everyone,



If you run RaspberryPI headless because you don't have a monitor, you might want to see the RaspberryPI's Desktop remotely.
For this, you need to set up a VNC server on RaspberryPI and a VNC client on your laptop.
The connection will be made via LAN cable, the same you are using for SSH control.

1. Set up VNC server on RaspberryPI

Connect with Putty to your device and send this commands:
root@raspberrypi:~# sudo apt-get install tightvncserver
Type y and press Enter in order to allow installation. 
root@raspberrypi:~# tightvncserver
Set up a password of 8 characters and an optional password for view only.

root@raspberrypi:~# vncserver :0 -geometry 1024x768 -depth 24

Launch a Desktop with 1024x768 resolution.

2. Install VNC client on your laptop


Download VNC Viewer and install it.
Open the program, type the IP of RaspberryPI and click on Connect.
Type in the password you set above and you are ready to go!

Life of RaspberryPI: Connect the PI to the internet.

Hi everyone,

In the previous post I showed you how to install Raspbian and how to connect to you Raspberry PI.
Now, you may want to connect it to the internet. There are many ways to do it.

1. USB tethering from mobile phone

This method saves your RJ-45 port which you can continue to use for SSH connection.

First, you have to connect your mobile phone to one Raspberry PI USB port via microUSB cable.
In your phone go to Settings > Tethering > USB Tethering. Check the button to enable the connection.

On RaspberryPI send the command:
root@raspberrypi:~# sudo dhclient usb0
root@raspberrypi:~# ping google.com
PING google.com (80.97.208.35) 56(84) bytes of data.
64 bytes from 80.97.208.35: icmp_req=1 ttl=53 time=49.6 ms
Now you can see that the internet is working if you ping Google.

2. Share your Wi-Fi through your LAN cable

Let's say your laptop is connected to a Wi-Fi hotspot (e.g. your router).
The RaspberryPI is connected with your laptop through LAN cable.

Go to Control Panel > Network and Internet > Network and Sharing Center
Click on Change Adapter Settings (left panel).
Right click on the Wireless Network Connection > Properties > Share
Check Allow other network .... and select Local Area Connection. Press Ok.

Now, click on Local Area Connection > Properties > IP v4 > Properties
and make sure it will take an IP automatically:
Start Menu > Run > cmd  and type ipconfig:


Now, copy this IP and add it to cmdline.txt located on the microSD card:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip=169.254.1.1::169.254.165.161

You can do this by either plugging the microSD into the laptop and edit the file with Notepad, or you can edit the file through Putty:

root@raspberrypi:/# cd /boot
root@raspberrypi:/boot# vi cmdline.txt




Similarly, edit the file /etc/resolv.conf to look like this:
root@raspberrypi:~# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
These two lines are the Google DNS servers. It helps your device locate websites and hostnames. Now, reboot your device:
root@raspberrypi:/boot# reboot
Broadcast message from root@raspberrypi (pts/1) (Sat Feb 14 11:02:52 2015):
The system is going down for reboot NOW!
After reboot:

root@raspberrypi:~# ping google.com
PING google.com (80.97.208.24) 56(84) bytes of data.
64 bytes from 80.97.208.24: icmp_req=1 ttl=53 time=598 ms
64 bytes from 80.97.208.24: icmp_req=2 ttl=53 time=34.3 ms
So it works!

Life of RaspberryPI. Hello World!

Hi everyone,

So far I have only been using microcontrollers in my projects. They were doing fine the tasks they were supposed to (usually one), but had their limitations such as low clock speed (20MHz) and more important, it was extremely hard to implement a real time operating system and to run parallel tasks.

A RaspberryPI microcomputer is a tiny board that offers both the performances of a real computer and the features of a microcontroller: IO pins, small dimensions and programmability.

RaspberryPI B+

I bought this from a local store in Bucharest and I was so excited that this little toy will run Linux for me!

They recommend us all to use the NOOBS installer. But if you don't have a monitor available, it's an impossible mission to have it running. So what I will show you next, is how to run the RaspberryPI headless (no monitor, no keyboard, no mouse).

Run headless RaspberryPI

RaspberryPI boots from a microSD card. To install an operating system on it, you have to download the latest Raspbian image: via torrent or direct link.
Unzip it and you will obtain a .img file, such as: 2015-01-31-raspbian.img

Download Win32 Disk Image, install it and Write the image to a microSD card (4GB or above).
Make sure you select the right device. Check My Computer for your microSD letter assigned.

Once the process completes, edit the file cmdline.txt located on the microSD card and assign an IP to your RaspberryPI:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait ip=169.254.1.1

You can eject the microSD card from your computer and plug it into your RaspberryPI.

Now, connect a LAN cable between the RaspberryPI RJ-45 port to your laptop's RJ-45 port.
Power on the device via microUSB port. You should see the LEDs flickering.



You can now connect to your Raspberry PI using Putty.
Just type in the IP you set above and click on open:

You will be asked for your credentials:
login as: pi
pi@169.254.1.1's password: raspberry


Now you can administer the PI as you want! Have fun!