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..)
8 Comments »
Leave a Reply
-
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
my first time visit your blog, very educative. good. two thumbs for you. and also i wanna say thank you for your help, that servo was usefully.
really nice posting bro..
but can you help to spell your program clearly??
what’s the meaning of :
TCCR1A=0×80;
TCCR1B=0×12;
TCNT1H=0×00;
TCNT1L=0×00;
ICR1H=0×3A;
ICR1L=0×98;
OCR1A=1000;
OCR1BH=0×00;
OCR1BL=0×00;
please,thanxz
For more explanation you can read the datasheet. I used Timer 1, so you can check more deeply in Timer 1 and all the register in there. TCCR1A and TCCR1B stand for initialization timer 1 as a PWM mode with the Phase and Frequency correct. TCNT and ICR1 stand for the limit counting number for the timer. OCR1A because i used PIN OC1A (PD5) as the output not OC1B. i will make another post about this, to make it more clear for u and other, maybe next week will be done…i really busy this week
makasih atas tutorialnya.membantu banget.
klo boleh saya mau tanya,
1-bisa gak menjalankan servonya di PORTA.kan keluaran PWMnya di PORTD ya klo gak salah.
2-klo servonya 5 bagaimana memberikan pulsanya keservo..
terima kasih sebelumnya.
mohon penjelasannya. ^_^
ga bisa di port A, maximal hanya 2 servo.
kecuali klo mau manual bikin programnya beda lagi
Dear..
Mau tanya BU??
apakah dalam micro atMega8535 dapat diberi tambahan tombol perubah IP Micro tersebut??
dan juga memory yang masih bisa memungkinkan untuk penambahan IP Micro trsebut??
MOHON bantuan.
terima kasih Bu…
wah saya kurang begitu mengerti pertanyaannya IP disini IP address..bukan yaa ;p
maksudna tambahan tombol perubah tuh yang seperti apa ya, (contohnya mau dijadikan apa ),
Apa maksudna mau buat tombol sebagai input di mikro itu bisa, jenis tombol banyak , mau yg seperti apa?
bisa