mikrokontroller : belajar dari nol
MIKROKONROLLER
Pertanyaan yang sering muncul begitu mendengar kata mikrokontroller ialah,
Apa bedanya dengan microprocessor ?
Jawaban simplenya, mikrokontroller lebih lengkap. Karena memiliki fitur tambahan terutama input-output, tapi kapasitas memori yang terbatas 8K atau 16K. Sedangkan microprocessor memorinya besar tapi tidak memiliki fitur input output, jadi kalau mau dipake harus menambah banyak ic. Oleh karena itu mikrokontroller lebih sering digunakan untuk proyek system embedded dan microprocessor digunakan pada PC computer, karena harus mengolah banyak data.
Kapan harus pakai mikrokontroller ?
Ketika semua rangkaian analog dan IC (Integrated Circuit) tak mampu lagi menangani tujuan circuit yang kita mau. Atau rangkaian analog terlalu rumit, jadi jauh lebih mudah menggunakan mikrokontroller.
Ada banyak jenis mikrokontroller. Tiap jenis namanya beda bergantung dari pabriknya, system pengoperasiannya pun beda, fiturnya juga beda-beda. Cara terbaik untuk mengenal mikrokontroller yang digunakan ialah dengan membaca datasheet. Walaupun tiap mikrokontroller berbeda tapi ada satu kunci untuk mengetahui semuanya. Di modul ini akan diberikan konsep itu.
ANTARMUKA
Atau disebut juga Interface merupakan bagian penting yang harus dipelajari. Ini seperti -Hubungan Luar Negri- buat mikrokontroller (atau device lain). Akan ada banyak protocol, sama seperti kalau mau keluar negri ga bisa langsung terbang naik pesawat, tapi harus buat passport dulu, ngisi prosedur pembuatan passport dan visa, prosedurnya pun beda-beda tergantung negara dan juga tujuan kesana. Nah, sama halnya dengan antarmuka computer, mikrokontroller.
Kalau dari computer ada tipe parallel, serial (RS232), dan USB. Paralel : lebih mudah prosedurnya hanya saja tidak bisa jarak jauh (panjang kabel terbatas), Serial : bisa lebih panjang dari parallel hanya saja perlu program tambahan, dan transfer datanya lebih lambat dari parallel (soalnya ngantri), USB : paling susah secara hardware dan juga software (atau beli USB to serial). Di modul ini akan dibahas ketiganya, tapi akan lebih fokus ke serial.
Kenapa harus AVR?
Karena dulu saya stuck dengan mcs (pas download programnya gagal terus, semaleman-full- Cuma berusaha untuk masukin program- tapi tetep, kadang berhasil tapi lebih banyak gagalnya). Padahal sampai kulitnya aja belum udah kena trouble, gimana mau nambah ilmu kalo kayak gitu.
Yang kedua karena ikutan lomba, Nah, saya dapat contoh programnya (dari internet) kebanyakan pake mikrokontroller AVR, jadi ‘terpaksa’ pake AVR. Tapi emang sekarang-sekarang ini orang lebih banyak menggunakan AVR. Karena keadaan tersebut mulailah saya belajar otodidak,di lab ku susah lho nyari bahan belajar mikro AVR (dibanding MCS).
Dan ternyata setelah saya pelajari AVR tuh menyenangkan (lebih mudah dan powerfull), fiturnya banyak lagi. cek aja datasheetnya. yang paling sering saya pake tuh ADC bisa sampai 10 bit lagih. udah gitu ngeprogramnya gampang dan cepet.
REGISTER
Dalam mikrokontroller ada yang disebut register. Ada banyak sekali register, jadi lumayan capek juga kalo dibahas semua. Register bisa juga dibayangkan sebagai kota dalam suatu Negara, tiap kota punya ciri khas dan hasil bumi masing-masing, kalau mau ke kota A pasti jalannya beda dengan ke kota B.
Nah analogi diatas, kalau di mikro kota sebagai register (ada banyak tipe-ada ADC, USART,dll) dan jalan untuk menuju kekota tertentu disamakan dengan cara kita mengakses register tersebut. karena banyak banget jadi ga akan dibahas semua, cukup satu aja (konsepnya jadi tar bisa ngerti semua register, syaratnya punya datasheet lengkapnya).
Contoh
Misalkan kita mau pake fitur ADC dalam mikro ATMega8535, caranya……
Rule number one. Coba dilihat daftar isi pada datasheet tentang ADC, langsung lompat ke register-register penyusun ADC, yaitu ADMUX, ADCSRA, ADCHdanADCL, dan satu register lagi SFIOR. Ga perlu bingung dengan namanya biasanya itu singkatan, missal ADMUX (ADC Multiplexer Selection Register), ga perlu hafal kok (apa gunanya datasheet klo hrs hafal)
Secara singkat ini fungsi masing-masing register :
ADMUX = setting ADC, mulai dari clock, tegangan refrensi, pin, dll
ADCSRA = settingan untuk, kapan harus mulai mengaktifkan ADC
ADCH/L = ini untuk tempat menampung data
SFIOR = menentukan trigger ADC
Tiap register diatas terdiri dari 8 bit, masing-masing bit merepresentasikan hal yang berbeda, seperti contoh untuk register ADMUX ini
……trouble……
Pada register ADMUX, untuk bit ke 6 dan 7 merupakan setingan untuk pengambilan tegangan referensi untuk ADC (klo masih bingung sama ADC coba buka modul praktikum system instrumentasi). Bit yang lain? (liat sendiri didatasheet )
Kayaknya capek yak klo liat datasheet terus, pengen gampang pake aja CodeWizard. Dalam Codewizard sudah ada cara setting ADC (tinggal klik-klik), langsung deh jadi programnya, kayak gini.
// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: Free Running
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0xA4;
SFIOR&=0x0F;
Tapi kita tetep perlu datasheet, karena ada beberapa perhitungan (biasanya clock), dan yang paling penting gimana fungsi itu bekerja (dalam hal ini ADC) –register mana dulu yang harus di set atau yang harus ditunggu-, sangat penting saat pembuatan program.
Jadi secara garis besar kalau mau kenal sama mikro(apapun jenisnya) ini gambarannya.
—–troublee———
Setiap jenis mikro punya karakteristik yang berbeda, jadi sangat penting untuk memiliki datasheetnya, emang sih agak kurang enak dibaca tapi itu penting!!!!
Dan satu lagi compilernya juga pasti beda-beda, bahkan satu jenis mikro bisa punya banyak compiler contohnya AVR bisa pake CodevisionAVR atau WinAVR. So…masih banyak yang harus dipelajari……..TETEP SEMANGAT…
to be continue
Example Application of AD/DA conversion
have u listen a music ?
Of Course yup! (what on earth r u -if u never listen a music-)
u must known CD (compact disk), its usually to storage a song & film but most of all is to storage music. Do you know how it works?
How exactly a computer or CD player read the code. it`s all about AD/DA conversion (Analog to Digital/Digital to Analog conversion).
ADC -Analog to Digital Converter-
it changes analog signal into digital (analog signal such as output sensor voltage). Why we must change the signal, it`s because a computer or any other electronic devices only process digital input, no matter what.
DAC -Digital to Analog Converter-
this is the inverse of ADC. its useful to ‘translate’ data from a computer to any actuator (for e.g.; fan, motor,etc).
when we talked about AD/DA conversion, we need to know these things
1. Bit
2. Resolution
3. Error
Bit: usually 8 bit ADC (cheaper) and 12 bit for more precision.
Resolution : depend on your bit. (full scale voltage)/(2^n -1)
Error : There is always an error. i got 6% of error from my DAC converter. U can count that with this formula.
(if u used 8 bit and max voltage 5 volt)
Digital voltage = (DAC read/256)*5 volt
Error = |Actual voltage-Digital voltage|*100% / actual voltage
see more detail in this site
http://communication.howstuffworks.com/analog-digital3.htm
STK 200 (FREE avr programmer / downloader)
i used this one, is simple, easy to build & cheap. no need any microcontroller. this is the schematic
i got it from this site
it`s connected to parallel port on your computer and also need supply voltage 5 volt and ground of course. There r three important line that must be connected between the parallel port (centronics) to your microcontroller unit (MCU), and that are MOSI MISO and SCK. Each type of MCU have a different pin configuration so u need to see the datasheet. This is my STK200

i have no trouble when i built this, its amazed me somehow, coz usually there is always some little mistake that i made when i build something, but not this one.
if u wanna build with USB connection, visit this site
Using CodevisonAVR
This is about, how to get started in codevison AVR.
First thing first, of course u need to install CodevisionAVR vist this site
and download this one,
CodeVisionAVR Evaluation V2.04.6
CodevisionAVR is a compiler for microcontroller AVR with C language, its included codewizardAVR. Believe me is really easy to used this thing, i will show u.
This is the step
File, New, Project, using codewizardAVR………then u will find this

do whatever u want -based on your purpose- (just click it) then after that
File , Generate save file and exit
all u need to do is just add your program (sometimes it takes only a few lines). for further information u can read my book (GUIDLINE PROJECT from AVR to Delphi)

i still want to edit this book, not to complete but its enough to understand about AVR. just come to my lab and i will give u this book. it`s still in indonesian version, if u want the english version, u have to wait.
i will give this book for free, coz knowledge is free.
control servo (PWM) with atmega8535
My friend ask me to help in her final project which need a motor with a very slow velocity (1cm/hour) . Can you imagine that ?
As far as I know, the best solution is Servo. We can control the speed with PWM (Pulse Width Modulation), and of course as my favourite microcotroller ATMega8535 will do that control. it`s only need two line addprogram in codevision AVR.
and it`s really work.
I love it…I love it…..I love it
this is the program
/*****************************************************
#include <mega8535.h>
#include <delay.h>
void main(void)
{
// Port A initialization
DDRA=0xFF;
// Port B initialization
DDRB=0xFF;
// Port D initialization
DDRD=0×20;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1500.000 kHz
// Mode: Ph. & fr. cor. PWM top=ICR1
// OC1A output: Non-Inv.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0×80;
TCCR1B=0×12;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0x3A;
ICR1L=0×98;
OCR1A=1000;
OCR1BH=0×00;
OCR1BL=0×00;
while (1)
{
for(OCR1A=600;OCR1A!=1500;OCR1A++){
delay_ms(7100);}
};
}
This program will control the servo in speed 1cm/hour
It`s WORKS! try this one(its fun, u need to wait 2hours to make sure the distance..ha…ha..)
ADC -Analog To Digital Converter
This is the first step of my final project. I am using ADC for converting voltage from solar cell and baterai into Digital, which has contribution in the next part (MPPT).
Equipment (i used the equipment in italic word):
- Microcontroller ATMega8535
- STK 200+ or any AVR chip programmer
-CodevisionAVR or WinAVR
With ADC built in ATMega8535 its quite simple to designing ADC, and also costless. This is the program :
#include <mega8535.h>
// Alphanumeric LCD Module functions
//#asm
// .equ __lcd_port=0×15 ;PORTC
//#endasm
//#include <lcd.h>
#include <delay.h>
#define ADC_VREF_TYPE 0×20
// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0×40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0×10)==0);
ADCSRA|=0×10;
return ADCH;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0×00;
DDRC=0xFF;
// ADC initialization
// ADC Clock frequency: 750.000 kHz
// ADC Voltage Reference: AREF pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: None
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0×84;
SFIOR&=0xEF;
// LCD module initialization
//lcd_init(16);
while (1)
{
// Place your code here
PORTC=read_adc(0);
};
}
I was using codewizard AVR, that`s why my program look so long. Honestly i`m not in the mood in writing, then i will continue this part later with a picture of my hardware.
in this program i plan to use LCD for appearance, but not finish yet, and because my LCD is broken so, i just try the result with LED in output at port C.
if you wanna try, good luck, its quite simply. do not hesitate to asking me, you can contact me at devinoer@students.itb.ac.id or just come to my lab (electronics and instrumentation laboratory Physics ITB)
An introduction to control system of solar cell
this topic is my Final Project in Bachelor degree.
Solar cell need some control system because it can`t storage the power, it`s only can produce the energy but not to storage. So, here we are try to learn and struggle with this area. For the first time, I really don`t get it, by the time finally i found something like treasure and it`s to heavy to carry out. I meant, it`s to complicated for me to understand well at beginning.
I`ll devided my project into 3 main part. First is the detector, commonly people use current sensing and voltage to get the data from the array (solar cell) and the bateries. but I made some exception for my final project, and that is no current sensing because is too expensive (if you want to buy that) and fragile (if you want to built it by yourself). Consequency is that i have to built more complicated algoritm in the next part, which is MPPT. Maximum Power Point Tracker to finding the best point and minimize loss energy. The last part is DC-DC converter, i still not decided yet, Which one i will use (the topology). But i prefer to using push-pull converter because i have to built this device in 500 Watt.
That`s all a brief of my final project. Explanation of each part will come soon. And this topic will finish in 4 month from now, that is mean in June (this is my deadline of this course)
-
Archives
- July 2010 (1)
- May 2010 (1)
- March 2010 (4)
- February 2010 (4)
- July 2009 (1)
- March 2009 (4)
- February 2009 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS
