// DC Motor PWM Test
// PWM FREQ. = 250 Hz
// TIMER/Count1, Fast PWM Mode : 7
#include <avr/io.h>
#include <avr/interrupt.h>
#include "ATmega128_v20.H"
unsigned int sum, ad_result;
ISR(TIMER3_OVF_vect) {
OCR3A = ad_result; // Port: PE3
}
int ADConvertor(char ch)
{
ADMUX = (ch & 0x1F) | 0x40;
ADCSRA = 0xC7;
while((ADCSRA & 0x10) != 0x10);
sum = ADCL+ADCH*256;
return(ADC);
}
int main(void)
{
unsigned int ADC6=0, ADC7=0;
MCU_initialize();
LCD_initialize();
LCD_string(0x80,"DC Motor Test");
LCD_string(0xC0," Tested By AACL ");
/////////////////////////////////////////////////////////
// Timer/Counter-3 Initialize for DC Motor PWM control //
/////////////////////////////////////////////////////////
TCCR3A = 0x83;
TCCR3B = 0x0B;
TCCR3C = 0x00;
TCNT3H = 0x00;
TCNT3L = 0x00;
ETIMSK = 0x04;
sei();
Delay_ms(1000);
LCD_string(0x80,"AD6: % AD7: %");
LCD_string(0xC0," ");
while(1)
{
ad_result = ADConvertor(6);
ADC6 = (sum/102.3*10);
LCD_command(0xC0+4);
LCD_3d(ADC6);
};
}
이게 dc모터 정방향으로 회전됩니다.. 여기서 역방향과 정지는 어떻게 구현해야할지 감이 안오네요 ㅠㅠ 도와주시면 감사하겠습니다. ㅠㅠ