Showing posts with label Robot. Show all posts
Showing posts with label Robot. Show all posts

Sunday, September 04, 2011

Driver Motor DC Relay dilengkapi dengan PWM

Driver Motor DC Relay dilengkapi dengan PWM

PWM ( Pulse Width Modulation ) bisa digunakan dalam mengendalikan kecepatan motor dengan cara mengubah lebar pulsa yang berdasarkan duty cyclenya. Sehingga secara tidak langsung mengakibatkan perubahan pada kecepatan motor itu sendiri.

Dibawah ini merupakan salah satu rangkaian Driver Motor DC dengan port PWM


Port Dir digunakan untuk merubah arah pergerakan motor CW/CCW.
Port PWM digunakan untuk inputan sinyal PWM itu sendiri.

Relay disini difungsikan sebagai pengaturan arah pergerakan motor ( CW=searah jarum jam atau CCW=berlawanan arah jarum jam )

Sedangkan.

IRF Mosfet sendiri digunakan sebagai inputan sinyal PWM, dengan memanipulasi jalur GROUND terhadap Motor.

Jumlah IRF Mosfet yang digunakan, tergantung dari besar arus (Ampere) motor yang dibutuhkan. Semakin besar arus (Ampere) motor yang dibutuhkan semakin banyak IRF Mosfet yang digunakan atau dengan menggunakan seri lain dengan spesifikasi Arus (Ampere) yang lebih besar.

Rangkaian ini bisa anda tambahkan sendiri dioda serta capasitor sebagai peredam spice,yang bisa muncul ketika motor baru berjalan atau perubahan arah putaran motor itu sendiri.Yang bisa di hubungan antara kutub kaki motor dengan sumber arus / sumber tegangannya.

Created By : I NYOMAN SURYASA S.Kom
Design By : http://www.digitdude.com

Wednesday, August 10, 2011

Cara Membuat Tricopter

The Tricopter build


It was a long time since I owned a helicopter, they were to expensive and fragile. I hated that you had to order replacement parts every time you had a minor crash. I want to be able to repair it my self, swift and easy. So I decided to design my self a Tricopter. That way I get it just the way I want it.

So what is a Tricopter?



It’s an aircraft similar to a helicopter except it has three rotor disks. The beauty of the design is that three ordinary outrunners direct driving ordinary propellers can be used. Four helicopter gyros makes the tricopter super stable. And to make it yaw a servo tilts the back motor. You set your radio for 120° CCPM and your good to go. It’s as simple as that. Very low part count, simple, cheap, easy to build with no advanced electronics needed.

What to buy?
After testing various speed controllers, motors, gyros, etc. These are the electronics I recommend buying for a tricopter weighing under 1.2kg:

3 x 2213N 800Kv Brushless motors
3 x TURNIGY Plush 18amp Speed Controllers
4 x Hobby King 401B AVCS Digital Head Lock Gyro
1 x 6 pack GWS 10*4.7 propellers
1 x 10 pack prop adapters
1 x BMS-385DMAX Digital Servo (Metal Gear)

1 x 3S 2200mAh Turnigy LiPo
1 x Turnigy UBEC for making the “jump starter” for the gyros

These are electronics I know work good on a Tricopter and have personally tested.

The Build
Now lets start building.



I used 1.5mm DIY PCB glass fiber laminate for making the motor mounts.



This is my solution for the back motor tilt. It’s a T-Rex 450 blade grip mounted to a piece of plastic.



It’s super low friction that I hope will give me a slop free tilt mechanism.



The back motor mount test fitted with the tilt mechanism.



I used a T-Rex 450 tailboom that I had laying around for making a light weight filler so that the glass fiber lamination doesn’t flex when I screw down the motor.



I made a simple servo mount to get the servo to the right height and make it easy to remove.



Here are the servo plates that also holds the tilt mechanism.



To remove weight I etched away the copper from the glass fibre laminates.



Test fitting the motor mount.



Turned out pretty nice. I will be using wood as my arms and as you can see in the picture, the mount is just screwed down, clamping the wood. This makes it super easy to fit new arms if I ever brake one or want to try longer ones.



This is my frame design. It’s not super pretty but I hope it does the job.



My tricopter is going to be foldable so I drilled a hole through the two front arms.



The tilt mechanism almost done. I had to add a piece of plastic to make it as thick as the arms.



Tilt mechanism done.



Motor mounts done.



I cut of a piece of the top piece of the frame to be able to mount the receiver in-between the to sheets of 1.5mm glass fiber laminate.



Gyros in place.





Started work on extending the cables on all the ESCs. Before and after.

All the electronics in place.





For some reason the Turnigy gyros did not work well with the Futaba receiver I had planned on using. I think it has something to do with the shorter frame rate Futaba 2.4GHz system uses. It made the output of the gyros go crazy at some points, so now I use a Assan 6 channel receiver.





Tilt mechanism cable solution.



Underside of the frame.



The arms when the tricopter is folded for transport.



The frame when it’s folded for transport.





Time for a test flight!

 

Udah dulu ah.cape jam udah menunjuki 11 agustus 2011 / 2:42 Pagi

wkwkwk..mau tidur dulu.

Monday, August 01, 2011

Interfacing an optical mouse sensor to your Arduino

Disini akan dijelaskan bagaimana menggunakan optical mouse untuk di aplikasi kan kedalam perangkat robot.sebelumnya kita coba mengeluarkan datanya dari optical mouse tersebut.

Optical Mouse memungkinkan kita dapat mengetahui koordinat xy dari perpindahan yang terjadi.

Materials


This is what you need:

  • Arduino board (any *duino will do) and the Arduino IDE.

  • Optical mouse containing the PAN3101, ADNS-2610, ADNS-2083 or ADNS-2051 optical sensor. These sensors come in many mice sold today. If yours has a different sensor, don’t worry too much; they are all much alike. With a bit of luck, the library I wrote will work with other sensors as well.

  • OptiMouse library for Arduino

  • Some wires and soldering gear.


Step 1 – Open up your mouse!


The optical sensor and LED were covered with the black protective cap. Take it off carefully.



PAN3101

Step 2 –Take a look at the datasheets


Check out the datasheet of the sensor you’re dealing with (Google).We only need to connect 4 pins of the sensor to the Arduino, of which two are used for data and two for the power supply. The sensor uses bi-directional serial communcation over one data line (SDIO, pin 3). The second data pin (SCLK, pin 4) is used to time the bits. In case of a different type of sensor, the pin numbers might be different.

PAN3101 Pinout

Step 3 – Cutting the controller wires (optional)


To make sure the mouse’s own controller does not interfere with the Arduino, I had cut the SDIO and SCLK wires running to the chip in the mouse. I’m not sure whether this is really necessary, so you might try first without cutting them.

Cutting the spinal cord of the mouse

Step 4 – Connecting wires


Solder wires to the four legs of the sensor that I indicated above. The +5V should go to the 5V Power pin on the Arduino, the GND should go to the GND Power pin on the Arduino. Pretty straightforward. Connect the SCLK to Arduino digital pin 2 and SDIO to Arduino digital pin 3. (You are free to use other pins as well, but in this tutorial I’m using pin 2 and 3.)

Soldering wires to intestine of the poor lil' mouse - Part 2

Step 5 – Example sketch


Download this .zip package with the library and example sketches. Expand the archive and move it into:

arduino-0010/hardware/libraries/

Restart the Arduino IDE. The examples should appear in File > Sketchbook > Examples > Library-OptiMouse. Open the Coordinates example and upload it to your Arduino board. Start Arduino’s serial monitor (38400 baud) to see the coordinates of your mouse coming in… Done!

Arduino meets the mouse



Sumber : http://www.martijnthe.nl/2009/07/interfacing-an-optical-mouse-sensor-to-your-arduino/

Sunday, July 31, 2011

Aplikasi Scada System pada Miniatur Water Level Control

Makalah ini menjelaskan pembuatan Miniatur Water Level Control yang digunakan sebagai salah satu bentuk simulasi dari proses yang terjadi dalam dunia industri.

Project ini juga dilengkapi dengan SCADA sistem, yang akan memberikan gambaran lebih nyata tentang proses yang dimaksud. Untuk lebih memudahkan proses kontrol dan monitoring, maka bentuk dan ukurannya-pun dibuat dalam model miniatur yang mudah dibawa (portable).

Miniatur water level control dibuat sebagai plant yang dikontrol oleh PLC. PLC yang digunakan ada 2 macam yaitu: OMRON CPM1 dan MODICON TSX Micro 3721. Sedangkan komputer dalam hal ini SCADA software akan memvisualisasikan proses yang terjadi pada plant.

Dari pengujian yang dilakukan, sistem dapat berjalan sesuai dengan yang diinginkan yaitu mempertahankan level ketinggian air.

Di mana pencapaian kestabilan terjadi apabila nilai sensor sama dengan set_point.

Untuk menjalankan sistem digunakan metode kontrol PID dengan bias (teg_pompa = bias + error).

Download

Komunikasi PLC ke DCS atau ke Sesama PLC

Rangkuman Diskusi KBK Instrumentasi

21 September 2006 – 6 Oktober 2006

Milis Migas Indonesia : http://groups.yahoo.com/group/Migas_Indonesia

Migas Indonesia Online : http://www.migas-indonesia.com

Migas Indonesia Network : http://www.migas-indonesia.net

 

Editor :

Windra Gumilar

Swastioko Budhi Suryanto

Moderator KBK Instrumentasi

Bisa download sini.

PLC (Programmable Logic Controller) – Pengantar

PLC (Programmable Logic Controller) diperkenalkan pertama kali pada tahun 1969 oleh Richard E. Morley yang merupakan pendiri Modicon Corporation. Menurut National Electrical Manufacturing Assosiation (NEMA) PLC didefinisikan sebagasi suatu perangkat elektronik digital dengan memori yang dapat diprogram untuk menyimpan instruksi-instruksi yang menjalankan fungsi-fungsi spesifik seperti: logika, sekuen, timing, counting, dan aritmatika untuk mengontrol suatu mesin industri atau proses industri sesuai dengan yang diinginkan. PLC mampu mengerjakan suatu proses terus menerus sesuai variabel masukan dan memberikan keputusan sesuai keinginan pemrograman sehingga nilai keluaran tetap terkontrol.

PLC merupakan “komputer khusus” untuk aplikasi dalam industri, untuk memonitor proses, dan untuk menggantikan hard wiring control dan memiliki bahasa pemrograman sendiri. Akan tetapi PLC tidak sama akan personal computer karena PLC dirancang untuk instalasi dan perawatan oleh teknisi dan ahli listrik di industri yang tidak harus mempunyai skill elektronika yang tinggi dan memberikan fleksibilitas kontrol berdasarkan eksekusi instruksi logika. Karena itulah PLC semakin hari semakin berkembang baik dari segi jumlah input dan output, jumlah memory yang tersedia, kecepatan, komunikasi antar PLC dan cara atau teknik pemrograman. Hampir segala macam proses produksi di bidang industri dapat diotomasi dengan menggunakan PLC. Kecepatan dan akurasi dari operasi bisa meningkat jauh lebih baik menggunakan sistem kontrol ini. Keunggulan dari PLC adalah kemampuannya untuk mengubah dan meniru proses operasi di saat yang bersamaan dengan komunikasi dan pengumpulan informasi-informasi vital.

Operasi pada PLC terdiri dari empat bagian penting:

1. pengamatan nilai input

2. menjalankan program

3. memberikan nilai output

4. pengendalian

Dari kelebihan diatas PLC juga memiliki kekurangan antara lain yang sering disoroti adalah bahwa untuk memrogram suatu PLC dibutuhkan seseorang yang ahli dan sangat mengerti dengan apa yang dibutuhkan pabrik dan mengerti tentang keamanan atau safety yang harus dipenuhi. Sementara itu orang yang terlatih seperti itu cukup jarang dan pada pemrogramannya harus dilakukan langsung ke tempat dimana server yang terhubung ke PLC berada, sementara itu tidak jarang letak main computer itu di tempat-tempat yang berbahaya. Oleh karena itu diperlukan suatu perangkat yang mampu mengamati, meng-edit serta menjalankan program dari jarak jauh.

Download kode program dan buku

Download Kode Buku dan update file (last updated 2 Agustus 2007)

12 Proyek Sistem Akuisisi Data, Elex Media Komputindo,2007

Download kode 12akuisisi.zip
Teknik Reparasi PC dan Monitor, Elex Media Komputindo,2005

Download kode monitor.zip

Panduan Lengkap Pemrograman J2EE Terbitan Andi Offset Yogya 2005 )

Download kode pemrogramanj2ee.zip
Download Update Materi Servlet & JSP UpdateJ2ee.zip

12 Proyek Mikrokontroler untuk Pemula, terbitan Elex Media 2007

Download kode 12proyek.zip
Elektronika Digital dan Mikroprosesor Terbitan Andi Offset Yogya 2005

Download kode mikroprosesor.zip
Download Turbo Assembler tasm.zip
Download Program Assembler BLASM IDE ASSEMBLER (Buat compiler assembly)

Pemrograman Web Menggunakan J2EE

Download Kode dari buku “Pemrograman Web Menggunakan J2EE”, Elexmedia Komputindo 2004

Interfacing Komputer dan Mikrokontroler

Download kode dari buku“Interfacing Komputer dan Mikrokontroler“,Elexmedia Komputindo, 2004
Download turbo c Turbo C++ Lite

Perancangan Sistem dan Aplikasi Mikrokontroler

Download kode dari buku“Perancangan Sistem dan Aplikasi Mikrokontroler“,Elexmedia Komputindo, 2005

Aplikasi Database Oracle 10g dengan Visual Basic 6/VB.Net

Download kode dari buku“Database Oracle 10g dengan Visual Basic, Elexmedia Komputindo, 2005

Membuat Robot Cerdas

Download kode dari buku “Membuat Robot Cerdas,Elex Media Komputindo

Pemrograman VB .Net 2005

Download kode dari buku “Pemrograman VB .Net 2005,Andi Offset Yogya,2006

Menguasai VB .NET Tingkat Lanjut

vbnet1.zip (Kode program VB .NET dari buku “Menguasai VB .NET Tingkat Lanjut”, 647KB) new
vbnet2.zip ( Kode program VB .NET anjutan dari buku Menguasai VB .NET Tingkat lanjut”,615 KB)
vbnet3.zip (Kode SQL, gambar panduan pembaca buku “Menguasai VB .NET Tingkat lanjut”, 100 KB)

Vb.NET untuk Aplikasi Perkantoran

Download kodevbnetperkantoran.zip (Kode Program dari buku ” Vb.NET untuk Aplikasi Perkantoran”, 900 KB)

Aplikasi e-Commerce Menggunakan Visual C#.NET

Download kode dari buku“Aplikasi e-Commerce Menggunakan Visual C#.NET”,Andi Offset, 2004.

Aplikasi Database menggunakan SQL Server 2000 dan Visual Basic 6, Terbitan Elex Media 2001

Download kodevb6.zip

Sistem Otomatis

Sistem otomasi dapat didefinisikan sebagai suatu tekhnologi yang berkaitan dengan aplikasi mekanik, elektronik dan sistem yang berbasis komputer (komputer, PLC atau mikro). Semuanya bergabung menjadi satu untuk memberikan fungsi terhadap manipulator (mekanik) sehingga akan memiliki fungsi tertentu.
Sejarah perkembangan sistem otomasi bermula dari governor sentrifugal yang berfungsi untuk mengontrol kecepatan mesin uap yang dibuat oleh james watt pada abad ke delapan belas. Dengan semakin berkembangnya komputer maka peran-peran dari sistem otomasi konvensional yang masih menggunkan peralatan-peralatan mekanik sederhana sedikit demi sedikit memudar. Penggunaan komputer dalam suatu sistem otomasi akan menjadi lebih praktis karena dalam sebuah komputer terdapat milliaran komputasi dalam beberapa milli detik, ringkas karena sebuah PC memiliki ukuran yang relatif kecil dan memberikan fungsi yang lebih baik daripada pengendali mekanis.

1. Elemen dasar sistem otomasi
Terdapat tiga elemen dasar yang menjadi syarat mutlak bagi sistem otomasi, yaitu power, program of instruction, kontrol sistem yang kesemuanya untuk mendukung proses dari sistem otomasi tersebut.
a. Power
Power atau bisa dikatakan sumber energi dari sistem otomasi berfungsi untuk menggerakan semua komponen dari sistem otomasi. Sumber energi bisa menggunakan energi listrik, baterai, ataupun Accu, semuanya tergantung dari tipe sistem otomasi itu sendiri.
b. Program of instruction
Proses kerja dari sistem otomasi mutlak memerlukan sistem kontrol baik menggunakan mekanis, elektronik ataupun komputer. Untuk program instruksi / perintah pada sistem kontrol mekanis maupun rangkaian elektronik tidak menggunakan bahasa pemrograman dalam arti sesungguhnya, karena sifatnya yang analog. Untuk sistem kontrol yang menggunakan komputer dan keluarganya (PLC maupun mikrokontroler) bahasa pemrograman merupakan hal yang wajib ada.
Bahasa pemrograman seperti yang dilukiskan dalam gambar berikut akan memberikan perintah pada manipulator dengan perantara driver sebagai penguat. Perintah seperti “out”, “outport” ,”out32” sebenarnya hanya memberikan perintah untuk sekian millidetik berupa arus pada manipulator yang kemudian akan diperkuat.

Translasi/kompilasi bahasa (seperti Pascal, C, Basic, Fortran), memberi fasilitas pada programer untuk mengimplementasikan program aplikasi. Daerah ini merupakan antarmuka antara pengguna dengan sistem. Translator atau kompiler untuk bahasa pemrograman tertentu akan mengubah statemen-statemen dari pemrogram menjadi informasi yang dapat dimengerti oleh komputer.
Instruksi komputer merupakan antarmuka antara perumusan perangkat lunak program aplikasi dan perangkat keras komputer. Komputer menggunakan instruksi tersebut untuk mendefinisikan urutan operasi yang akan dieksekusi. Penyajian Data membentuk antarmuka antara program aplikasi dan komputer. Daerah irisan dari ketiga lingkaran menyatakan sistem operasi. Sistem operasi ini yang akan mengkoor-dinasi
interaksi program, mengatur kerja dari perangkat lunak dan perangkat keras yang bervariasi, serta operasi dari unit masukan/keluaran.
Komputer merupakan salah satu produk teknologi tinggi yang dapat melakukan hampir semua pekerjaan diberbagai disiplin ilmu, tetapi komputer hanya akan merupakan barang mati tanpa adanya bahasa pemrograman untuk menggambarkan apa yang kita kerjakan, sistem bilangan untuk mendukung komputasi, dan matematika untuk menggambarkan prosedur komputasi yang kita kerjakan.
c. Sistem kontrol
Sistem kontrol merupakan bagian penting dalam sistem otomasi. Apabila suatu sistem otomasi dikatakan layaknya semua organ tubuh manusia seutuhnya maka sistem kontrol merupakan bagian otak / pikiran, yang mengatur dari keseluruhan gerak tubuh. Sistem kontrol dapat tersusun dari komputer, rangkaian elektronik sederhana, peralatan mekanik. Hanya saja penggunaan rangkaian elektronik, perlatan meknik mulai ditinggalkan dan lebih mengedepankan sistem kontrol dengan penggunaan komputer dan keluarganya (PLC, mikrokontroller)
Sistem kontrol sederhana dapat ditemukan dari berbagai macam peralatan yang kita jumpai, diantaranya
- Setiap toilet memiliki mekanisme kontrol untuk mengisi ulang tangki air dengan pengisian sesuai dengan kapasitas dari tangki tersebut. Mekanisme sistem kontrol tersebut menggunakan peralatan mekanis yang disusun sedemikian rupa sehingga membentuk sistem otomasi.
- AC atau air conditioner merupakan sistem otomasi yang menggunakan sistem kontrol mikroelektronik atau yang sering disebut komputer sederhana.
- Robot assembly contoh sistem otomasi yang menggunakan klntrol sistem komputer atau keluarganya. Sistem control tersebut akan memberikan pengaturan pada gerakan-gerakan tertentu untuk menyusun suatu peralatan pada industri.

DOWNLOAD ARTIKEL LENGKAP (PDF):

  1. SISTEM OTOMASI


DOWNLOAD SOFTWARE PENDUKUNG:

  1. Acrobat PDF Reader

Setting Dial Up Internet Menggunakan Operator GSM & CDMA

Dengan banyaknya operator selular baik gsm maupun cdma tentunya memberikan pilihan untuk melakukan koneksi internet. Untuk itu diperlukan setting khusus di pc atau handphone.

1. Telkomsel Flash – Halo/Simpati/As (Waktu)
Dial Up Number : *99***1#
User Name :
Password :
Access Point : FLASH
Extra Setting : at+cgdcont=1,”IP”,”flash”

2. Telkomsel GPRS – Halo/Simpati/As (Data)
Dial Up Number : *99***1#
User Name : wap
Password : wap123
Access Point : TELKOMSEL
Extra Setting : at+cgdcont=1,”IP”,”internet”

3. Indosat – Matrix – (Data)
Dial Up Number : *99***1#
User Name :
Password :
Access Point : www.satelindogprs.com
Extra Setting : at+cgdcont=1,”IP”,” www.satelindogprs.com”

4. Indosat – Mentari – (Data)
Dial Up Number : *99***1#
User Name : indosat
Password : indosat
Access Point : www.satelindogprs.com
Extra Setting : at+cgdcont=1,”IP”,” www.satelindogprs.com”

5. Indosat – IM3 – (Data)
Dial Up Number : *99***1#
User Name : gprs
Password : im3
Access Point : www.indosat-m3.net
Extra Setting : at+cgdcont=1,”IP”,” www.indosat-m3.net”

6. Indosat – IM3 – (Waktu)
Dial Up Number : *99***1#
User Name : indosat@durasi
Password : indosat@durasi
Access Point : www.indosat-m3.net
Extra Setting : at+cgdcont=1,”IP”,” www.indosat-m3.net”

7. XL – Xplor/Bebas/Jempol (Data)
Dial Up Number : *99***1#
User Name : xlgprs
Password : proxl
Access Point : www.xlgprs.net
Extra Setting : at+cgdcont=1,”IP”,” www.xlgprs.net”

8. Telkom Flexi – Classy/Trendy (Data)
Dial Up Number : #777
User Name : telkomnet@flexi
Password : telkom
Access Point :
Extra Setting : at+crm=1
9. Telkom Flexi – Classy/Trendy (Waktu)
Dial Up Number : 080989999
User Name : telkomnet@instan
Password : telkom
Access Point :
Extra Setting : at+crm=0

10. Mobile 8 – Fren
Dial Up Number : #777
User Name : m8
Password : m8
Access Point :
Extra Setting :

11. Starone
Dial Up Number : #777
User Name : starone
Password : indosat
Access Point :
Extra Setting :

12. Esia (Waktu)
Dial Up Number : #777
User Name : esia
Password : esia
Access Point :
Extra Setting :

13. Axis – (Data)
Dial Up Number : *99***1#
User Name : axis
Password : 123456
Access Point : AXIS
Extra Setting : at+cgdcont=1,”IP”,”axis”

14. Three – (Data)
Dial Up Number : *99***1#
User Name : 3gprs
Password : 3gprs
Access Point : 3grps
Extra Setting : at+cgdcont=1,”IP”,”3gprs”

CVI/Labwindows : Alternative bagi pembenci Labview

Bagi anda-anda yang berkecimpung di Control Systems/Instrumentation, pasti kenal dengan program yang satu ini, ya Labview dari National Instruments. Di Perancis sini, hampir semua Industri memakai Labview sebagai bahasa utama pengembangan sistem instrumentasi dan kontrol di industri. Di tingkat universitas dan ecole (institut/sekolah tinggi), setiap mahasiswa Teknik Elektro dan Ilmu Komputer (Informatique) di Perancis diwajibkan untuk mempelajari Labview sebagai bagian dari matakuliah pemrograman, Sistem Kontrol dan Instrumentasi. FYI uniknya di Perancis, mahasiswa Ilmu Komputer atau seringnya disebut Industrielle Informatique disini SELALU mendapatkan mata kuliah Control Systems dan Instrumentation. Sesuatu yang tidak saya temui di UK dan Indonesia. Hal ini disebabkan oleh banyaknya industri manufaktur di Perancis sehingga demand untuk engineer yang menguasai Sistem Kontrol dan Automasi sangat tinggi.

Labview menggunakan konsep Graphics Language sebagai landasan pemrogramannya. So semua operasi logika, iterasi dan matematika direpresentasikan dengan lambang dan flowchart. Labview memang ideal untuk scientist dan engineer yang kurang kuat background programmingnya tapi harus membuat aplikasi measurement dan insrumentasi dengan cepat.

Ok anyway, bagi saya, meskipun sangat tepat untuk data acquisition and measurement, orang Perancis kebablasan menggunakan Labview sebagai bahasa pemrograman general untuk urusan APA SAJA. Bahkan teman saya disuruh menggunakan Labview untuk memodelkan persamaan matematik (dimana Matlab, Mathematica atau Scilab lebih tepat untuk itu).

Labview memaksa kita untuk menggunakan prinsip dataflow, dimana fleksibilitas menjadi taruhannya.

Untuk program-program sederhana seperti akuisisi data dari instrumen, mengukur, dan menampilkannya, graphical programming language ini sangat cepat dan praktis. Tapi untuk menulis program yang cukup kompleks (misal aplikasi Object Detector and Recognition) dibutuhkan fleksibilitas yang sangat tinggi.

Sebagai orang pure Computer Science yang berlatar belakang text based programming dan telah mempelajari Theory of Programming Language dan Compiler Design, saya sangat membenci Labview dengan alasan berikut :

1. Tidak bisa memberi komentar
2. Tidak bisa memberi nama variabel (WTF ??)
3. Nonlinear dan alurnya susah diikuti, ini bikin program atau main game Maze???
4. Untuk memodifikasi satu perintah (dimana dalam bahasa pemrograman text hanya merubah satu baris) harus merubah keseluruhan struktur program.
5. Nonlinearity membuat sangat sulit untuk di-debug.
6. Nonlinearity membuat timing menjadi hal yang sangat sulit.
7. Penanganan Array dan iterasi yang rumit.
9. Sulit untuk menerapkan konsep OOP.
10. Pendukung Labview bilang operasi Parallel lebih mudah divisualisasikan dengan Labview, BULLSHIT, saya membuat parallel program dengan Celoxica Handel-C, tidak ada masalah.

Pertama kali menggunakan Labview untuk aplikasi numerical simulation and modeling (karena perusahaan tidak memiliki Matlab dan bos taunya hanya Labview), saya banyak terbantu dengan memakai C-Script untuk formula programming. Tapi lama-lama setelah aplikasi jadi kompleks, ternyata gabungan Labview dengan C-Script membuat program jadi rumit dan berat.
Akhirnya, setelah berkutat dengan kejengkelan, VOILA saya menemukan solusinya, Paolo, seorang PhD EE asal Brazil yang juga membenci Labview memberitahu pada saya bahwa Labwindows/CVI bisa menggantikan Labview dan kebetulan perusahaan MEMILIKI LISENSI Labwindows/CVI!

Labwindows/CVI adalah ANSI-C Compiler buatan National Instruments yang diklaim pembuatnya dapat menggunakan semua library dan modul akusisi data dari National Instrument dan compatible dengan Labview. So kita bisa mengerjakan aplikasi instrumentasi dan kontrol yang sama dengan Labview tanpa kepusingan-kepusingan bahasa pemrograman grafis.

Akhirnya semua program Labview saya convert ke Labwindows/CVI dan saya bisa meneruskan pekerjaan saya dengan bahasa pemrograman tercinta, ANSI-C !!

Beberapa hari setelah bermain dengan Labwindows/CVI, saya menyadari bahwa development tool ini lebih friendly daripada Visual C++.Net dan tentu saja memiliki library instrumentasi yang sangat lengkap. So Labwindows/CVI adalah tools terbaik untuk aplikasi instrumentasi, kontrol dan measurement di Industry bagi para software engineer atau hardcore coder.

Linux Cross Assemblers

Linux Cross Assemblers


Motorola/Freescale 680X/6811 cross assemblers for Unix/Linux


Masm is a modification of the Motorola DOS freeware assembler that works on UNIX/Linux environments. This assembler package supports the following microprocessors: 6800, 6801, 6804, 6805, 6809, and 68HC11. I have added command line arguments to allow generation of Intel Hex files and a 64K binary image format in addition to the default Motorola S records. A variety of EPROM programmers are thus supported.

Buf is a utility that allows a Unix/Linux machine to download S record files directly to the Buffalo monitor program that is found on the Motorola 6811EVM development board. Buf is distributed under the Gnu GPL license.

The microprocessor break reset circuit below is required for fully automatic operation of buf. The circuit allows buf to reset a running program and jump into the Buffalo monitor program by detecting a break signal on the serial line. This speeds up the code testing cycle and allows the 68HC11 to be in a remote location. This circuit has allowed software to be developed on a microprocessor system that was sitting hundreds of miles away across the internet, connected to a Unix machine’s serial port.

An example 68HC11 assembly language program is included as a useful starting point. This code makes use of the Unix Gnu C preprocessor and #define statements so that both the RAM based BUFFALO version and the EPROM based version can be built from a single assembly language file.

FC’s Tools for working with the 68HC11 under Linux



  • masm.tar.gz Cross assembler source code for 68XX processors

  • buf.tar.gz Linux side software for uploading to the 68HC11 BUFFALO monitor program

  • Break Reset Circuit for hands-free operation of buf/BUFFALO

  • example.asm Example 6811 assembly language program

  • umi Example shell script that runs as11 (masm) and buf


Microprocessor Development Links



Other Utilities



  • gerbv a free Gerber Viewer

  • gEDA GPL’d suite of Electronic Design Automation tools

  • KTechlab development and simulation environment

  • XCircuit schematic drawing package

  • JTAG-O-MAT a simple JTAG interface

  • AsmIDE Assembler development tools for Linux


Microprocessor Manufacturers


Programming the AVR microcontroller with GCC, libc 1.0.4

Programming the AVR microcontroller with GCC, libc 1.0.4


[Illustration]

Abstract:

The AVR 8-Bit RISC microcontroller from Atmel is a very common microcontroller. This microcontroller is one chip with EEPROM, Ram, Analog to Digital converter, a lot of digital input and output lines, timers, UART for RS 232 communication and many other things.

The best is however that a complete programming environment is available under Linux: You can program this microcontroller in C using GCC.

I wrote already in March 2002 an article about the same subject. A lot of things have changed in the avr-libc development and the AT90S4433 microcontroller which I used in 2002 is no longer manufactured by Atmel. This is therefore an update of the March 2002 article. I will use libc-1.0.4 and the ATmega8 microcontroller.

This article shall be only an introduction and in a later series of articles we will again build interesting hardware but this time based on the ATmega8.

_________________ _________________ _________________


Introduction


Many people where interested in microcontroller programming after the article which I wrote in 2002. However this first step to get the development environment up and running is the hardest. If something does not work then you have absolutely no clue where the fault is. Programmer cable wrong?? Circuit faulty? Installation incorrect? Parallelport disabled in bios? Kernel modules for ppdev compiled wrong? There can be a lot of reasons why things don’t work.

To make the entrance to the exciting world of microcontrollers easier shop.tuxgraphics.org offers now a bootable CD with a manual and the programmer hardware. All you need to do then is boot from this CD and everything is up and running. No software installation is required and nothing is modified on your local computer.

Even I use such a CD now for a while because the hardware I build often survives several generations of kernels and software installations on my PC. If I want later on to update some microcontroller software then I do not have to worry if the development environment on my Linux PC is still working. I just boot from the CD and it is up and running.

Independent of this CD I will explain the installation of the GCC avr development environment in the following paragraphs. If you have the CD from tuxgraphics then continue with chapter “A small test project”.

Software installation: What you need


To use the GNU C development environment you need the following software:



















binutils-2.15.tar.bz2Available from:
ftp://ftp.gnu.org/gnu/binutils/
or any mirror. E.g:
ftp://gatekeeper.dec.com/pub/GNU/binutils/
gcc-core-3.4.2.tar.bz2Available from: ftp://ftp.gnu.org/gnu/gcc/
or any mirror. E.g:
ftp://gatekeeper.dec.com/pub/GNU/gcc/
avr-libc-1.0.4.tar.bz2The AVR C-library is available from: http://savannah.nongnu.org/projects/avr-libc/
uisp-20040311.tar.bz2The AVR programmer software is available from: http://savannah.nongnu.org/projects/uisp

We will install all the programs to /usr/local/avr. This is to keep the program separate from your normal Linux C compiler. Create this directory with the command:
    mkdir /usr/local/avr

You can add it already now to your PATH:
mkdir /usr/local/avr/bin
export PATH=/usr/local/avr/bin:${PATH}


Software installation: GNU binutils


The binutils package provides all the low-level utilities needed for building object files. It includes an AVR assembler (avr-as), linker (avr-ld), library handling tools (avr-ranlib, avr-ar), programs to generate object files loadable to the microcontroller’s EEPROM (avr-objcopy), disassembler (avr-objdump) and utilities such as avr-strip and avr-size.

Run the following commands to build and install the binutils :
tar jxvf binutils-2.15.tar.bz2
cd binutils-2.15/
mkdir obj-avr
cd obj-avr
../configure --target=avr --prefix=/usr/local/avr --disable-nls
make

# as root:
make install

Add the line /usr/local/avr/lib to the file /etc/ld.so.conf and run the command /sbin/ldconfig to rebuild the linker cache.

Software installation: AVR gcc


avr-gcc will be our C compiler.

Run the following command to build and install it:
tar jxvf gcc-core-3.4.2.tar.bz2
cd gcc-3.4.2

mkdir obj-avr
cd obj-avr
../configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-language=c

make

# as root:
make install


Software installation: The AVR C-library


The C-library is quite stable now compared to the one I presented in March 2002.
Run the following command to build and install it:
tar jxvf avr-libc-1.0.4.tar.bz2
cd avr-libc-1.0.4
PREFIX=/usr/local/avr
export PREFIX
sh -x ./doconf
./domake

cd build
#as root:
make install


Software installation: The Programmer


The programmer software loads the specially prepared object code into the EEPROM of our microcontroller.

The uisp programmer for Linux is a very good programmer. It can be used directly from within a Makefile. You just add a “make load” rule and you can compile and load the software in one go.

uisp is installed as follows:
tar jxvf uisp-20040311.tar.bz2.tar
cd uisp-20040311
./configure --prefix=/usr/local/avr
make

# as root:
make install


A small test project


We will start with a small test circuit which you can expand later on.

This circuit can also be used as a simple test environment for more complex hardware. You can easily test load software and attach sensors or measurement equipment.

Our test program as presented here will just cause a LED to blink.


Needed Hardware


[test circuit]
You need the parts listed in the table below. Although it is a very common microcontroller it might not be available in every local radio shop but bigger distributors for electronic components like ( www.conrad.de (germany), www.selectronic.fr (france), digikey.com (US, CA), etc… have it in store).
The best place to get the microcontroller and the other parts is however: shop.tuxgraphics.org ;-) .















1 x ATmega8 DIP version, Atmel 8 bit Avr risc processor.
1 x 28 pin 7.5mm IC socket
The 28 pin socket is a bit more difficult to get. Usually the 28 sockets are 14mm wide but we need a 7.5mm socket.
1 x 10K resistor (color code: brown,black,orange)
1 x 1K resistor (color code: brown,black,red)
1 x 10uF electrolytic capacitor
Some wires
1 x LED
matrix board
The following is needed for the programmer (not needed if you get the “Linux AVR programming kit” from tuxgraphics):
1 x DB25 connector to plug into the parallel port.
Any kind of 5 pin connector/socket for the programmer. I recommend to use precision strip connectors (similar to IC sockets) and break 5 pins off.
1 x 220 Ohm resistor (color code: red,red,brown)
2 x 470 Ohm resistor (color code: yellow,purple,brown)

In addition to the above parts you need a 5V electronically stabilized DC power supply or you can use a 4.5V battery as power supply.

You have probably noticed that we do not need a crystal. This is because the ATmega8 has now a build-in oscilator. This oscilator can be used when accurate timing is not an issue. However if you want to build precise measurement equipment or you want to use the UART/RS232 interface then you will need a crystal. Which type of oscilator is used can be defined via fuse bits which you can modify with the programmer. By default (factory setting) the internal 1Mhz oscilator is active.

Building the programmer hardware


The AVR microcontrollers allows for in circuit programming (ISP). [Linux AVR programmer]
That is: you do not need to remove the microcontroller form the board to program it. You will see that you can get different programmer hardware from 50-150 Euro. However with Linux running it is also possible to build a very simple programmer that does the job. You need a free parallel port on your computer and the following cable.

Note that this is an improved programmer compared to the one presented in the March 2002 article. We build the protection resistors into the programmer. This will then save some space and parts on the circuit board. The wiring for the programmer cable has to be as follows:







































pin on pcbpin on AVRprotection resistorPin on parallel port
5Reset (1)Init (16)
4MOSI (17)470 OhmD0 (2)
3MISO (18)220 OhmBusy (11)
2SCK (19)470 OhmStrobe (1)
1GNDGND (18)

The cable should not be longer than 70cm.

The protection resistors can be build into the connector as show on the picture on the right.

Writing software


The Atmeag 8 can be programmed in plain C with the help of gcc. To know some AVR assembler can be useful but it is not needed.

The AVR libc comes with an avr-libc-user-manual-1.0.4.pdf (1139921 bytes) which documents all functions available in C. From Atmel’s website, (www.atmel.com, go to: avr products -> 8 bit risc-> Datasheets), you can download the complete data sheet. It describes all the registers and how to use the CPU.

One thing to keep in mind when using a microcontroller is that it has only a few bytes of Ram. That means you must not declare large data structures or strings. Your program should not use deeply nested function calls or recursion.

Much better than all theory is a real example. We will write a program that causes our LED to blink in 0.5 seconds intervals. Not very useful but very good to get started.

The avr-libc has changed a lot. Previously you did set a bit on a port with sbi and you cleared it with cbi. Now those functions are deprecated. First I present the “good old way”:
    /* defines for future compatibility */
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void main(void)
{
/* INITIALIZE */
/* enable PC5 as output */
sbi(DDRC,PC5);

/* BLINK, BLINK ... */
while (1) {
/* led on, pin=0 */
cbi(PORTC,PC5);
delay_ms(500);
/* set output to 5V, LED off */
sbi(PORTC,PC5);
delay_ms(500);
}
}

The following example does exactly the same but uses the new syntax:
    void main(void)
{
/* INITIALIZE */
/* enable PC5 as output */
DDRC|= _BV(PC5);

/* BLINK, BLINK ... */

/* PC5 is 5 (see file include/avr/iom8.h) and _BV(PC5) is 00100000 */
while (1) {
/* led on, pin=0 */
PORTC&= ~_BV(PC5);
delay_ms(500);
/* set output to 5V, LED off */
PORTC|= _BV(PC5);
delay_ms(500);
}
}

The above code snipet shows how simple it is to write a program. You see only the main program, the delay_ms function is included in the full listing (avrm8ledtest.c). To use pin PC5 as output you need to set the PC5 bit in the data direction register for port C (DDRC). After that you can set PC5 to 0V with the function cbi(PORTC,PC5) (clear bit PC5) or to 5V with sbi(PORTC,PC5) (set bit PC5). The value of “PC5″ is defined in iom8.h which is included via io.h. You don’t have to worry about it. If you have already written programs for multi user / multi tasking systems such as Linux you know that one must never program a non blocking endless loop. This would be a waste of CPU time and slow the system very much down. In the case of the AVR this is different. We don’t have several tasks and there is no other program running. There is not even an operating system. It is therefore quite normal to busy loop forever.

Compiling and loading


Before you start make sure that you have /usr/local/avr/bin in the PATH. If needed edit your .bash_profile or .tcshrc and add:

export PATH=/usr/local/avr/bin:${PATH} (for bash)
setenv PATH /usr/local/atmel/bin:${PATH} (for tcsh)

We use the parallel port and uisp to program the AVR. Uisp uses the ppdev interface of the kernel. Therefore you need to have the following kernel modules loaded:
    # /sbin/lsmod
parport_pc
ppdev
parport

Check with the command /sbin/lsmod that they are loaded otherwise load them (as root) with:
    modprobe parport
modprobe parport_pc
modprobe ppdev

It is a good idea to execute these commands automatically during startup. You can add them to a rc script (e.g for Redhat /etc/rc.d/rc.local).
To use the ppdev interface as normal user root needs to give you write access by once running the command

chmod 666 /dev/parport0

Make as well sure that no printer daemon is running on the parallel port. If you have one running then stop it before you connect the programmer cable. Now everything is ready to compile and program our microcontroller.

The package for our test program (avrm8ledtest-0.1.tar.gz) includes a make file. All you need to do is type:

make
make load

This will compile and load the software. I will not go into the details of all the commands. You can see them in the Makefile and they are always the same. I can my self not remember all of them. I just know that I need to use “make load”. If you want to write a different program then just replace all occurrences of avrm8ledtest in the Makefile with the name of your program.

Some interesting binutils


More interesting than the actual compilation process are some of the binutils.
Those utilities have however not really changed since March 2002. Take a look at the “Some interesting binutils” chapter in article231, March 2002.

Ideas and suggestions


The ATmega8 is compatible to the AT90S4433 for most uses. You need to program the fuse bits to use the external oscilator and the previously presented hardware might work with possibly minor changes. Unfortunatley I have not had time yet to re-test all circuits for the ATmega8. If you want to be on the save side then use the AT90S4433 for the old articles. If you don’t mind to troubleshoot and solve problems then try the ATmega8 with the old articles/circuits.

Here is a list of those previous hardware articles:

Note: the programmer presented here includes already the protection resistors which were build into the circuit board in the older hardware articles. To use the new programmer with the old boards you will just need to replace the protection resistors on the board by wires.

Atmel provides an application note “AVR081: Replacing AT90S4433 by ATmega8″ which lists all the incompatibilities: at90s4433_to_atmega8.pdf (101343 bytes)

References


Pengantar Embedded Systems

Apakah embedded system itu ?

Embedded system adalah kombinasi dari hardware dan software yang disisipkan (embedded) dalam suatu perangkat tertentu yang bertujuan melakukan suatu fungsi/tugas khusus.

Contoh dari embedded systems ini dalam kehidupan sehari-hari adalah microwave, kalkulator elektronic, game watch, Antilock Brake Systems dan masih banyak lagi.

Hampir semua aspek kehidupan kita tidak dapat dipisahkan dari embedded systems.

Coba anda lihat sekeliling kamar anda, pastinya anda tidak akan sulit menemukan suatu benda yang mengandung embedded systems di dalamnya.

Coba sebutkan, di kamar saya saja sekarang ada Mobile Phone, MP3 Player dan MIDI Keyboard. Embedded systems banyak dikaitkan dengan Real-Time Systems (sistem waktu nyata).

Kebanyakan Embedded system memang memiliki sistem operasi berbasis real-time systems, kenapa ?

karena kita tidak ingin ada jeda waktu eksekusi dalam sistem embedded systems. Embedded system juga banyak dikaitkan dengan Instrumentasi. Karena untuk membuat instrument, kita menghubungkan (antarmuka/interface) antara prosesor dengan dunia luar melalui sensor.

Saturday, May 28, 2011

Atmega32 dan RS-232

Sebuah mikrokontroller tentu saja perlu berkomunikasi dengan dunia luar, misalnya dengan PC. Interface yang populer untuk keperluan ini adalah Serial Port RS-232. Untuk melengkapi serial port RS-232 ke mikrokontroller atmega anda, gunakan IC TTL to RS232 converter, yang dikeluarkan oleh Maxim MAX232, atau ICL232. Rangkaiannya:


Di sisi PC, anda dapat menggunakan software Hyperterminal yang terdapat di Accessories, atau, apabila ingin yang lebih bagus, gunakan software Docklight (www.docklight.de). Atau, jika anda mau membuat aplikasi under Delphi yang membaca port serial, gunakan komponen cport yg bisa di download di http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/c/co/comport/


Software di avr-gcc untuk mengakses port serial ini adalah.

#include < avr/io.h>
#include < avr/interrupt.h>
#include < inttypes.h>
#include < avr/iom32.h>
#include < stdio.h>
#include < math.h>
#include < avr/pgmspace.h>
#include < avr/eeprom.h>
#include < avr/wdt.h>

#define F_OSC 11059200
#define UART_BAUD_RATE 9600
#define UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) ((F_OSC)/((UART_BAUD_RATE)*16l)-1)

volatile unsigned char ser[22]; // variabel buffer serial rx

SIGNAL (SIG_UART_RECV)
{
unsigned char c;
unsigned char a;

c = UDR;

for(a=0;a<21;a++) ser[a]=ser[a+1];
ser[21]=c;
}


void usart_putc(unsigned char c) // kirim ke serial 1 char
{
while(!(UCSRA & (1 << UDRE)));
UDR = c;
}

void usart_puts (char *s) // kirim ke serial 1 string
{
while (*s)
{
usart_putc(*s);
s++;
}
}

int main(void)
{
DDRD=0xfe;

UBRRH = (unsigned char)(UART_BAUD_CALC(UART_BAUD_RATE,F_OSC) >> 8);
UBRRL = (unsigned char)UART_BAUD_CALC(UART_BAUD_RATE,F_OSC);
UCSRB = (1 << RXEN)|(1 << TXEN)|(1 << RXCIE);
UCSRC = (1 << URSEL)|(3 << UCSZ0);

while (1)
{
usart_puts(“Serial ready\r\n”);
}
}

Keterangan source code:

1. Setiap kali RX menerima data, maka data tersebut disimpan di variabel ser[21], data sebelumnya bergeser. Lihat fungsi interupsi serial SIGNAL (SIG_UART_RECEIVE)
2. Untuk mengirim 1 karakter ke TX, gunakan fungsi usart_putc();
3. Untuk mengirim 1 string ke TX, gunakan fungsi usart_puts();
4. Setting baud date di #define UART_BAUD_RATE 9600

Mendapatkan second serial di ATMEGA32 (Soft UART)

Apabila dibutuhkan lebih dari 1 serial port, maka bisa menggunakan softuart, yaitu uart yang dibuat oleh software. pin untuk TX dan RX adalah:

