|
¡û ¤Ï¤¸¤á¤Ë
Á°²ó ¤È Á°¡¹²ó ¤Ç¡¢¥µ¡¼¥Ü¥â¡¼¥¿¤òÆ°¤«¤¹¤³¤È¤¬½ÐÍè¤Þ¤·¤¿¡£¤È¤³¤í¤Ç¡¢ËÜʸ½ñ¤Ç»È¤Ã¤Æ¤¤¤ë´ðÈĤˤϥܥê¥å¡¼¥à¤È¤¤¤¦ÆþÎϥǥХ¤¥¹¤¬ÉÕ¤¤¤Æ¤¤¤Þ¤¹¡£¤»¤Ã¤«¤¯¤Ç¤¹¤«¤é¤³¤ì¤ò»È¤Ã¤Æ¥µ¡¼¥Ü¥â¡¼¥¿¤ò¼êÆ°¤ÇÆ°¤«¤·¤Æ¤ß¤¿¤¤¤È»×¤¤¤Þ¤¹¡£¥Ü¥ê¥å¡¼¥à¤«¤é¤ÎÆþÎϤˤĤ¤¤Æ¤Ï¡¢LECTURE 4 A/D ÊÑ´¹¤Ç¥Ü¥ê¥å¡¼¥à¡Ê²ÄÊÑÄñ¹³¡ËÃͤòÆÉ¤à ¤ÇÀâÌÀ¤·¤Æ¤¤¤Þ¤¹¡£
¡û ¥³¥ó¥»¥×¥È
°Ê²¼¤ÎÍͤʥ³¥ó¥»¥×¥È¤Ç¡¢½èÍý¤ò¹Ô¤¤¤Þ¤¹¡£
- LECTURE 9 ¥µ¡¼¥Ü¥â¡¼¥¿¤òÆ°¤«¤¹¡Ê¹â®PWMµ¡Ç½»ÈÍÑ¡Ë ¤ÈƱ¤¸¤¯¥¿¥¤¥Þ/¥«¥¦¥ó¥¿1 ¤Î¹â® PWM µ¡Ç½¤ò»È¤Ã¤Æ¥µ¡¼¥Ü¥â¡¼¥¿¤òÆ°¤«¤¹
- LECTURE 4 A/D ÊÑ´¹¤Ç¥Ü¥ê¥å¡¼¥à¡Ê²ÄÊÑÄñ¹³¡ËÃͤòÆÉ¤à ¤ÈƱ¤¸¤¯ A/D ÊÑ´¹¤Ë¤è¤ê¥Ü¥ê¥å¡¼¥àÃͤòÆɤ߹þ¤à
- ¢¬¤ÇÆɤ߹þ¤ó¤À¥Ü¥ê¥å¡¼¥àÃͤ˱þ¤¸¤Æ¥¿¥¤¥Þ/¥«¥¦¥ó¥¿1 ¤Î OCR1A¡ÊÈæ³Ó A ¥ì¥¸¥¹¥¿¡Ë¤ÎÃͤòÊѲ½¤µ¤»¡¢¥µ¡¼¥Ü¥â¡¼¥¿¤Î³ÑÅÙ¤òÀ©¸æ¤¹¤ë
¤È¤³¤í¤Ç¡¢ËÜʸ½ñ¤ÇÉ®¼Ô¤¬»È¤Ã¤¿¥Ü¥ê¥å¡¼¥à¤Î²óž³ÑÅÙ¤È A/D ÆþÎÏÃͤÎÂбþ¤Ï¡¢²¼¿Þ¤ÎÍͤˤʤê¤Þ¤·¤¿¡£²£¼´¤¬²óž³ÑÅ٤ǡ¢½Ä¼´¤¬ A/D ÆþÎÏÃͤǤ¹¡£
¿Þ¤ò¸«¤ë¤È¡¢³«¤»Ï¤á¤Î A/D ÆþÎÏÃͤÎÊѲ½¤¬Â礤¯ºÇ¸å¤ÎÊý¤ÏÊѲ½¤¬¾®¤µ¤¯¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤Î¤¿¤á¥µ¡¼¥Ü¥â¡¼¥¿¤ÎÆ°¤¤â¡¢¥Ü¥ê¥å¡¼¥à¤Î³«¤»Ï¤á¤ÎÊѲ½¤¬Â礤¯ºÇ¸å¤ÎÊý¤ÏÊѲ½¤¬¾®¤µ¤¯¤Ê¤ê¤Þ¤·¤¿¡£¾å¿Þ¤ÎÆÃÀ¤Ï¡¢»ÈÍѤ¹¤ë¥Ü¥ê¥å¡¼¥à¤Ë±þ¤¸¤Æ°Û¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¢µ¤¤Ë¤Ê¤ëÊý¤ÏÄ´¤Ù¤Æ¤ß¤Æ²¼¤µ¤¤¡£
¡û ²óÏ©¿Þ
LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ¤Ë¤Ä¤¤¤Æ ¤Ë·ÇºÜ¤·¤Æ¤¢¤ëÁ´ÂβóÏ©¿Þ¤ËÂФ·¤Æ¡¢ATMega8535 ¤Î¥Ü¥ê¥å¡¼¥à¡Ê²ÄÊÑÄñ¹³¡ËÉôʬ¤È OC1A ¥Ô¥ó¤ª¤è¤Ó¥µ¡¼¥Ü¥â¡¼¥¿¤ÈÀܳ¤¹¤ë¿®¹æÀþ¡Ü¥³¥Í¥¯¥¿Éôʬ¤òÀÖÏȤǰϤó¤À¿Þ¤ò ¤³¤Á¤é ¤ËÃÖ¤¤¤Æ¤ª¤¤Þ¤¹¡£
¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÈÀâÌÀ
¥Ü¥ê¥å¡¼¥à¤ò»È¤Ã¤Æ¥µ¡¼¥Ü¥â¡¼¥¿¤òÁàºî¤¹¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò 11steering.tar.gz ¤«¤é¥À¥¦¥ó¥í¡¼¥É¤Ç¤¤Þ¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò ¸Ç¤á¤¿ tar ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
Ãæ¤Ë¤Ï
- Makefile
- adc.h
- adc.c
- util.h
- util.c
- timer1.h
- timer1.c
- main.c
¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£adc.h/adc.c/util.h/util.c ¤Ë¤Ä¤¤¤Æ¤Ï LECTURE 4 A/D ÊÑ´¹¤Ç¥Ü¥ê¥å¡¼¥à¡Ê²ÄÊÑÄñ¹³¡ËÃͤòÆÉ¤à ¤ÎÆâÍƤÈƱ¤¸¡¢timer1.h/timer1.c ¤Ë¤Ä¤¤¤Æ¤Ï LECTURE 8 ¥¿¥¤¥Þ/¥«¥¦¥ó¥¿1¤ò»È¤¦ ¤ÎÆâÍƤÈƱ¤¸¤Ç Makefile ¤â¤Û¤È¤ó¤ÉÊѤï¤é¤Ê¤¤¤Î¤Ç¡¢main.c ¤Ë¤Ä¤¤¤Æ°Ê²¼¤ËºÜ¤»¤Þ¤¹¡£¤Ê¤ª¡¢°Ê²¼¤Ë·ÇºÜ¤·¤Æ¤¤¤ë¥½¡¼¥¹¥³¡¼¥É¤Ë¤Ï½¤Àµ BSD ¥é¥¤¥»¥ó¥¹¾ò¹à¤ò´Þ¤á¤Æ¤¤¤Þ¤»¤ó¤¬¡¢¥½¡¼¥¹¥³¡¼¥ÉÇÛÉۤϽ¤Àµ BSD ¥é¥¤¥»¥ó¥¹¤Ë½¾¤¤¤Þ¤¹¡Ê¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤ÎÌÈÀÕ»ö¹à¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡Ë¡£
¤³¤ì¤Þ¤Ç¤Ë¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄê¤ò¹Ô¤Ã¤¿¤³¤È¤¬°ìÅÙ¤â̵¤¤¾ì¹ç¤Ï¡¢¤Þ¤ººÇ½é¤Ë make fuse ¤ò¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£fuse ¥¿¡¼¥²¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Ï¡¢LECTURE 2 LED ¤òÅÀÌǤµ¤»¤ë ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Î¹à¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
make ¼Â¹Ô¸å¡¢¥×¥í¥°¥é¥à¤ò¥¢¥Ã¥×¥í¡¼¥É¤¹¤ë¾ì¹ç¤Ï make uisp ¤ò¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£
¥Ü¥ê¥å¡¼¥à¤Ç¥µ¡¼¥Ü¥â¡¼¥¿¤òÁàºîÃæ¤ÎÆ°²è¤Ç¤¹¡Ê10Éá£YouTube ¤ËÀܳ¤·¤Þ¤¹¡Ë¡£
- main.c
1 #include <avr/interrupt.h> 2 #include <avr/io.h> 3 #include <avr/sleep.h> 4 5 #include "adc.h" 6 #include "timer1.h" 7 #include "util.h" 8 9 10 #define ICR1_AS_TOP 19999 11 #define OCR1A_LIMIT_CCW 2100 12 #define OCR1A_CENTER 1500 13 #define OCR1A_LIMIT_CW 900 14 15 static void timer1_ic_interrupt(void); 16 17 18 int 19 main(void) 20 { 21 DDRD |= _BV(DDD5); /* PD5 ¥Ô¥ó¤ò½ÐÎϤËÀßÄê */ 22 pullup(); 23 PORTA &= ~_BV(PINA0); /* PINA0 ¥×¥ë¥¢¥Ã¥×̵¸ú */ 24 25 /* (8MHz/64) = 125KHz */ 26 adc_init(ADC_CK_64, ADC_NO_INT); 27 adc_set_ch(PINA0); 28 29 timer1_ic_enable(); 30 timer1_ic_set_interrupt(timer1_ic_interrupt); 31 timer1_set_wave_mode(WGM1_FAST_PWM_ICR1); 32 timer1_set_coma_mode(COM_A_HIGH_FIRST); 33 timer1_set_count(0); 34 timer1_set_icr1(ICR1_AS_TOP); 35 timer1_set_ocr1a(OCR1A_LIMIT_CW); 36 37 sei(); 38 39 /* (8MHz/8)/20000 = 50Hz */ 40 timer1_start(TIMER1_CK_8); 41 42 while (1){ 43 sleep_mode(); 44 } 45 46 return 0; /* ·Ù¹ð¤òÈò¤±¤ë¤¿¤á */ 47 } 48 49 50 /* 51 * ¥¿¥¤¥Þ/¥«¥¦¥ó¥¿1 Êá³Í³ä¹þ¥Ï¥ó¥É¥é¡ÊTOPÃÍÅþã¡Ë 52 * 53 * ¥Ü¥ê¥å¡¼¥à³«Å٤˱þ¤¸¤Æ OCR1A Ãͤò·×»»¤·¥Ç¥å¡¼¥Æ¥£Èæ¤òÊѹ¹¤¹¤ë¡£ 54 * ¥Ü¥ê¥å¡¼¥à³«ÅÙ¤ËÂбþ¤¹¤ë OCR1A Ãͤϰʲ¼¤Ç·×»»¤¹¤ë 55 *¡ÊR2 ¤Ï¥Ü¥ê¥å¡¼¥àÄñ¹³ºÇÂçÃÍ¡¢R1 ¤Ï¥×¥ë¥¢¥Ã¥×Äñ¹³ÃÍ¡Ë 56 * 57 * OCR1A = OCR1A_LIMIT_CW + (OCR1A_LIMIT_CCW - OCR1A_LIMIT_CW) * 58 * data / (ADC_MAX * (R2 / (R1 + R2))) 59 * 60 * ¥é¥¤¥Ö¥é¥ê¤ËÍê¤Ã¤ÆÉâÆ°¾®¿ôÅÀ·×»»¤ò¹Ô¤¦¤È¡¢¥×¥í¥°¥é¥à¥µ¥¤¥º 61 * ¤¬ 8KB ¤ÇǼ¤Þ¤é¤Ê¤¤¤¿¤á¡¢¼ÂÃͤò»È¤Ã¤Æ°Ê²¼¤ÎÍͤ˷׻»¤·¤Æ¤ª¤¯¡£ 62 * 63 * R2 = 50K 64 * R1 = 10K 65 * (OCR1A_LIMIT_CCW - OCR1A_LIMIT_CW) / (ADC_MAX * (R2 / (R1 + R2))) = 1.4076 66 * 67 * ¾åµ¤ò 10 Çܤ·¤Æ·×»»¤·¡¢ºÇ¸å¤Ë 10 ¤Ç³ä¤Ã¤ÆÀµ¤·¤¤ÃͤòÆÀ¤ë¡£ 68 * 69 * OCR1A = OCR1A_LIMIT_CW + (14 * data) / 10; 70 */ 71 static void 72 timer1_ic_interrupt(void) 73 { 74 uint16_t ocr1a; 75 76 adc_start(); 77 adc_wait(); 78 79 ocr1a = OCR1A_LIMIT_CW + (14 * adc_get()) / 10; 80 timer1_set_ocr1a(ocr1a); 81 } 82 83 /* End of main.c */
- 18 ¡Á 47 ¹ÔÌÜ (main())
- pullup() ¤ÎÁ°¤Ë PORTD5 ¤Î¤ß½ÐÎÏÊý¸þ¤ËÀßÄê
- pullup() (pullup.h¡¢PORTD5 °Ê³°¤ÎÁ´ÆþÎϥݡ¼¥È¤ÎÆâÉô¥×¥ë¥¢¥Ã¥×¤ò͸ú²½)
- PINA0 ¥Ô¥ó¤ÏÆþÎϤȤ·¤Æ»ÈÍѤ¹¤ë¤Î¤Ç¡¢¥×¥ë¥¢¥Ã¥×¤ò̵¸ú²½
- adc_init() (adc.h¡¢A/D ÊÑ´¹´ï½é´ü²½)
- adc_set_ch() (adc.h¡¢PINA0 ¤ò¥¢¥Ê¥í¥°ÆþÎϤȤ·¤ÆÀßÄê)
- timer1_ic_enable() (timer1.h¡¢¥«¥¦¥ó¥¿ºÇÂçÃÍ ICR1 Åþã»þ¤ÎÊá³Í³ä¤ê¹þ¤ß͸ú²½)
- timer1_ic_set_interrupt() (timer1.h¡¢Êá³Í³ä¤ê¹þ¤ß»þ¤Ë¼Â¹Ô¤¹¤ë¥æ¡¼¥¶´Ø¿ô¤ÎÅÐÏ¿)
- timer1_set_wave_mode() (timer1.h¡¢ÇÈ·ÁÀ¸À®¼ïÊ̤òÀßÄê)
- timer1_set_coma_mode() (timer1.h¡¢Èæ³ÓA½ÐÎϥ⡼¥É¤òÀßÄê)
- timer1_set_count() (timer1.h¡¢TCNT1 ¤Î½é´üÃͤòÀßÄê)
- timer1_set_icr1() (timer1.h¡¢ICR1 ¤ÎÃͤòÀßÄê)
- timer1_set_ocr1a() (timer1.h¡¢OCR1A ¤ÎÃͤòÀßÄê)
¤ò¹Ô¤Ã¤¿¸å¡¢sei() (avr/interrupt.h) ¤ò¼Â¹Ô¤·¤Æ¥·¥¹¥Æ¥à¤Î³ä¤ê¹þ¤ß¤ò͸ú²½¤·¤Æ¤¤¤Þ¤¹¡£
A/D ÊÑ´¹´ï¤Î½èÍý¤Ë¤Ä¤¤¤Æ¤Ï¡¢LECTURE 4 A/D ÊÑ´¹¤Ç¥Ü¥ê¥å¡¼¥à¡Ê²ÄÊÑÄñ¹³¡ËÃͤòÆÉ¤à ¤Î main-noint.c ¤ò¡¢¥¿¥¤¥Þ/¥«¥¦¥ó¥¿1 ¤Î½èÍý¤Ë¤Ä¤¤¤Æ¤Ï LECTURE9 ¥µ¡¼¥Ü¥â¡¼¥¿¤òÆ°¤«¤¹¡Ê¹â®PWMµ¡Ç½»ÈÍÑ¡Ë ¤Î main.c ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£
°Ê¸å sleep_mode() ¤Ë¤Æ¥¢¥¤¥É¥ëÆ°ºî¤Ë°Ü¹Ô¤·¡¢¥µ¡¼¥Ü¥â¡¼¥¿¤Î³ÑÅÙÀ©¸æ¤ÏÊá³Í³ä¤ê¹þ¤ß¥Ï¥ó¥É¥é¤ËǤ¤»¤Þ¤¹¡£
- 50 ¡Á 81 ¹ÔÌÜ (timer1_ic_interrupt())
Êá³Í³ä¤ê¹þ¤ß»þ¤Ë¼Â¹Ô¤µ¤ì¤ë¥æ¡¼¥¶´Ø¿ô¤Ç¤¹¡£
ËÜ´Ø¿ô¤Ï TCNT1 ¤¬¥«¥¦¥ó¥¿ºÇÂçÃÍ¡ÊICR1¡Ë¤ËÅþ㤹¤ëÅÙ¡Ê50Hz = 20ms Ëè¡Ë¤Ë¼Â¹Ô¤µ¤ì¡¢ ¤½¤Î»þÅÀ¤Ç¤Î¥Ü¥ê¥å¡¼¥àÃͤò A/D ÊÑ´¹¤Ë¤è¤Ã¤ÆÆɤ߹þ¤ß¡¢¥Ü¥ê¥å¡¼¥àÃͤ˱þ¤¸¤¿ OCR1A ¤ÎÃͤò·×»»¤·¤ÆºÆÀßÄꤷ¤Þ¤¹¡£
A/D ÊÑ´¹¤Ë¤è¤ëÆþÎÏÃͤò data¡¢R1 ¤ò¥×¥ë¥¢¥Ã¥×Äñ¹³ÃÍ¡¢R2 ¤ò¥Ü¥ê¥å¡¼¥àÄñ¹³ºÇÂçÃͤȤ·¤Æ¡¢ OCR1A ¤ò°Ê²¼¤Î·×»»¼°¤Ç·×»»¤·¤Þ¤¹¡£
OCR1A = OCR1A_LIMIT_CW + (OCR1A_LIMIT_CCW - OCR1A_LIMIT_CW) * data / (ADC_MAX * (R2 / (R1 + R2)))
timer1_ic_interrupt() ¤Î´Ø¿ô¥³¥á¥ó¥È¤Ë¤¢¤ëÄ̤ê¤Ë¡¢¼ÂÃͤò»È¤Ã¤Æ·×»»¤ò¿Ê¤á¤ë¤È
OCR1A = OCR1A_LIMIT_CW + 1.4 * data
¤È¤Ê¤ê¤Þ¤¹¡£¤Ä¤Þ¤ê OCR1A ¤Ï¡¢OCR1A_LIMIT_CW ¤ò²¼¸Â¤È¤·¤Æ data ¤ËÈæÎ㤷¤ÆÊѲ½¤·¤Þ¤¹ (0 <= data <= Ìó 853.182(0x355)¡¢853.182 ¤Ë¤Ä¤¤¤Æ¤Ï ¤³¤Á¤é ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£¤Ê¤ª¡¢É®¼Ô¤Î´Ä¶¤Ç¤Ï 855 ¤Þ¤Ç¾å¤¬¤ê¤Þ¤·¤¿)¡£
76 ¡Á 77 ¹ÔÌÜ¤Ç A/D ÊÑ´¹¤ò¹Ô¤¤¡¢79 ¹ÔÌܤǿ·¤·¤¤ OCR1A ¤ÎÃͤò·×»»¤·¤Æ¤¤¤Þ¤¹¡£¤½¤Î¸å 80 ¹ÔÌܤǿ·¤·¤¤ OCR1A ¤òÀßÄꤹ¤ë¤³¤È¤Ç¡¢¥Ü¥ê¥å¡¼¥à¤Î³«Å٤˱þ¤¸¤Æ¥µ¡¼¥Ü¥â¡¼¥¿¤Î ²óž³ÑÅÙ¤¬ÊѲ½¤¹¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£
°Ê¾å¤Ç²òÀâ¤Ï½ª¤ï¤ê¤Ç¤¹¡£¥Ü¥ê¥å¡¼¥à¤ò¤¯¤ë¤¯¤ë²ó¤¹¤È¡¢¥µ¡¼¥Ü¥â¡¼¥¿¤¬¤½¤ì¤Ë¤Ä¤¤¤Æ¤¯¤ë¤Î¤¬¤Á¤ç¤Ã¤È³Ú¤·¤«¤Ã¤¿¤ê¤·¤Þ¤¹¡Ä