Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIT 29 MCU Project 로봇 SW 교육원 조용수.

Similar presentations


Presentation on theme: "UNIT 29 MCU Project 로봇 SW 교육원 조용수."— Presentation transcript:

1 UNIT 29 MCU Project 로봇 SW 교육원 조용수

2 학습 목표 M051 MCU 를 이용한 간단한 프로젝트 진행

3 Simple Mobile Robot Mobile Robot 자율 주행 가능한 Robot 제작 장애물이 있을 경우 회피
독립 전원 사용

4 필요한 기능 DC Motor 구동 능력 장애물 판별 능력 PWM 을 이용한 모터의 속력 조절 Motor Driver 회로 필요
Ultrasonic Sensor 로 전방 장애물 판단 장애물이 있는 경우 좌/우로 회피

5 필요한 기능 M051에서 사용할 기능 UART GPIO : PWM : TIMER : 디버깅 메시지 출력용
P2.1 ~ 2.4 : LED P4. 2 : Ultrasonic Sensor Interface PWM : PWM5 : DC 모터 속도 조절 용 PWM6 :DC 모터 속도 조절 용 TIMER : Timer 0 : 주기적으로 인터럽트를 발생하여 , 전방 장애물 판단 및 모터의 속도 조절 용 Timer 1 : Delay 함수 용

6 M051 MCU L293D Block Diagram Motor0 Motor0 Battery (1.5v x 4) UART
JTAG GPIO P4.2 PWM P2.5 , P2.6 Motor0 L293D Ultrasonic Motor0

7 Init void Sys_Init() { SYS_UnlockReg();
CLK->APBCLK = CLK_APBCLK_UART0_EN_Msk; SystemCoreClockUpdate(); CLK_EnableModuleClock(PWM45_MODULE); CLK_EnableModuleClock(PWM67_MODULE); CLK_SetModuleClock(PWM45_MODULE, CLK_CLKSEL2_PWM45_S_HIRC, 0); CLK_SetModuleClock(PWM67_MODULE, CLK_CLKSEL2_PWM67_S_HIRC, 0); SYS->P2_MFP = SYS_MFP_P24_PWM4 | SYS_MFP_P25_PWM5 | SYS_MFP_P26_PWM6 | SYS_MFP_P27_PWM7 ; SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0 ; SYS_LockReg(); }

8 System Init void Sys_Init() { SYS_UnlockReg();
CLK->APBCLK = CLK_APBCLK_UART0_EN_Msk; SystemCoreClockUpdate(); CLK_EnableModuleClock(PWM45_MODULE); CLK_EnableModuleClock(PWM67_MODULE); CLK_SetModuleClock(PWM45_MODULE, CLK_CLKSEL2_PWM45_S_HIRC, 0); CLK_SetModuleClock(PWM67_MODULE, CLK_CLKSEL2_PWM67_S_HIRC, 0); SYS->P2_MFP = SYS_MFP_P25_PWM5 | SYS_MFP_P26_PWM6; SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0 ; SYS_LockReg(); }

9 Timer Init void TMR0_Init(void) { CLK_EnableModuleClock(TMR0_MODULE);
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HIRC, 4); TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 5); /* Enable the Timer time-out interrupt */ TIMER_EnableInt(TIMER0); /* Start Timer counting */ TIMER_Start(TIMER0); /* Enable TMR0 Interrupt */ NVIC_EnableIRQ(TMR0_IRQn); } void TMR1_Init(void) CLK_EnableModuleClock(TMR1_MODULE); CLK_SetModuleClock(TMR1_MODULE, CLK_CLKSEL1_TMR1_S_HIRC, 1);

10 PWM Init void PWMInit() { PWM_ConfigOutputChannel(PWMB, 1, 5000, 10);
/* PWMA pin output enabled */ PWM_EnableOutput(PWMB, 0xF); /* Start PWMA module */ PWM_Start(PWMB, 0xF); }

11 Main() int main() { int d; int change = 0; Sys_Init(); Uart_Init();
PWMInit(); // Motor Control TMR1_Init(); // Delay TMR0_Init(); // Loop printf("Mobile App Test \n"); while(1) distance = getDistance(); TIMER_Delay(TIMER1, ); }

12 Timer Handler void TMR0_IRQHandler(void) {
/* Clears Timer time-out interrupt flag */ TIMER_ClearIntFlag(TIMER0); if(distance < 1000) { if(d == 0) { printf("Turn Left: %d\n", distance); PWM_ConfigOutputChannel(PWMB, 1, 5000, 1); PWM_ConfigOutputChannel(PWMB, 2, 5000, 99); } else { printf("Turn Right: %d\n", distance); PWM_ConfigOutputChannel(PWMB, 1, 5000, 99); PWM_ConfigOutputChannel(PWMB, 2, 5000, 1); }

13 Timer Handler else { d = rand()%2; if(distance > 5000) {
printf("Go Forward: %d , Speed : %d\n", distance , 99); PWM_ConfigOutputChannel(PWMB, 1, 5000, 99); PWM_ConfigOutputChannel(PWMB, 2, 5000, 99); } else if(distance > 1000) { int speed = (int)((float)distance / 100); printf("Go Forward: %d , Speed : %d\n", distance , 30 + speed); PWM_ConfigOutputChannel(PWMB, 1, 5000, 30 + speed); PWM_ConfigOutputChannel(PWMB, 2, 5000, 30 + speed); } }


Download ppt "UNIT 29 MCU Project 로봇 SW 교육원 조용수."

Similar presentations


Ads by Google