TX : Pin 19 (OC1A)
RX : Pin 20 (ICP1)

Sedangkan source codenya adalah:

#include < avr/io.h>
#include < avr/interrupt.h>
#include < inttypes.h>
#include < avr/iom32.h>
#include < stdio.h>
#include < math.h>
#include < avr/pgmspace.h>
#include < avr/eeprom.h>
#include < avr/wdt.h>

#define F_OSC 11059200
#define SOFT_BAUD 9600 // Software uart baud rate

#define BIT_TIME (unsigned short)((F_OSC + SOFT_BAUD/2) / SOFT_BAUD)
#define kbhit() (srx_done)

volatile unsigned char stx_count;
unsigned char stx_data;

volatile unsigned char srx_done;
unsigned char srx_data;
unsigned char srx_mask;
unsigned char srx_tmp;

SIGNAL( SIG_INPUT_CAPTURE1 )
{
OCR1B = ICR1 + (unsigned short)(BIT_TIME * 1.5);
srx_tmp = 0;
srx_mask = 1;
TIFR = 1 << OCF1B;
if( !(SRXPIN & 1 << SRX))
TIMSK = 1 << OCIE1A^1 << OCIE1B;
}

SIGNAL( SIG_OUTPUT_COMPARE1B )
{
unsigned char in = SRXPIN;

if( srx_mask )
{
if( in & 1 << SRX )
srx_tmp |= srx_mask;
srx_mask << = 1;
OCR1B += BIT_TIME;
}
else
{
srx_done = 1;
srx_data = srx_tmp;
TIFR = 1 << ICF1;
TIMSK = 1 << TICIE1^1 << OCIE1A;
}
}

SIGNAL( SIG_OUTPUT_COMPARE1A )
{
unsigned char dout;
unsigned char count;

OCR1A += BIT_TIME;
count = stx_count;

if( count )
{
stx_count = --count;
dout = 1 << COM1A1;
if( count != 9 )
{
if( !(stx_data & 1) )
dout = 1 << COM1A1^1 << COM1A0;
stx_data >>= 1;
}
TCCR1A = dout;
}
}

void suart_init( void )
{
OCR1A = TCNT1 + 1;
TCCR1A = 1 << COM1A1^1 << COM1A0;
TCCR1B = 1 << ICNC1^1 << CS10;

TIFR = 1 << ICF1;
TIMSK = 1 << TICIE1^1 << OCIE1A;

stx_count = 0;
srx_done = 0;
STXDDR |= 1 << STX;
}

unsigned char sgetchar( void )
{
while( !srx_done );
srx_done = 0;
return srx_data;
}

void sputchar( unsigned char val )
{
while( stx_count );
stx_data = ~val;
stx_count = 10;
}

void sputs( char *txt )
{
while( *txt )
sputchar( *txt++ );
}

int main(void)
{
DDRD=0xbe;

while (1)
{
sputs(“Kirim string\r\n”);
}
}

Keterangan source code:
1. Untuk mengirimkan string, gunakan sputs();
2. Untuk mengirimkan 1 karakter, gunakan sputchar();
3. Untuk menerima data dari serial, cek dahulu apakah ada data baru dengan kbhit(), jika true berarti ada data masuk, ambil data dengan fungsi sgetchar();
4. Untuk softuart tidak ada fasilitas interupsi.

Friday, May 27, 2011

Simple calculator using avr microcontroller

Here's a simple calculator with the Atmega16 microcontroller. It have an LCD display and a 4x4 keypad.

You can also download the proteus simulation file on the downloads


Bascom Code


$regfile = "m16def.dat"
$crystal = 1000000

Config Kbd = Portd , Debounce = 30
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , Rs = Portb.3 , E = Portb.2

Dim A As Byte
Dim B As Byte
Dim Key As Byte
Dim C As Byte
Dim D As Byte
Dim E As Byte
Dim F As Byte

Cls
Cursor Off
Locate 2 , 1
Lcd "avrprojects.info"
E = 0
B = 0

Q:
Waitms 200
'B = 0
A = Getkbd()
If A > 15 Then
Goto Q
Else
Key = Lookup(a , Dta)
If Key <= 9 Then
D = 0
B = 10 * B
B = B + Key
If E = 0 Then C = B
If E = 1 Then D = B
Cls : Lcd B
Elseif Key = 10 Then
Cls
F = 1
E = 1
B = 0
Elseif Key = 11 Then
Cls
E = 1
F = 2
B = 0
Elseif Key = 12 Then
Cls
E = 1
F = 3
B = 0
Elseif Key = 15 Then
Cls
E = 1
F = 4
B = 0
Elseif Key = 13 Then
Cls
E = 0
B = 0
Elseif Key = 14 Then
If E = 1 Then
Cls
Select Case F
Case 1 :
B = C / D
Case 2:
B = C * D
Case 3:
B = C - D
Case 4:
B = C + D
End Select
Lcd B

End If
End If
End If
Locate 2 , 1
Lcd "avrprojects.info"

Goto Q
End
Dta:
Data 7 , 8 , 9 , 10 , 4 , 5 , 6 , 11 , 1 , 2 , 3 , 12 , 13 , 0 , 14 , 15

http://www.avrprojects.info/avr-projects/simple-calculator-using-avr-microcontroller/

Stepper motor Control with Atmega16

Bascom Code

$regfile = "m16def.dat"
$crystal = 1000000

Config Kbd = Portb
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , Rs = Portc.0 , E = Portc.1
Config Portd = Output
Config Porta = Input

Dim A As Byte , B As Byte , Key As Byte , C As Byte , D As Byte , E As Byte

Cls
Cursor Off

B = 0
D = 1

Q:
Locate 1 , 1
Lcd "Direction:"
Locate 2 , 1
Lcd "Speed:"
Do
'************Read Keyboard
A = Getkbd()
If A > 15 Then
Goto Q
Else
Key = Lookup(a , Dta)
If Key <= 9 Then
B = B * 10
B = B + Key
'*************Direction
If D = 0 Then Lcd B
Waitms 270
Elseif Key = 10 Then
Locate 1 , 11
Lcd "Left"
C = 1
D = 0
B = 0

Elseif Key = 11 Then
Locate 1 , 11
Lcd "Right"
C = 2
D = 0
B = 0
'****************reset
Elseif Key = 13 Then
Cls
D = 1
B = 0
Portd.0 = 0
Portd.1 = 0
Waitms 50
Goto Q
'****************Enter key
Elseif Key = 14 Then
If D = 0 Then
Select Case C
Case 1 : Gosub R
Case 2 : Gosub T
End Select

End If
End If

End If

Wait 1

Loop

End

Dta:
Data 7 , 8 , 9 , 10 , 4 , 5 , 6 , 11 , 1 , 2 , 3 , 12 , 13 , 0 , 14 , 15

R:
Do
Portd = &B00000001 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001001 : Waitms B
If Pina.0 = 1 Then
Locate 2 , 1
Lcd "Speed:"
B = 0
Lcd B ; " "
Return
End If

Loop

T:
Do
Portd = &B00001001 : Waitms B
Portd = &B00001000 : Waitms B
Portd = &B00001100 : Waitms B
Portd = &B00000100 : Waitms B
Portd = &B00000110 : Waitms B
Portd = &B00000010 : Waitms B
Portd = &B00000011 : Waitms B
Portd = &B00000001 : Waitms B
If Pina.0 = 1 Then
Locate 2 , 1
Lcd "Speed:"
B = 0
Lcd B ; " "
Return
End If

Loop

Wednesday, May 25, 2011

Bascom and AVR, Strings

Strings are a type of variable where space is reserved for a series (string) of character. It is typically used when we want to input/output text or long numbers. A string is dimensioned as:
Dim Usermessage as String*10

Usermessage can hold a text of 10 characters. Each character takes a storage space of one byte. Bascom will add an extra byte with value 'null' to signal the end of the string. The maximum length of a string is 254 characters (exluding the 'null' byte).

Bascom has a large repertoire for string handling:




Bin  Converts a bytevalue to a binary string

Example:
Dim Portstate as String*8
PortD= 152
Portstate = Bin(PortD)
'Portstate = "10011000"





Format  Format Inpstring according to format string

Example:
Dim Inpstring as String*6
Dim Pstring as String*6
Inpstring = "38.869"
Pstring = Format(Inpstring, "+000.00")
'Pstring = "+038.86"





Fusing  Format a single variable according to a format string, do rounding if necessary

Example:
Dim Xval as Single
Dim Pstring as String*4
Xval = 16.379
Pstring = Fusing(Xval, "format")
Pstring = "16.4"





Hex  Convert a hex number to a string

Example:
Dim Hval as Integer
Hval = 12345
Pstring = Hex(Hval)
'Pstring = "3039"





Hexval  Convert a hex string to a number

Example:
Dim Dval as Integer
Dim Instring as String*2
Instring = "10"
Dval = Hexval(Instring)
'Dval = 16





Instr  Determine the position of a substring in a string

Example:
Dim Complstring as String*13
Dim Substring as String*6
Dim Pval as Integer
Complstring = "bascom course"
Substring = "course"
Pval = Instr(Complstring, Substring)
'Pval = 8





Lcase  Convert a string to all lower case

Example:
Dim Instring as String*13
Dim Lowstring as String*13
Instring = "Bascom Course"
Lowstring = Lcase(Instring)
'Lowstring = "bascom course"





Left  Get the left part of a string

Example:
Dim Instring as String*13
Dim Leftstring as String*3
Dim Pval as Integer
Instring = "Bascom Cursus"
Pval = 3
Leftstring = Left(Instring, Pval)
'Leftstring = "Bas"





Len Get the length of the string

Example:
Dim Instring as String*20
Dim Lval as Integer
Instring = "Bascom tasks"
Lval = Len(Instring)
'Lval = 12





Ltrim  Remove leading spaces from a string

Example:
Dim Instring as String*10
Dim Pstring as String*10
Instring = " course"
Pstring = Ltrim(Instring)
Pstring = "course"





Mid  Get the middle part of a string [FUNCTION]

Example:
Dim Instring as String*13
Dim Pstring as String*3
Dim Sval as Integer
Dim Nval as Integer
Instring = "Bascom Course"
Sval = 4
Nval = 3
Pstring = Mid(Instring, Sval, Nval)
'Pstring = "com"





Mid Replace a substring in a string [ROUTINE]

Example:
Dim Instring as String*13
Dim Pstring as String*3
Instring = "Bascom is not easy"
Pstring = "very"
Sval = 10
Pval = 4
Mid(Pstring, Sval, Nval) = Instring
'Instring = "Bascom is very easy"





Right  Get the right part of a string

Example:
Dim Instring as String*13
Dim Rightstring as String*3
Dim Pval as Integer
Instring = "Bascom Course"
Pval = 3
Rightstring = Right(Instring, Nval)
'Rightstring = "rse"





Rtrim  Remove trailing spaces from a string

Example:
Dim Instring as String*10
Dim Pstring as String*10
Instring = " course "
Pstring = Rtrim(Instring)
'Pstring = " course"





Space  Make a string of spaces

Example:
Dim Pstring as String*10
Dim Nval as Integer
Nval = 4
Pstring = Space(Nval)
'Pstring = " "





Str  Convert a number to a string

Example:
Dim Pstring as String*10
Dim Varval as Integer
Varval = 15436
Pstring = Str(Varval)
'Pstring = "15436"





String  Make a string by repeating characters

Example:
Dim Pstring as String*10
Dim Nchar as Integer
Dim Charcode as Byte
Nchar = 6
Charcode = 88
Pstring = String(Nchar, Charcode)
'Pstring = "XXXXX"





Trim Remove leading and trailing spaces from a string

Example:
Dim Instring as String*10
Dim Pstring as String*10
Instring = " course "
Pstring = Trim(Instring)
'Pstring = "course"





Ucase  Convert a string to all upper case

Example:
Dim Instring as String*13
Dim Upstring as String*13
Instring = "Bascom Course"
Upstring = Ucase(Instring)
'Upstring = "BASCOM COURSE"





Val  Convert a string to a number

Example:
Dim Instring as String*10
Dim Varval as Integer
Instring = " 781"
Varval = Val(Instring)
'Varval = 781

Terima data serial dengan URXC Interrupt BASCOM-AVR

Beberapa metode (function) penerimaan data serial UART telah disediakan oleh BASCOM-AVR. Salah satu metode penerimaan data serial yang patut anda coba adalah dengan menggunakan Interupsi URXC pada uC AVR yaitu interupsi yang terjadi ketika register UDR terisi oleh satu byte data. Kali ini compiler yang akan kita gunakan adalah BASCOM-AVR.

Berikut adalah contoh program untuk penerimaan data serial dengan URXC Interrupt.


$regfile = "m16def.dat"
$crystal = 4000000
$baud = 9600

Enable urxc
Enable Interrupts
On urxc urxc_isr
Dim x as byte
Dim y as String * 20
Dim z as String * 20
Dim complete as Bit

y = ""
complete = 0

Do
If complete = 1 then
'Lakukan sesuatu dengan / terhadap data serial yang diterima (variabel z)
complete = 0
End if
Loop
End

urxc_isr:
x = UDR
If x <> 13 then
If x <> 10 and x <> 0 then
y = y + chr(x)
End if
Else
z = y
complete = 1
y = ""
End if
Return
Return


Friday, May 13, 2011

Sensor TAOS TCS3200

sensor warna berbasis sensor TAOS TCS3200 yang dapat digunakan untuk pengukuran komponen RGB sebuah obyek. DT-SENSE Color Sensor dilengkapi kemampuan untuk menyimpan 25 data warna serta 2 pilihan antarmuka yaitu UART TTL dan I2C. Modul ini dapat digunakan untuk aplikasi sistem sortir warna atau color recognition.



Dimensi modul DT-SENSE Color Sensor:

  • tanpa spacer : 4,8 cm (p) x 4,8 cm (l) x 2,8 cm (t).

  • dengan spacer : 4,8 cm (p) x 4,8 cm (l) x 4,6 cm (t).


Spesifikasi DT-SENSE Color Sensor:

  • Berbasis sensor TAOS TCS3200D.

  • Mampu mengukur komponen warna RGB dari sebuah obyek berwarna.

  • Dilengkapi dengan spacer 3 cm sehingga mencakup area pandang (field of view) 2 cm x 2 cm.

  • Tersedia 2 LED putih untuk membantu pembacaan data warna pada obyek.

  • Tersedia fitur penyimpanan 25 buah data warna.

  • Pin input/output kompatibel dengan level TTL/CMOS.

  • Dilengkapi dengan antarmuka UART TTL dan I2C.

  • Konfigurasi komunikasi serial adalah : baudrate 9600 bps, 8 data bit, 1 stop bit, tanpa parity, dan tanpa flow control.

  • Antarmuka I2C mendukung bit rate data hingga 50 kHz.

  • Pada antamuka I2C modul ini dapat di-cascadehing

    • ga 8 modul tanpa hardware tambahan.

    • Pengaturan alamat hardware I2C melalui pengaturan jumper.

    • Tersedia perintah white balance untuk membaca referensi warna putih dan black balance untuk membaca nilai referensi warna hitam melalui command set.

    • Kebutuhan catu daya 4,8 - 5,4 VDC.

    • Tersedia deskripsi dan penjelasan command set yang didukung oleh modul ini.

    • Tersedia contoh program uji untuk antarmuka I2C.





ManualSensorTAOSTCS3200ColorSensor.pdf

Sensor TAOS TCS3200

Contoh Source Code Bascom :
SensorTAOSTCS3200ColorSensor.zip