Created
July 13, 2019 09:11
-
-
Save surinoel/c1a93cafb0f7b7003bb5721dde8bc312 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* servo.c | |
* | |
* Created: 2019-06-30 오후 3:41:18 | |
* Author : yeong | |
*/ | |
#include <avr/io.h> | |
#include "timer3.h" | |
#include "switch.h" | |
int main(void) | |
{ | |
// 서보를 돌린다 | |
// 돌리기 위해선 PWM 3번 타이머, 14번 고속 PWM(TOP ICR3, OCR3A => OC3A) | |
// ICR3 => 20ms 파형을 맞추고, OCR3A = ICR3 * 1/10 => -90, ICR3 * 3/20 => 0, ICR3 * 1/5 => 90 | |
timer3_pwm_init(); | |
switch_exti_init(); | |
while (1) | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "timer3.h" | |
void timer3_pwm_init(void) | |
{ | |
DDRE |= (1<<3); | |
TCCR3A |= (1<<COM3A1) | (1<<WGM31); | |
TCCR3B |= (1<<WGM33) | (1<<WGM32) | (1<<CS32); | |
ICR3 = 1250; | |
OCR3A = 93; | |
} | |
void servo_control(void) | |
{ | |
OCR3A = 35; | |
_delay_ms(1000); | |
OCR3A = 93; | |
_delay_ms(1000); | |
OCR3A = 150; | |
_delay_ms(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment