å 容ïŒ
- ãã€ã¯ããšã¬ã¯ãããã¯ã¹ãšã®æåã®æ¥è§Šã
- éããã°ã©ããã«ããžãã¯ãšã¬ã¡ã³ãã§ã®èªåè»ã®æ§ç¯ã
- STM32ã®äœ¿çšãéå§ããã éçºç°å¢ã ãã€ã¯ãã³ã³ãããŒã©ãŒããã·ã³ã«æ¥ç¶ããŸãã
- å茪ã®å転è§åºŠã決å®ããŸã-ADCãä»ãããã£ãŒãããã¯ã
- DACã䜿çšããŠãµãŠã³ããåçããŸãã
1.ãã€ã¯ããšã¬ã¯ãããã¯ã¹ãšã®æåã®æ¥è§Š
çç±ã¯é¢ä¿ãããŸããããé»è©±ããã®ã³ãã³ããåãä»ããããã€ã¹ãäœæãããšããèããçãŸããŸããã ã©ããã£ãŠããã®ïŒ BluetoothãWiFiãUSBãªã©ãä»ããŠå¯èœã§ãã ããããæºåž¯é»è©±ã®åºåãããããã»ããã«éãããé³ãèªèããæ¹ãç°¡åã§ãããæ®éçã§ããããã«èŠããŸãïŒä»¥äžãåé¡ã®è§£æ±ºã®ããã«ãæãåçŽãªå®è£ ãçµææåã®æ¹æ³ãéžæãããŸãïŒã
ãµãŠã³ãã¯ã¹ããŒããã©ã³çšã®ç¹å¥ãªããã°ã©ã ã§åæã§ããŸãããèå³æ·±ããªãã·ã§ã³ããããŸã-DTMFä¿¡å·ã ãããã¯æšæºã§ããããã¹ãŠã®æºåž¯é»è©±ããã³ã»ãšãã©ã®åºå®é»è©±ïŒçªå·ããã€ã€ã«ãããšããŸãã¯é³å£°ã¡ãã¥ãŒã§ïŒã§äœ¿çšãããé³å£°ãã£ãã«ã§åé¡ãªãéä¿¡ãããŸãã
ã¿ã¹ã¯1ïŒDTMFä¿¡å·èªè
DTMF埩å·åãå®è£ ããããã®3ã€ã®ãªãã·ã§ã³ãã€ã³ã¿ãŒãããããå°å·ãããŠããŸãïŒç§ã®èãã¯æ°ãããã®ã§ã¯ãããŸããïŒã è³Œå ¥ãããŸãïŒ
- MT 8870DEãã³ãŒããŒ-å ¥åã¢ããã°ä¿¡å·ããæåŸã«èªèãããDTMFã³ãã³ãã®ãã€ããªã³ãŒãïŒ4ãããïŒãšã1ããã-DTMFã³ãã³ãã®æç¡ïŒä»åºŠã¯ã5çªç®ã®åºåããšåŒã³ãŸãïŒãåãåããŸãã
- ãã³ãŒããŒã®åäœã«å¿ èŠãªæ°Žæ¶æ¯ååãã³ã³ãã³ãµãŒãæµæåšã
- 7ã»ã°ã¡ã³ãã€ã³ãžã±ãŒã¿-é»è©±ã§æŒãããçªå·ã衚瀺ããŸãã
- 7ã»ã°ã¡ã³ãã€ã³ãžã±ãŒã¿ãŒçšKR 514ID-1ãã³ãŒããŒ-ãã€ããªã³ãŒããããã»ã°ã¡ã³ãããšã«7ã€ã®åºåãåãåããŸãã
- ã¯ãã ä»ãããã«å®è£ ããããã®éçºããŒãã
- ãã¬ããããŒãã®é ç·/ãžã£ã³ããŒã
ãšã©ãŒãåéãæ€èšŒãä¿®æ£ããŸã...åäœããŸãã ã·ã§ãã¯ã
ããã§ãããããã¹ãŠã匷å¶çã«ãã·ã³ãå¶åŸ¡ããå¿ èŠããããŸãã ããã«ããã·ã³ã®ã¢ã¯ã·ã§ã³ãæŒãããçªå·ã«è«ççã«å¯Ÿå¿ããããã«ïŒ2-åæ¹ã4-å·ŠåŽã6-å³åŽã8-åŸæ¹ã
ã¿ã¹ã¯2ïŒDTMFãã³ãŒããŒããã®ä¿¡å·ã®4ã€ã®ç¹å®ã®çµã¿åããã¯ã4ã€ã®æ©èœã®ãããããã¢ã¯ãã£ãã«ããå¿ èŠããããŸã
æãåçŽãªãªãã·ã§ã³ã¯ã10é²ãã³ãŒããŒã§ãã ãªãŒãã³ã³ã¬ã¯ã¿ãŒä»ãã®K155ID10ãè³Œå ¥ããŸãã-ãã€ããªã³ãŒãçšã®4ã€ã®å ¥åã10ã®åºåã¯0ã9ã®æ°åãè¡šããç®çã®åºåã¯ã0ããæ®ãã¯ã1ãã«ãªããŸãã ãã®ãã³ãŒããŒã¯è² è·ã§äœ¿çšãããåäœé»æµã¯80 mAïŒçœç±é»çããªã¬ãŒïŒã«éããããšãã§ãã䟿å©ã§ãã ãã©ã³ãžã¹ã¿ã¯ãŸã 䜿çšããå¿ èŠããããŸãããã
ã¿ã¹ã¯3ïŒã¢ãŒã¿ãŒã®æ¥µæ§å転ãHããªããž
åäŸã®é ã¯ãã¹ãŠãã¬ãŽããè»ãéããŸãããã¬ãŽã¯ãé»æ± ã®æ¥µæ§ãæåã§åãæ¿ããããšã§è¡ãæ¥ããŸããïŒã¢ãŒã¿ãŒãšãªã¢ã³ã³ä»ãã®ã¬ãŽã»ããã¯ãããŸããã§ããïŒã ããã倧人ã®ããã¡ããéã¶æéã§ãã
æ®éã®äººã¯ãã©ã³ãžã¹ã¿ã§HããªããžãäœããŸãã é«åºŠ-ããããšåããã©ã³ãžã¹ã¿ã§ã¿ãŒã³ããŒãœãªã¥ãŒã·ã§ã³ãè³Œå ¥ããŸãã ç§ã¯é»ç£ç¶é»åšãåãæ¿ããŸããã åŸã§åŒ·åãªïŒæ倧3Aã®ã³ã¬ã¯ã¿é»æµçšïŒNPNããã³PNPãã©ã³ãžã¹ã¿ãŒTIP31 C STããã³TIP32 C STãè³Œå ¥ããããããããã®Hããªããžãçµã¿ç«ãŠãŸããããäœããã®çç±ã§ãªã³ããŒãLEDã§ã®ã¿åäœããã¢ãŒã¿ãŒã¯ãªã³ã«ãªããŸããã§ããåã çç±ã¯ããããŸããã
ã¹ã€ããã³ã°ãªã¬ãŒã«ã¯ãã¢ãŒã¿ãŒããšã«2ã€å¿ èŠã§ãïŒãã©ã³ãžã¹ã¿ãŸãã¯ã¯ããŒãºãªã¬ãŒã«ã¯4ã€å¿ èŠã§ãïŒã ããã©ã«ãã§ã¯ãã¢ãŒã¿ãŒã®äž¡æ¹ã®æ¥ç¹ïŒç©å ·ã®ããã«éåžžã®ã³ã¬ã¯ã¿ãŒïŒã¯ãã€ãã¹ã«æ¥ç¶ãããŠããŸãã å¶åŸ¡ä¿¡å·ããªã¬ãŒã®1ã€ã«é©çšããããšãã¢ãŒã¿ãŒæ¥ç¹ããã©ã¹ã«åãæ¿ãããã¢ãŒã¿ãŒãäœåãéå§ããŸãã ãã®ãããªæ¥ç¶ã®å€§ããªå©ç¹ã¯ãã©ã®ãããªç¶æ³ã§ããªã¬ãŒã®æ éã®ããã«çæéã§ç絡ããããšããã§ããªãããšã§ãã æ¬ ç¹ã¯ãå¶åŸ¡é»å§ããªã¬ãŒããé€å»ããããšãã¢ãŒã¿ãŒãç絡ããŠãã¬ãŒãã«ãªãããšã§ãã 解決çã¯ãå¥ã®ãªã¬ãŒãéããããšã§ãã ããŠãã¢ãŒã¿ãŒãå転ãããã«ã¯ãããªãŒã©ã³ãã³ã°ã®ããã«ãããéããå¿ èŠããããŸã-ãããéããŠãããã¬ãŒããã®ããã«-ãããåã³éããŸãã ãã®ãªã¬ãŒã¯åŸã§è¿œå ãããŸãã
ã¿ã¹ã¯4ïŒã¿ã€ãã©ã€ã¿ãŒãçµã¿ç«ãŠã
ãã·ã³ã«ã¯2ã€ã®ã¢ãŒã¿ãŒããããŸãã1ã€ã¯ã¬ãŽãã£ãã¡ã¬ã³ã·ã£ã«ãä»ããŠåŸèŒªãå転ããã2ã€ç®ã¯å茪ãå転ãããŸãã ã®ã¢ããã¯ã¹å ã®ãã©ã¹ããã¯ã®ã¢ã¯ã·ã¹ãã ã®å¹çãåäžãããŸãããããã¹ãŠæ©èœããŸãã
ããŒãã«4ã€ã®ãªã¬ãŒãé 眮ããŸãã ãã¬ããããŒãã¯é«é»æµçšã«èšèšãããŠããªãïŒåã¢ãŒã¿ãŒã¯1ã1.6 Aãæ¶è²»ããïŒãšèšãããŸããããçæéã§çµæãåŸãããªãå Žåããããžã§ã¯ãã¯æ¬¡ã®ãšã¢ããã¯ãç¶æãããªã¹ã¯ããããŸãã ã¡ãªã¿ã«ããªã¬ãŒãå«ãããšé»å§ãµãŒãžãçºçããã«ãŒããšèª€åäœãçºçããŸããã 確ãã«ããã¯ç¹å¥ãªã¹ããŒã ã«ãã£ãŠè§£æ±ºãããŸãããç§ã¯ããããªãŒãåããå¥ã®ãŠãããããã¢ãŒã¿ãŒã«é»åãäŸçµŠããŸããã
é»ç£ãªã¬ãŒã2ã€ã®é»æº-ããŸãã«ãããŒãã³ã¢ã¯ãããŸãããïŒ ããã«ãã£ãšïŒ
ããããã¹ãŠã10é²ãã³ãŒããŒã«æ¥ç¶ããããšã¯æ®ããŸãã å¿ èŠãªçµè«ã¯ã4ã€ã®NPNãã©ã³ã¹ãã©ãŒããŒBC547ã®ãšããã¿ãŒã§ããããã®ããŒã¹ã«ã¯ãDTMFãã³ãŒããŒããããŒãæŒããããšããä¿¡å·ïŒã5çªç®ã®åºåãïŒãã³ã¬ã¯ã¿ãŒãåãªã¬ãŒããããŸãã æ²ãã£ããå¥åŠãªããããããã¯åäœããŸãã
2.éããã°ã©ããã«ããžãã¯ãšã¬ã¡ã³ãã§ã®èªåè»ã®æ§ç¯
ãã·ã³ãåæã«ä¹ãããšãšå転ããããšãã§ããã¯ãã ãšä»®å®ããŸãã è«ççã«ã¯ã1ã3ã7ã9ã®æ°åã䜿çšãããšã2ã€ã®ãªã¬ãŒãããªã¬ãŒãããŸãã æåã¯ããã©ã³ãžã¹ã¿ãšããã¿ãã10é²ãã³ãŒããŒã«ãã€ãªãŒããæ¥ç¶ããŠãããå®è£ ããäºå®ã§ããããããŸããããŸããã§ããã 10é²ãã³ãŒããŒãã0ããæå®ããå Žåããã®ããŒããã§éãPNPãã©ã³ãžã¹ã¿ãå¿ èŠã§ããããšãããããŸããã ããããNPNãããããŸããã§ããã
ã¿ã¹ã¯5ïŒ1ã3ã7ããŸãã¯9ãæŒããšããã·ã³ã移åããŠå転ããã¯ãã§ãã
ãšã³ã¿ãŒãã€ã³ã¡ã³ã/éçº/䜿çšã®ç®çã§ãè«çèŠçŽ 4-Iã4-ORãNOTãAND-NOTãOR-NOTãããã³ANDã1ã€ãã€è³Œå ¥ããŸããã æåã®èãã¯ã10é²æ°ãã³ãŒããŒããã®åºåãšDTMFãã³ãŒããŒããã®ã5çªç®ã®åºåããåçŽãªè«çåè·¯ã§äœ¿çšããããšã§ãæçµçã«å¿ èŠãªãã©ã³ãžã¹ã¿ãŒïŒããã³ããããä»ããŠïŒãéããŸãã ãããïŒ ããŠãããããšããŠã®10é²åŸ©å·åšK155ID10ã¯ãäœãã§2ãã«ããçæããŸãã èªç±ã«äœ¿ããè«çèŠçŽ ã¯ã©ããããã®ãããªä¿¡å·ãããŠãããããšèŠãªããŸããã§ããã 4-IïŒKR1533ïŒãé€ãã DTMFã§ã裞ã®ã4ãããã®ãã€ããªã³ãŒãã䜿çšãããšãå©çšå¯èœãªèŠçŽ ããå¿ èŠãªããžãã¯ãçµã¿ç«ãŠãããšãã§ããŸããã§ããã éåžžã®10é²æ°ã®åŸ©å·åæ©èœã¯ãã¿ã¹ã¯ãäœåºŠãä¿é²ããŸãã ãããŠãããã¯ãã®ãããªå°ããªmç¬ã«ãªããŸãã-ããã®ã¯é£ããã§ãããã§ããŸãïŒ ïŒååäžã«å¯ãŠè©³çŽ°ã調ã¹ããšããèãã¯æåŠãããŸããïŒã
10é²ãã³ãŒããŒã¯ã埩å·åãããæ°å€ã®åºåãé€ããã¹ãŠã®çµè«ã«ãã¢ã³ãããããäžããããšãæãåºããŠã次ã®ããšãè¡ããŸãã
æåã«... m ... 4-IèŠçŽ ã®å ¥åã®ã«ã«ãããã§ãæ°å1ã2ã3ãããã³ããŠãããããæå®ããŸãã 2çªç®-7ã8ã9ãããã³ããŠããããã æåã®åºåããã1ã2ããŸãã¯3ãæŒãããå ŽåïŒè»ãåé²ããå ŽåïŒã2çªç®ã®åºåãã-7ã8ã9ïŒæ»ãå ŽåïŒããããŒãããåŸãããŸãã ãã以å€ã®å Žåã4-IèŠçŽ ã®åºåã¯äž¡æ¹ãšãããŠããããã§ãã
ä»åãã æ®ãã®5ã€ã®ããžãã¯ãšã¬ã¡ã³ãã䜿çšããŠãããªãããŒãªåè·¯ãåéããŸãã 4ãš6ã®æ°åãæåŠããããšã«ããŸããïŒãã®å Žã§è»èŒªãåãã®ã¯ãªãã§ããïŒïŒïŒãã1ãš7ïŒå·ŠïŒã3ãš9ïŒå³ïŒã ãã®ã¿ãŒã³ã®ãã€ã¢ã°ã©ã ãäœæããããšããã§ããŸããã
ãã®çµæãããŒãäžïŒå¥ã®ãã®ãè³Œå ¥ããå¿ èŠããããŸããïŒãDTMFãã³ãŒããŒãã€ã³ãžã±ãŒã¿ãŒããã®ãã³ãŒããŒã10é²æ°ãã³ãŒããŒã4-ANDãNOTã4-ORãOR-NOTãAND-NOTã4ãã©ã³ãžã¹ã¿ã4ãªã¬ãŒã
ãã·ã³ã¯6ã€ã®ç°ãªãã³ãã³ããå®è¡ããŸãããå茪ãäžå€®ã«æ»ãæ¹æ³ãç¥ããŸããã LEGOããŒãã®å¹çãšäœãã¢ãŒã¿ãŒåºåã«ããããªã¿ãŒã³ã¹ããªã³ã°ããŽã ã¯äœ¿çšã§ããŸããã
ãªã¬ãŒã¯æã æ°åã¯ãªãã¯ããŸãããçç±ã¯æããã§ã¯ãããŸããïŒå¹²æžïŒïŒã
ããžãã¯ãæäœããããžãã¯ããã¹ã¿ãŒãããŸããã
3. STM32ã®äœ¿çšãéå§ãã
éçºç°å¢
é ç·ããã°ã©ãã³ã°ããã³ãŒãããã°ã©ãã³ã°ã«åãæ¿ããŸãããã ããã°ã©ã å¯èœãªãã€ã¯ãã³ã³ãããŒã©/ãããã«ã€ããŠã¯ãRaspberry Piã匷åããããArduinoãé«äŸ¡ã§ãããäžè¬çã§ã¯ãªããšããæŒ ç¶ãšããèããããããŸããã§ããã ãã®æã売ãæã§ããããã€ã«ã¯ã579ã«ãŒãã«ã®STM32VLDiscoveryãç§ã«æžããã ããã§ã®åœŒã«ã€ããŠã ãã§ãªã ã 圌ãããã§ã«æžãããã®ã§ããã圌ã®ç 究ã§æ¬åœã«å©ãã«ãªããŸããã
ã³ã³ãããŒã©ã¯ãã¬ããããŒãã«åºå®ã§ããŸããããããã«ãåºå®ã§ããŸããã åæã«ã6æ¬ã®è¶³ãã¶ãäžãã£ããŸãŸã«ãªããŸã-ãŸã æ°åæ¬ããã®ã§ããããã䜿ããã«è¡ãããšãã§ããŸãã ããã°ã©ã ãããã€ã¹ã«å ¥ã£ãããUSBã³ãŒãããããŒããåæããããšãªããã¡ã¢ãªã«ããŠã³ããŒããããããã°ã©ã ã®æ©èœã確èªããããšãã§ããŸãã ãããŠãããªãã¯ããããé£ã¹ãããšãã§ããŸãã
CooCoxã®CoIDEç°å¢ã§ã¯ãã¿ã³ããªã³ãšã®ãã³ã¹ã1åã ãå¿ èŠã§ãããç¹å®ã®ãã¡ã€ã«ãç¹å®ã®ãã©ã«ããŒã«æåã§ããŠã³ããŒãããããšã¯ãäœæ¥ãéå§ããããã®æé©ãªéžæã®ããã§ãã 確ãã«ããã¡ãŒã ãŠã§ã¢ãããã€ã¹ã«ã¢ããããŒãã§ããŸããã§ãããããŒãã¡ãŒã«ãŒã®ST-LINKãŠãŒãã£ãªãã£ã䜿çšããå¿ èŠããããŸãã 圌ãã¯äŸ¿å©ãªSublime Text 2ããçŽæ¥ã³ã³ãã€ã«ã§ãããšèšã£ãŠããŸãããåœä»€ã®é·ãã¯è©ŠããŠã¿ãã«ã¯ããŸãã«ãæççã§ããã
ç§ãCã§æžããããšããªãããšãèãããšãæãåçŽãªç¹æ» ããLEDã§ãã倧ããªå°é£ãåŒãèµ·ãããŸããã ããã«ãäžæçãªã¬ãžã¹ã¿ã16é²ã·ã¹ãã ããã«ã¢ããæµæåšã®ç®çãååã«ç解ããŠããªã人åãã®åºåãšå ¥åã®ããŸããŸãªåäœã¢ãŒã...ãããã誰ãã®æ¢è£œã®äŸã®ã³ããŒã¢ã³ãããŒã¹ãæ¹æ³ãããªãã¯ãè¡ããŸããã 次ã«ãããã€ã¹ã®äŸ¡æ Œã«ãããããŒããŠã§ã¢ã®æ£ããæ¥ç¶ã«ç ©ããããããšããªããªããŸãã ããšãã°ãåGNDèãã°ã©ãŠã³ãã«æ¥ç¶ããå¿ èŠããããã©ãããããã³4æ¬ã®æã®ããããªãŒããããã€ã¹ã«é»åãäŸçµŠããããšãæ害ãã©ããã¯ãŸã ããããŸããã§ããã
ã³ãŒãã«ããè¿ãã ããã§ã¯ä»ã®äººã®äŸãåŒçšããã説æãããã¯ããŸããããç§ã®ãã¹ããã©ã¯ãã£ã¹ãããã€ã玹ä»ããŸãã ãããã¯ãWebäžã®ç¹å®ã®åé¡ã«å¯Ÿãã蚱容å¯èœãªè§£æ±ºçããªãã£ããšãã«ç»å ŽããŸããã
ã¿ã¹ã¯6ïŒé 延
ããšãã°ãLEDããªã³ã«ãããã°ããããŠãããªãã«ããŸãã å€ãã®å Žåãé 延ã¯äœåãå®è¡ããã空ã®ã«ãŒãã«ãã£ãŠå®è£ ãããŸãã ãã®æ¹æ³ã¯ç¢ºãã«åçŽã§ãããLEDã®ç¹æ» ã«å ããŠãããŒãã«äœãå¿ èŠãªãå Žåã«ã®ã¿é©çšã§ããŸãã ãµã€ã¯ã«ã®ã¿ãäžæã§ããŸããããã¿ãŸããããäžæããïŒå°ãåŸã§ïŒãããµã€ã¯ã«ãçµäºããããã®è¿œå æ¡ä»¶ãèšå®ããŸãã ãã以å€ã®å Žåããã®ãµã€ã¯ã«ãç¶ãéãããŒãã¯äœããããäœã«ãåå¿ããŸããã
ç§ãææ¡ããã®ã¯ãããã°ã©ã ã§å¿ èŠãªãã¹ãŠã®é 延ã«å¯ŸããŠã¡ã€ã³ç¡éã«ãŒããããã«äœ¿çšããããšã§ããåãã¹ã¯ç¹å®ã®å€æ°ã®å€ãå¢ãããŸãïŒãxããšåŒã³ãŸãããïŒã å€æ°ãç¹å®ã®å€ã«éãããšããã«ããµã€ã¯ã«ã®æ¬äœã§ç¹å®ã®æ¡ä»¶ãããªã¬ãŒãããŸãïŒãã®æ°ã¯ããã€ã§ãå¯èœã§ãïŒã æ¬ ç¹ã¯ããã®ãããªé 延ãã©ããããç¶ãããäºåã«ç¥ããªãããšã§ãã ãããåé¡ã«ãªããªãå Žåã¯ãçµéšçã«å¿ èŠãªå€ãéžæããŠäœ¿çšããŸãã
ã³ãŒã
int main(void) { unsigned int x=0; char something; while(1) { if (x>5000) { // }; if (x==10000) { // . , x. }; if (something==1)// { x=0; // } if (x<15000) { x++; }; // x 0, x 15000. }; };
ã¿ã¹ã¯7ïŒæå®ãããééã§ã®éé
æ°Žæ¶æ¯ååãå€æŽãããããã»ããµãŒåšæ³¢æ°ã24 MHzã®ãŸãŸã§ãã£ããšããŸãã ç¹å¥ãªåœä»€ã«ãã£ãŠ2400çªç®ã®ããã»ããµãŒæ°ã«éãããšãã«å²ã蟌ã¿ãäœæããããšã«ããã100 Hzã®åšæ³¢æ°ïŒ10ããªç§ããšïŒã§TIM6_DAC_IRQHandleré¢æ°ïŒããã¯å²ã蟌ã¿ãã³ãã©ãŒïŒã®å®è¡ãååŸããŸãã 以äžã®ã³ãŒãã¯å ã ã©ããã§åãããŠããŸãã
ã³ãŒã
unsigned int ti=0; int main(void) { // 6 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE); TIM6->PSC = 24000 - 1; // 1000 TIM6->ARR = 10 - 1; // 10- TIM6->DIER |= TIM_DIER_UIE; // TIM6->CR1 |= TIM_CR1_CEN; // ! NVIC_EnableIRQ(TIM6_DAC_IRQn); // TIM6_DAC_IRQn }; // TIM6_DAC void TIM6_DAC_IRQHandler(void) { ti++; TIM6->SR &= ~TIM_SR_UIF; // }
ãã®å²ã蟌ã¿ã®äž»ãªç®çã¯ã10ããªç§ããšã«å¢å ããå€æ°tiã䜿çšããããšã§ãã ããã«ãå²ã蟌ã¿ã¯ã¡ã€ã³ããã°ã©ã ã³ãŒãã«ãããã³ãããããã ãã§ãªããå²ã蟌ã¿ãã³ãã©å ã§æ¯åå€åãããããå€æ°tiã®æ¯èŒãå²ãåœãŠã®æäœãæªããå¯èœæ§ãããããšãããããŸããã å¥ã®å€æ°ãå€æ°tiã®å€ã«å²ãåœãŠã代ããã«ãå€ãå€ã®äžéšãšæ°ããå€ã®äžéšãå²ãåœãŠãããç¶æ³ãçºçããå ŽåããããŸãã Webã§èŠã€ãã£ãåé¡ã®è§£æ±ºçã®äžã§ãç§ã¯ããã以äžã匷調ããŸããã
- ã¢ãããã¯æäœã®äœ¿çšïŒãããã¯äžæãããŸããïŒ-intåã®å²ãåœãŠã¯ããã§ã¯ãããŸãããããlongãåã䜿çšããå¿ èŠããããŸãã
- ç¹å®ã®åœä»€ã®å®è¡äžã«å²ã蟌ã¿ãæ©èœãããã©ããã確èªããããã®è¿œå ã®å€æ°ãŸãã¯ã¬ãžã¹ã¿ã®äœ¿çšã¯ãå°ãé¢åã§ãããããŸãæ確ã§ã¯ãããŸããïŒç§ã«ãšã£ãŠïŒã
- ãã®ä»ã®ãªãã·ã§ã³...
ãã®ãããªåé¡ã解決ããŸããã å€æ° "ti"ããä»£å ¥ãããããŸã§ãããŒã«ã«å€æ°stiã«å²ãåœãŠãŸãã 粟床ãåºæ¬çã§ãªãå Žåã¯ãå°ããããã¯ã©ãã·ã¥ããè¿œå ã§ããŸãã
do { sti=ti; } while (ti>1+sti);
ããŒã«ã«å€æ°stièªäœã¯ãå€æ°tiã®å€ãå¿ èŠãªå Žæã«åæ§ã®ã«ãŒããæ¿å ¥ããªãããã«ã®ã¿äœ¿çšãããŸãã
ããã«ããã°ã©ã ã§ã¯ãstiå€æ°ã«æããããšãªãã¢ã¯ã»ã¹ãããŒãã«ããããšããã§ããŸãã ãã®ãã¹ãŠã䜿çšããŠããã®ã³ãã³ããŸãã¯ãã®ã³ãã³ããã¿ã€ãã©ã€ã¿ãŒã«äžããããæéãä¿®æ£ããåŸã§ã¿ã€ãã©ã€ã¿ãŒãã«ãŒããç¹°ãè¿ãããšãã§ããããã«ããŸããã åœç¶ããŒãåã¯ç¡é§ã«ãã¹ãã§ã¯ãããŸããããããã£ãŠãã¡ã€ã³ããã°ã©ã ã«ãŒãã®æåŸã«ãç°¡åãªã³ãŒããè¿œå ãããŸããã
if (sti==0) { do { ti=0; } while (ti>1); }
å²ãåœãŠã®æç¹ãŸãã¯çµäºæ¡ä»¶ã®ãã§ãã¯æã«ãå€æ°tiãå€åãã誀ã£ã圢åŒã§ãæ瀺ãããããšããµã€ã¯ã«ãç¹°ãè¿ãããŸãã å²ã蟌ã¿ã¬ãŒããé«ãã»ã©ãã«ãŒããçµäºããæ¡ä»¶ã2åç®ã«ããªã¬ãŒãããé »åºŠãé«ããªããŸãã åœç¶ãäžæã®é »åºŠãé«ãããå Žåãã«ãŒãã¯é·ãããããŸããã 倱æããå²ãåœãŠã®è©Šè¡åæ°ãå¶åŸ¡ããããã«ãLEDã䜿çšããŸããã
ã¿ã¹ã¯8ïŒãã£ã¹ãã¬ã€ãšããŠã®LED
æã ãããã°ã©ã ã調æŽããããã«ãããã€ã¹ã®æäœäžã«ç¹å®ã®å€æ°ã®å€ãååŸãããã®ã§ããããã£ã¹ãã¬ã€ãã€ã³ãžã±ãŒã¿ãŒãæå ã«ãªãããããããæ¥ç¶ããããããŸããã ãã®åŸãLEDãå¿ èŠãªåæ°ã ãç¹æ» ãããããäžæåæ¢ããããå床ç¹æ» ããããããããšãã§ããŸãããããã®ç®çã®ããã«ãã¡ã€ã³ã«ãŒãã®æ¬æã§æ¬¡ã®ã³ãŒãã䜿çšããŸãã
// - if ((todisp>0) && (sti%10==0)) { if ((sti%(todisp*20+100)<todisp*20) && (sti%20<10)) { GPIOC->BSRR=GPIO_BSRR_BS8; } else { GPIOC->BRR=GPIO_BRR_BR8; }; };
ããã°ã©ã ã®ä»»æã®æç¹ã§ãå€æ°ãdispãããšãã°3ã«å²ãåœãŠãŸããããŒãäžã®LED No. 8ã3åç¹æ» ããã·ãªãŒãºéã§2åç®ã®äžæåæ¢ãè¡ããŸãã å€æ°stiã¯ïŒå€æ°tiãä»ããŠïŒ10ããªç§ããšã«ã€ã³ã¯ãªã¡ã³ããããŸããã代ããã«å€æ°xã䜿çšããŠãã¡ã€ã³ã«ãŒãã®åãã¹ã§ã€ã³ã¯ãªã¡ã³ãã§ããŸãã ãã®å Žåãä¿æ°ããããã«å¢ããå¿ èŠããããŸãã
䜿çšäŸ
while (1) { do { sti=ti; todisp++; } while (ti>1+sti); todisp--; if ((todisp>0) && (sti%10==0)) { if ((sti%(todisp*20+100)<todisp*20) && (sti%20<10)) { GPIOC->BSRR=GPIO_BSRR_BS8; } else { GPIOC->BRR=GPIO_BRR_BR8; }; }; }
ãã®äŸã§ã¯ãå²ã蟌ã¿ã®ããã«å²ãåœãŠæäœsti = tiã倱æããæ¯èŒæäœti> 1 + stiãtrueãè¿ããã³ã«ïŒæ¯èŒæã«å²ã蟌ã¿ãçºçããå Žåã«ãèµ·ãããŸãïŒãLEDã1åç¹æ» ããŸãå以äžã ååãšããŠãããŒãæäœã®nååŸã«LEDãç¹æ» ããåæ°ã枬å®ããå¹³åãµã€ã¯ã«æéïŒå²ã蟌ã¿ã®é »åºŠã«åºã¥ããŠïŒãèšç®ããããšãã§ããŸãããŸããå²ã蟌ã¿ã䜿çšããéã®ããããã¹ãŠã®äºé²æªçœ®ã決ããŠäžèŠã§ããããšã確èªã§ããŸãã
ã¿ã¹ã¯9ïŒãã€ã¯ãã³ã³ãããŒã©ãŒããã·ã³ã«æ¥ç¶ããŸã
LEDã§ååãªæ°ã®å®éšãè¡ã£ãåŸãåŸã ã«ãããããã€ãŒã«ã«å€æŽã§ããŸãã å€ãããŒã¹ããžãã¯åè·¯ããæãå¿ èŠãªãã®ã®ã¿ãååŸããŸããDTMFãã³ãŒããŒãçŸå®¹çšãã³ãŒããŒä»ãã€ã³ãžã±ãŒã¿ãŒããã©ã³ãžã¹ã¿ãŒä»ããªã¬ãŒã§ãã æåŸã«ã10é²ãã³ãŒããŒãå¿ããããšãã§ããŸãïŒ
DTMFãã³ãŒããŒããã®åºåã¯ããããã®ç®çã®ããã«éžæããã³ã³ãããŒã©ãŒã®å ¥åã«æ¥ç¶ãããŸãã ã³ã³ãããŒã©ãŒããã®åºåïŒåã³ãããã°ã©ã ã§éžæããã³åæåïŒããæµæåšïŒããšãã°ã3 kOhmïŒãä»ããŠåŸæ¥ã®NPNãã©ã³ãžã¹ã¿ãŒã®ããŒã¹ã«åºåïŒBC547ã䜿çšïŒã ãšããã¿ãŒ-ããã©ã¹ãã³ã¬ã¯ã¿ãŒ-察å¿ãããªã¬ãŒã®ã³ã€ã«ã ã¡ã€ã³ã¢ãŒã¿ãŒã®ã·ã§ãŒãïŒããã¬ãŒããã¢ãŒãïŒãé²ã5çªç®ã®ãªã¬ãŒãè¿œå ããæ¹åæ瀺åš/寞æ³ã奜ã¿ã«åãããŠèª¿æŽããŸãã ã¢ãŒã¿ãŒã®ããã©ã¹ãã¯ãå¥ã®ããããªãŒããã¯ãããªã¬ãŒã«æ¥ç¶ãããŸãã åè·¯ãšã¢ãŒã¿ãŒã®äž¡æ¹ã«é»åãäŸçµŠããããã«ãç§ã¯ãããã4æ¬ã®æé»æ± /èé»æ± çšã®ãã©ã¹ããã¯ã±ãŒã¹ïŒ2åïŒã䜿çšããŸãã 圌ãã¯ãã£ã40ã«ãŒãã«ã®è²»çšãããããåäŸã®é ç§ã¯ãã€ãã¹ã³ããããŒããšãã€ã«ã§èŠãããããŸãã...
DTMFãã³ãŒããŒããã®ã¯ã€ã€ããååŸã«ç§»åãããªã¬ãŒã®çäžãééããããšãå€æããŸããã ããããããã¯ããªã¬ãŒããªã³ã«ãªã£ããšãã«æ¢åã®é»åãµãŒãžã«å¹²æžãè¿œå ããŸãã ãã®çµæãã¯ã©ã¹ã¡ãŒããžã®ãã¬ãŒã³ããŒã·ã§ã³äžã«ããªã¬ãŒã¯å®æçã«å²ãå§ãããã·ã³ã¯ãŸã£ããæ»ãããšãæåŠããŸãã-ãªã¬ãŒã¯ãã³ã¹ãããã§åãæ¿ãããåäžãªå²ããçºããŸããã ããã©ã¹ãã®æ¹åã«ãªã¬ãŒã³ã€ã«ã«äžŠåã«æ¥ç¶ããããã€ãªãŒãã¯ããã®ç¶æ³ã«åœ±é¿ããŸããã§ããã ããã°ã©ã ããã¡ã€ãã©ã€ãºããŠããŸã-10ããªç§ããšã«å ¥åå€ããã§ãã¯ãã5ã€ã®å ¥åã®çµã¿åãããé£ç¶ããŠ6ååãå Žåã«ã®ã¿å€æŽã«åå¿ããŸãã ç®ã®é 延ã¯ã»ãšãã©æç¥ã§ãããå¹²æžã®åé¡ã¯è§£æ±ºãããŸãã ããããããã°ã©ããã«ãã€ã¯ãã³ã³ãããŒã©ãŒã®äž»ãªå©ç¹ã§ãïŒ
4.å茪ã®å転è§ã決å®ãã-ADCïŒã¢ããã°-ããžã¿ã«ã³ã³ããŒã¿ãŒïŒãä»ãããã£ãŒãããã¯
第äºéšã§ã¯ãå茪ãæ©æ¢°çã«äžå€®ã«æããããšã¯ã§ããªããšè¿°ã¹ãŸããã ãã·ã³ã¯çŽç·ã§èµ°è¡ã§ããã¯ããªã®ã§ãåé¡ã解決ããæãæ¥ãŸããïŒ
ã¿ã¹ã¯10ïŒã¬ãªã¹ã¿ãããæ¥ç¶ãã
解決çã¯ããèªäœã瀺åããŠããŸã-ã¹ããªã³ã°ã§ã¯ãªãå Žåããã€ãŒã«ãæãããŸã§ã¢ãŒã¿ãŒãå察æ¹åã«å転ãããŸãã æå ã«ã¯ããžã¿ã«ãšã³ã³ãŒãã¯ãããŸããããçŽ æŽããã10kΩã¬ãªã¹ã¿ããããããããŒãã«ã¯12ãããADCïŒ2ã§ãïŒããããã€ã³ã¿ãŒãããã«ã¯æ¥ç¶åè·¯ãšã³ãŒãããããŸãã ã¬ãªã¹ã¿ããã®ç«¯ãããã©ã¹ããšããã€ãã¹ãã«ãã¹ã©ã€ããŒ-1kΩæµæãä»ããŠå ¥åã«æ¥ç¶ããŸãã ãšããã§ãADCã®ç®çã®ããã«ãå ¥åã䜿çšããããšã¯ã§ããŸããã äŸã§æå®ããããã®ã䜿çšããŸããã ãµã³ãã«ã³ãŒãã¯ãADCãå«ãåã©ã€ãã©ãªã®CoIDEã§çŽæ¥èŠã€ããããšãã§ããŸãïŒCoIDEã§ADCã©ã€ãã©ãªãæ¥ç¶ããããšãå¿ããªãã§ãã ããïŒã ã³ããŒãšè²Œãä»ãã®ã³ãŒãã¯ç§ã®ããã°ã©ã ã«ãããæãéèŠãªããšã¯ããããæ©èœããããšã§ãã
ã¬ãªã¹ã¿ãããæ©æ¢°ã«åãä»ããã¬ãªã¹ã¿ããã·ã£ãããå転æ©æ§ã®ãæžéæ©ãã®åºåã·ã£ãããšå軞ã«æ¥ç¶ããŸããããã¯ã¢ãŒã¿ãŒãã3çªç®ã§ãã LEGO以å€ã®ããŒããšLEGOããŒãããã¢ãªã³ã°ããããã»ã¹ã¯åžžã«å®è¡ãããŸãããã¢ãŒã¿ãŒã¯äŸç¶ãšããŠã¬ãªã¹ã¿ãããå転ããããã€ãŒã«ãå転ãããŸãã å°é£ã䌎ããç§ã¯èšããªããã°ãªããªãã ã¬ãªã¹ã¿ããããããŒããŸã§3æ¬ã®ã¯ã€ã€ã䌞ã³ãã¢ãŒã¿ãŒãã4æ¬ã®ã¯ã€ã€ã䌞ã³ãŠããŸãã
ã¿ã¹ã¯11ïŒã¬ãªã¹ã¿ããããã®ããŒã¿ã䜿çšãã
çµéšçãªæ¹æ³ã§ã¯ã0ãã4095ã®æ°å€ãéžæããŸããããã¯ãå茪ãçŽæ¥åãä»ããå Žåã®å茪ã®å転è§ã®èš±å®¹ãããå·Šå³ã®å¢çã«å¯Ÿå¿ããŸãã ãã®ç¯å²ã¯äžæ垯ãšåŒã°ããŠããããã§ã-ãã®äžã§ãè»èŒªã¯äžå€®ã§æŽåããŠãããšèŠãªãããŸãã ãŸããæ倧å転è§ã«éãããšãã«ã¢ãŒã¿ãŒããªãã«ããå€ãéžæããŸããã
ã³ãŒã
js= 2500; // j â 0 4095 () gist=150; // full=500; // while (1) { //... if ((x>=max*7) && (inpok)) // inpok 0, . . if ((num==1) || (num==4) || (num==7)) // { GPIOC->BRR=GPIO_BRR_BR7; if (j>0+full) { GPIOC->BSRR=GPIO_BSRR_BS6; } else { if (j<0+full-gist) { GPIOC->BRR=GPIO_BRR_BR6; } } } else { GPIOC->BRR=GPIO_BRR_BR1; } if ((num==3) || (num==6) || (num==9)) // { GPIOC->BRR=GPIO_BRR_BR6; if (j<4250-full) { GPIOC->BSRR=GPIO_BSRR_BS7; // « » } else { if (j>4250-full+gist) { GPIOC->BRR=GPIO_BRR_BR7; // « » } } } else { GPIOC->BRR=GPIO_BRR_BR3; } // if ((num==2) || (num==5) || (num==8)) { if (j<js-gist*3) // { GPIOC->BRR=GPIO_BRR_BR6; // « » ( ) GPIOC->BSRR=GPIO_BSRR_BS7; // « » } else { if (j>js-gist*2) { GPIOC->BRR=GPIO_BRR_BR7; « » } }; if (j>js+gist*3) { GPIOC->BRR=GPIO_BRR_BR7; GPIOC->BSRR=GPIO_BSRR_BS6; } else { if (j<js+gist*2) { GPIOC->BRR=GPIO_BRR_BR6; } }; }; }; //.. }
æ©æ¢°ã極端ãªæ¡ä»¶ã§æäœããã巚倧ãªéè² è·ã®åœ±é¿äžã§ããã€ãŒã«ãé©åãªã³ãã³ããªãã§çªç¶å転è§åºŠãå€æŽãããšãåãã³ãŒããåžæã®äœçœ®ã«æ»ããŸãã ããšãã°ã4ãæŒãããã€ãŒã«ããã§ã«å·Šç«¯ã®äœçœ®ã«ããå Žåããªã¬ãŒã¯ãªã³ã«ãªããŸããã
æãåºããŠãã ãããããã€ãã®ã³ãŒãã¯ä»ã®èª°ãã®äŸããåãããŸããã
æ©æ¢°å¶åŸ¡ããã°ã©ã ã®æçµã³ãŒã
/** ***************************************************************************** * @title ADC_simple.c * @author Claude * @date 2010 Dec 29 * @brief ADC Example, Blink a LED according to ADC value ******************************************************************************* */ #include<stm32f10x_rcc.h> #include<stm32f10x_gpio.h> #include<stm32f10x_adc.h> #include "stm32f10x.h" #include "stm32f10x_conf.h" GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; unsigned int i,j,js,gist,full,ti=0; /* Blink a LED, blink speed is set by ADC value */ int main(void) { unsigned int x,max; unsigned int move[10]; unsigned int oldsti=0,sti=0,time[10],tit=0; unsigned short recheck=5; unsigned char todisp=0,todisp2=0; x=0; unsigned char ji,ju,inp0,inp1,inp2,inp3,inpok,ink,in0,in1,in2,in3,inok,num,oldnum,back; max=250; inp0=0; inp1=0; inp2=0; inp3=0; inpok=0; ink=0; back=0; num=0; void backreset(void) { back=0; for (ju=0;ju<10;ju++) { time[ju]=0; move[ju]=0; } GPIOC->BRR=GPIO_BRR_BR9; } GPIO_InitTypeDef PORT,GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); PORT.GPIO_Pin = (GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12| GPIO_Pin_8 | GPIO_Pin_9); PORT.GPIO_Mode = GPIO_Mode_Out_PP; PORT.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init( GPIOC , &PORT); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // A GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_9 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); PORT.GPIO_Pin = (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_5); PORT.GPIO_Mode = GPIO_Mode_Out_PP; PORT.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init( GPIOA , &PORT); // input of ADC (it doesn't seem to be needed, as default GPIO state is floating input) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; // that's ADC1 (PA1 on STM32) GPIO_Init(GPIOA, &GPIO_InitStructure); //clock for ADC (max 14MHz --> 72/6=12MHz) RCC_ADCCLKConfig (RCC_PCLK2_Div6); // enable ADC system clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); // define ADC config ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // we work in continuous sampling mode ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_RegularChannelConfig(ADC1,ADC_Channel_1, 1,ADC_SampleTime_28Cycles5); // define regular conversion config ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1 // enable ADC ADC_Cmd (ADC1,ENABLE); //enable ADC1 // ADC calibration (optional, but recommended at power on) ADC_ResetCalibration(ADC1); // Reset previous calibration while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); // Start new calibration (ADC must be off at that time) while(ADC_GetCalibrationStatus(ADC1)); // start conversion ADC_Cmd (ADC1,ENABLE); //enable ADC1 ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start conversion (will be endless as we are in continuous mode) // debug information RCC_ClocksTypeDef forTestOnly; RCC_GetClocksFreq(&forTestOnly); //this could be used with debug to check to real speed of ADC clock // 6 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE); TIM6->PSC = 24000 - 1; // 1000 // TIM6->ARR = 1000 ; // TIM6->ARR =4; TIM6->DIER |= TIM_DIER_UIE; // TIM6->CR1 |= TIM_CR1_CEN; // ! NVIC_EnableIRQ(TIM6_DAC_IRQn); // TIM6_DAC_IRQn j= 2500; js=j; gist=150; full=500; if (back==0) { for (ju=0;ju<10;ju++) { time[ju]=0; move[ju]=0; } } while (1) { // adc is in free run, and we get the value asynchronously, this is not a really nice way of doing, but it work! j = ADC_GetConversionValue(ADC1) ; // value from 0 to 4095 /* possible change : * ADC_ContinuousConvMode = DISABLE * then on the infinite loop, something like : * * ADC_SoftwareStartConvCmd(ADC1, ENABLE); // start ONE conversion * while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); // wait end of conversion * j = ADC_GetConversionValue(ADC1) * 500; // get value * */ do { sti=ti; } while (ti>1+sti); //if ((back!=2) || GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)) if (oldsti!=sti) { oldsti=sti; if (ink<recheck) { in0+=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_5); in1+=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6); in2+=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7); in3+=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8); inok+=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9); ink++; if (ink==recheck) { ink=0; if ((in0==0 || in0==recheck) && (in1==0 || in1==recheck) && (in2==0 || in2==recheck) && (in3==0 || in3==recheck) && (inok==0 || inok==recheck)) { if (in0==recheck) { in0=1; } if (in1==recheck) { in1=1; } if (in2==recheck) { in2=1; } if (in3==recheck) { in3=1; } if (inok==recheck) { inok=1; } if ((back==2) && (inok==1)) { backreset(); } if ( (back!=2) && (back!=4) && ((inp0!=in0) || (inp1!=in1) || (inp2!=in2) || (inp3!=in3) || (inpok!=inok)) ) { x=0; inp0=in0; inp1=in1; inp2=in2; inp3=in3; inpok=inok; oldnum=num; if (inp0) // - { if (inp1) { if (inp2) { if (inp3) { num=15; } else { num=7; }; } else { if (inp3) { num=11; } else { num=3; }; }; } else { if (inp2) { if (inp3) { num=13; } else { num=5; }; } else { if (inp3) { num=9; } else { num=1; }; }; }; } else { if (inp1) { if (inp2) { if (inp3) { num=14; } else { num=6; }; } else { if (inp3) { num=10; } else { num=2; }; }; } else { if (inp2) { if (inp3) { num=12; } else { num=4; }; } else { if (inp3) { num=8; } else { num=0; }; }; }; }; }; } in0=0; in1=0; in2=0; in3=0; inok=0; } } }; // if ((todisp>0) && (sti%10==0)) { if ((sti%(todisp*20+100)<todisp*20) && (sti%20<10)) { GPIOC->BSRR=GPIO_BSRR_BS8; } else { GPIOC->BRR=GPIO_BRR_BR8; }; }; if ((todisp2>0) && (sti%10==2)) { if ((sti%(todisp2*20+100)<todisp2*20) && (sti%20<10)) { GPIOC->BSRR=GPIO_BSRR_BS9; } else { GPIOC->BRR=GPIO_BRR_BR9; }; }; // if ((num==12)) { switch (back) { case 0: if (inpok) { back=3; }; break; case 3: if (!inpok) { back=4;ji=0;inpok=0;x=0; sti=0; }; break; default: ; } }; if (back==4) { if (inpok==0) { while ((move[ji]<1) && (ji<10)) { ji++; }; if ((ji<10)) { if ((sti>100)) { x=0; sti=0; num=move[ji]; tit=time[ji]; inpok=1; GPIOC->BRR=GPIO_BRR_BR8; GPIOC->BSRR=GPIO_BSRR_BS9; } } else { backreset(); } } else { if (sti>tit) { inpok=0; sti=0; x=0; ji++; GPIOC->BSRR=GPIO_BSRR_BS8; } } }; // if ((num==10)) { switch (back) { case 0: if (inpok) { back=1; }; break; case 1: if (!inpok) { back=2;ji=9;inpok=0;x=0; sti=0; }; break; default: ; } }; if (back==2) { if (inpok==0) { if ((ji>0) && (move[ji]>0)) { if ((sti>100)) { x=0; sti=0; num=move[ji]; if (num<4) { num+=6; } else { if (num>6) { num-=6; } } tit=time[ji]; inpok=1; GPIOC->BRR=GPIO_BRR_BR8; GPIOC->BSRR=GPIO_BSRR_BS9; } } else { backreset(); } } else { if (sti>tit) { inpok=0; x=0; sti=0; ji--; GPIOC->BSRR=GPIO_BSRR_BS8; } } }; // "*" if (num==11) { backreset(); } if ((x==3*max)) { GPIOC->BRR=GPIO_BRR_BR12; if ((!inpok) || (num<1) || (num>9)) { GPIOC->BRR=GPIO_BRR_BR6; GPIOC->BRR=GPIO_BRR_BR7; GPIOC->BRR=GPIO_BRR_BR10; GPIOC->BRR=GPIO_BRR_BR11; } if ((back!=2)&&(back!=4)) { in0=inp0; in1=inp1; in2=inp2; in3=inp3; inok=inpok; } if ((move[9]>0)&&(move[9]<10)&&(!inpok)&&(back!=2)&&(back!=4)) { for (ju=0;ju<9;ju++) { time[ju]=time[ju+1]; } time[9]=sti; }; }; if ((x==5*max) && (inpok)) { if ((1<=num) && (num<=9)&&(back!=2)&&(back!=4)) { for (ju=0;ju<9;ju++) // { move[ju]=move[ju+1]; } move[9]=num; sti=0; // , }; if ((num==1) || (num==2) || (num==3)) { GPIOC->BRR=GPIO_BRR_BR10; GPIOC->BSRR=GPIO_BSRR_BS11; GPIOC->BSRR=GPIO_BSRR_BS2; } else { GPIOC->BRR=GPIO_BRR_BR11; }; if ((num==7) || (num==8) || (num==9)) // { GPIOC->BRR=GPIO_BRR_BR11; GPIOC->BSRR=GPIO_BSRR_BS10; GPIOC->BSRR=GPIO_BSRR_BS2; } else { GPIOC->BRR=GPIO_BRR_BR10; }; }; if ((x>=max*7) && (inpok)) // inpok 0, . . { if ((num==1) || (num==4) || (num==7)) // { GPIOC->BRR=GPIO_BRR_BR7; if (j>0+full) { GPIOC->BSRR=GPIO_BSRR_BS6; } else { if (j<0+full-gist) { GPIOC->BRR=GPIO_BRR_BR6; } } } else { GPIOC->BRR=GPIO_BRR_BR1; } if ((num==3) || (num==6) || (num==9)) // { GPIOC->BRR=GPIO_BRR_BR6; if (j<4250-full) { GPIOC->BSRR=GPIO_BSRR_BS7; } else { if (j>4250-full+gist) { GPIOC->BRR=GPIO_BRR_BR7; } } } else { GPIOC->BRR=GPIO_BRR_BR3; } // if ((num==2) || (num==5) || (num==8)) { if (j<js-gist*3) // { GPIOC->BRR=GPIO_BRR_BR6; // « » ( ) GPIOC->BSRR=GPIO_BSRR_BS7; // « » } else { if (j>js-gist*2) { GPIOC->BRR=GPIO_BRR_BR7; « » } }; if (j>js+gist*3) { GPIOC->BRR=GPIO_BRR_BR7; GPIOC->BSRR=GPIO_BSRR_BS6; } else { if (j<js+gist*2) { GPIOC->BRR=GPIO_BRR_BR6; } }; }; }; if ((x==max*15)) { if (((num==1) || (num==2) || (num==3) || (num==5) || (num==7) || (num==8) || (num==9))&&(inpok)) // { GPIOC->BSRR=GPIO_BSRR_BS12; } else { GPIOC->BRR=GPIO_BRR_BR12; } x++; } else { x++; if (x>max*20+300000) { if (!inpok) { GPIOC->BRR=GPIO_BRR_BR2;// } x=max*20+1; } } // if (x%80000<40000) { if ((num%3==1) && (inpok) && (num<10)) { GPIOC->BSRR=GPIO_BSRR_BS1; } else { GPIOC->BRR=GPIO_BRR_BR1; } if ((num%3==0) && (inpok) && (num<10)) { GPIOC->BSRR=GPIO_BSRR_BS3; } else { GPIOC->BRR=GPIO_BRR_BR3; } } else { GPIOC->BRR=GPIO_BRR_BR1; GPIOC->BRR=GPIO_BRR_BR3; } if (sti==0) { do { ti=0; } while (ti>1); } }; return 0; }; // TIM6_DAC void TIM6_DAC_IRQHandler(void) { ti++; TIM6->SR &= ~TIM_SR_UIF; // UIF }
次ã®ããã«æ©èœããŸãã
5. DACïŒããžã¿ã«-ã¢ããã°ã³ã³ããŒã¿ãŒïŒã䜿çšããŠãµãŠã³ããåçãã
ADCã¯ãã¹ã¿ãªã³ã°ãããŠãããããDACã泚æããã«æŸçœ®ããªãã§ãã ããã æè²ã嚯楜ã®ç®çã§äœ¿çšããæãæçœãªæ¹æ³ã¯ãé³ãçæããããã«æããŸãã éçºé åºã¯å€å žçã§ããWebã§æ¢è£œã®ãµã³ãã«ãèŠã€ããŠå®è¡ããããããïŒããã³ãŒããå€æŽããŸãã
ã¹ããŒã«ãŒãNPNãã©ã³ãžã¹ã¿ã®ãã©ã¹ãšã³ã¬ã¯ã¿ã«æ¥ç¶ããŸãããDACãæµæãä»ããŠåºåãããã¬ãã°ããã®ä¿¡å·ã¯ããã©ã³ãžã¹ã¿ã®ããŒã¹ã«å°éããŸãã çè«çã«ã¯ãã¹ããŒã«ãŒã¯æ¥µæ§ãå€åããé³ã®åšæ³¢æ°ã®é»æ°ä¿¡å·ã§é§åãããŸãããã¹ããŒã«ãŒã«ã¯äžæ¹åã«ã®ã¿é»æµãäŸçµŠããŸãã 2ã€ã®ãã©ã³ãžã¹ã¿ã«ã€ããŠç°ãªãåè·¯ãè©ŠããŸããããé³ã«å€§ããªéãã¯èãããŸããã§ããã ãããããé©åãªã¹ããŒã ãèŠã€ããããªãã£ãã®ã§ãããã
æåã®é³ã¯ã ãã®äŸã䜿çšããŠååŸãããŸããã
ãµã³ãã«ã³ãŒã
#include "stm32f10x.h" #include "stm32f10x_rcc.h" #include "stm32f10x_gpio.h" /* , DAC */ const uint16_t sin[32] = { 2047, 2447, 2831, 3185, 3498, 3750, 3939, 4056, 4095, 4056, 3939, 3750, 3495, 3185, 2831, 2447, 2047, 1647, 1263, 909, 599, 344, 155, 38, 0, 38, 155, 344, 599, 909, 1263, 1647}; unsigned char i=0; int main(void) { /* */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* 6 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE); /* */ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); /* */ TIM6->PSC = 0; TIM6->ARR = 500; TIM6->DIER |= TIM_DIER_UIE; // TIM6->CR1 |= TIM_CR1_CEN; // ! NVIC_EnableIRQ(TIM6_DAC_IRQn); // TIM6_DAC_IRQn /* DAC1 */ DAC->CR |= DAC_CR_EN1; /* */ while (1) { } } /* 6 */ void TIM6_DAC_IRQHandler(void) { TIM6->SR &= ~TIM_SR_UIF; // UIF DAC->DHR12R1=sin[i++]; // if (i==32) i=0; // 32 }
ããã°ã©ã ã³ãŒãã«åºã¥ããŠé£åã®åšæ³¢æ°ãèšç®ããçµæããã¥ãŒããŒãšæ¯èŒãããšããã§ãããã ããã»ããµãŒåšæ³¢æ°ïŒ24,000,000 Hzã ã¿ã€ããŒTIM6-> PSCã¯ããŒãã«éãããšãªã»ãããããŸãã ãã¹ãŠã®ããŒãã ã¿ã€ããŒTIM6-> ARRã¯500ã«ã«ãŠã³ããããŸãã å²ã蟌ã¿ã¯ã501åç®ã®ãªã»ããããšã«ããªã¬ãŒãããŸãTIM6-> PSC-ãã®å ŽåãïŒ24 000 000 Hz / 1ïŒ/ 501â47 904 Hzã§ãã ããã¯ãå°æ¥ã®ãªãŒãã£ãªä¿¡å·ã®ãµã³ããªã³ã°åšæ³¢æ°ã§ã ã , - mp3 44 100 . , , â 16 12. , .
â , 32 sin. : 47 904 / 32 â 1 497 . ( 5 ), ⊠«!». F#6, , : 1 497,1 .
12:
ãªããªã , - . -, . , 5 , 10 . :
TIM6->PSC = 23; // 1 M
TIM6->ARR = 99; // PSC 23 ARR 99 100 (10 )
, , â 27,5 . , (440 , ), 11 ( ). ( 12 n ).
: , Excel . , . . , (), . 2 400 . Excel, , :
- , 12 ( ).
- ( â 27,5 ) (# â +1 , â +2 , â +12 ).
- , 10 000 , 10 000 .
- .
- 0 4095, .
. çµæïŒ
// const uint16_t noteC[]={ 76,2216,2383,2547,2709,2865,3017,3162,3299,3428,3547,3657,3755,3842,3917, 3979,4028,4064,4086,4095,4090,4070,4038,3991,3932,3860,3775,3679,3572, 3455,3328,3193,3050,2900,2744,2584,2419,2253,2085,1917,1749,1584,1422, 1264,1111,965,826,695,574,462,361,271,194,129,76,38,12,1,3,19,49,92,149, 218,300,393,498,613,738,871,1013,1161,1316,1475,1639,1805,1973 };
// const uint16_t noteCd[]={ 72,2226,2402,2576,2746,2911,3069,3220,3361,3493,3614,3722,3818,3901,3970, 4024,4063,4087,4095,4088,4065,4027,3974,3907,3825,3730,3622,3503,3372, 3231,3081,2924,2759,2590,2416,2239,2061,1883,1706,1532,1362,1196,1038, 887,744,612,490,381,284,200,130,75,35,10,0,6,27,64,116,182,263,357,464, 583,713,853,1002,1159,1323,1492,1666,1842,2020 }; const uint16_t noteD[]={ 68,2236,2423,2607,2786,2959,3124,3280,3425,3559,3680,3787,3879,3955,4016, 4059,4086,4095,4087,4061,4018,3959,3883,3792,3686,3566,3432,3288,3132, 2968,2795,2617,2433,2246,2057,1869,1682,1498,1318,1145,980,823,677,543, 421,314,221,143,82,38,10,0,7,32,74,133,207,298,403,523,655,799,954,1118, 1291,1469,1652,1839,2028 }; const uint16_t noteDd[]={ 63,2247,2445,2639,2828,3009,3181,3342,3490,3625,3745,3849,3935,4003, 4053,4084,4095,4087,4059,4012,3946,3862,3761,3643,3510,3363,3204, 3034,2854,2666,2473,2275,2076,1876,1678,1483,1293,1111,938,775, 625,488,366,260,171,100,48,14,0,6,31,76,139,220,319,434,565,710, 868,1037,1215,1402,1594,1792,1991 }; // const uint16_t noteE[]={ 60,2259,2469,2673,2872,3061,3239,3405,3556,3691,3809,3907,3986,4044,4080, 4095,4087,4058,4008,3936,3844,3733,3604,3458,3297,3122,2937,2741,2538, 2330,2119,1907,1697,1490,1289,1097,914,744,588,447,324,219,133,69,25, 3,3,24,68,133,218,323,446,586,742,912,1095,1287,1488,1694,1905 }; const uint16_t noteF[]={ 57,2272,2493,2709,2917,3115,3300,3470,3623,3756,3870,3961,4029,4074, 4094,4089,4060,4007,3930,3831,3710,3569,3410,3234,3044,2842,2631, 2413,2190,1965,1742,1522,1309,1104,911,731,567,421,295,189,106,47, 11,0,14,51,113,199,306,434,582,748,929,1123,1329,1543,1763,1987 }; const uint16_t noteFd[]={ 54,2285,2519,2747,2966,3172,3362,3536,3689,3820,3927,4008, 4063,4091,4092,4065,4010,3929,3823,3693,3540,3367,3177, 2971,2753,2526,2291,2054,1817,1582,1354,1135,929,738,564, 410,279,171,89,33,4,3,29,83,163,269,399,550,723,912,1118,1336,1563,1797,2034 }; const uint16_t noteG[]={ 51,2299,2547,2787,3016,3230,3426,3602,3754,3880,3978,4047,4086, 4094,4071,4017,3934,3822,3683,3519,3333,3127,2905,2670,2426,2176, 1924,1674,1430,1194,972,766,580,416,276,163,79,25,1,8,47,115,213, 338,490,665,861,1075,1303,1543,1791,2042 }; const uint16_t noteGd[]={ 48,2314,2576,2829,3068,3290,3492,3668,3817,3936,4023,4076, 4095,4079,4028,3944,3828,3681,3506,3307,3086,2848,2596, 2335,2069,1802,1540,1286,1045,821,618,440,288,167,78,22, 0,14,61,143,257,401,574,771,991,1228,1479,1739,2005 }; const uint16_t noteA[]={ 45,2330,2606,2872,3123,3353,3558,3734,3878,3987,4059,4092, 4087,4043,3961,3842,3689,3504,3292,3056,2801,2532,2253, 1970,1689,1415,1153,907,684,486,319,184,85,23,0,16,71, 163,292,454,646,865,1107,1366,1639,1919 }; const uint16_t noteAd[]={ 42,2346,2639,2918,3179,3416,3624,3798,3934,4030,4083,4093, 4059,3982,3864,3707,3514,3290,3039,2767,2480,2183,1883, 1587,1301,1031,782,561,371,218,103,30,1,15,72,172,313, 490,700,940,1203,1484,1777 }; const uint16_t noteH[]={ 40,2364,2673,2967,3238,3481,3690,3859,3985,4064,4095,4076, 4009,3894,3736,3536,3301,3036,2747,2441,2126,1809,1498,1199, 922,671,453,274,137,46,3,10,65,168,316,506,732,991,1274,1577,1890 }; const uint16_t noteP[]={ // 1,2048 };
, ( 1, 2, 4, 8 ..):
uint16_t mnote(const uint16_t *pa,char octave) // { int ii=0; do {ii=i;} while (ii!=i); ii=(octave*ii)%pa[0]; ii=*(pa+ii); return ii; }
i 100 :
/* 6 */ void TIM6_DAC_IRQHandler(void) { i++; TIM6->SR &= ~TIM_SR_UIF; // UIF }
, . , Nokia:
uint16_t *melody[]={ noteE,noteP,noteG,noteP, noteA,noteA,noteP,noteE, noteP,noteG,noteP,noteAd, noteA,noteA,noteP,noteP, noteE,noteP,noteG,noteP, noteA,noteA,noteP,noteG, noteP,noteE,noteP,noteP, noteP,noteP,noteP,noteP };
, ?..
(), , :
ã³ãŒã
uint16_t *melody2[]={ noteH,noteP,noteD,noteP, noteE,noteE,noteP,noteH, noteP,noteD,noteP,noteF, noteE,noteE,noteP,noteP, noteH,noteP,noteD,noteP, noteE,noteE,noteP,noteD, noteP,noteH,noteP,noteP, noteP,noteP,noteP,noteP }; uint16_t *melody3[]={ noteGd,noteP,noteH,noteP, noteCd,noteCd,noteP,noteGd, noteP,noteH,noteP,noteD, noteCd,noteCd,noteP,noteP, noteGd,noteP,noteH,noteP, noteCd,noteCd,noteP,noteH, noteP,noteGd,noteP,noteP, noteP,noteP,noteP,noteP };
( ). ãããïŒ 0 4095, . , , . 100 âŠ
.
#include "stm32f10x.h" #include "stm32f10x_rcc.h" #include "stm32f10x_gpio.h" int i=0; uint16_t current=0; int loccurrent=0; uint16_t mnote(const uint16_t *pa,char octave) // { int ii=0; do {ii=i;} while (ii!=i); ii=(octave*ii)%pa[0]; ii=*(pa+ii); return ii; } // 100 , 0 4095 // const uint16_t noteC[]={ 76,2216,2383,2547,2709,2865,3017,3162,3299,3428,3547,3657,3755,3842,3917,3979,4028,4064,4086,4095,4090,4070,4038,3991,3932,3860,3775,3679,3572,3455,3328,3193,3050,2900,2744,2584,2419,2253,2085,1917,1749,1584,1422,1264,1111,965,826,695,574,462,361,271,194,129,76,38,12,1,3,19,49,92,149,218,300,393,498,613,738,871,1013,1161,1316,1475,1639,1805,1973 }; // const uint16_t noteCd[]={ 72,2226,2402,2576,2746,2911,3069,3220,3361,3493,3614,3722,3818,3901,3970,4024,4063,4087,4095,4088,4065,4027,3974,3907,3825,3730,3622,3503,3372,3231,3081,2924,2759,2590,2416,2239,2061,1883,1706,1532,1362,1196,1038,887,744,612,490,381,284,200,130,75,35,10,0,6,27,64,116,182,263,357,464,583,713,853,1002,1159,1323,1492,1666,1842,2020 }; const uint16_t noteD[]={ 68,2236,2423,2607,2786,2959,3124,3280,3425,3559,3680,3787,3879,3955,4016,4059,4086,4095,4087,4061,4018,3959,3883,3792,3686,3566,3432,3288,3132,2968,2795,2617,2433,2246,2057,1869,1682,1498,1318,1145,980,823,677,543,421,314,221,143,82,38,10,0,7,32,74,133,207,298,403,523,655,799,954,1118,1291,1469,1652,1839,2028 }; const uint16_t noteDd[]={ 63,2247,2445,2639,2828,3009,3181,3342,3490,3625,3745,3849,3935,4003,4053,4084,4095,4087,4059,4012,3946,3862,3761,3643,3510,3363,3204,3034,2854,2666,2473,2275,2076,1876,1678,1483,1293,1111,938,775,625,488,366,260,171,100,48,14,0,6,31,76,139,220,319,434,565,710,868,1037,1215,1402,1594,1792,1991 }; // const uint16_t noteE[]={ 60,2259,2469,2673,2872,3061,3239,3405,3556,3691,3809,3907,3986,4044,4080,4095,4087,4058,4008,3936,3844,3733,3604,3458,3297,3122,2937,2741,2538,2330,2119,1907,1697,1490,1289,1097,914,744,588,447,324,219,133,69,25,3,3,24,68,133,218,323,446,586,742,912,1095,1287,1488,1694,1905 }; const uint16_t noteF[]={ 57,2272,2493,2709,2917,3115,3300,3470,3623,3756,3870,3961,4029,4074,4094,4089,4060,4007,3930,3831,3710,3569,3410,3234,3044,2842,2631,2413,2190,1965,1742,1522,1309,1104,911,731,567,421,295,189,106,47,11,0,14,51,113,199,306,434,582,748,929,1123,1329,1543,1763,1987 }; const uint16_t noteFd[]={ 54,2285,2519,2747,2966,3172,3362,3536,3689,3820,3927,4008,4063,4091,4092,4065,4010,3929,3823,3693,3540,3367,3177,2971,2753,2526,2291,2054,1817,1582,1354,1135,929,738,564,410,279,171,89,33,4,3,29,83,163,269,399,550,723,912,1118,1336,1563,1797,2034 }; const uint16_t noteG[]={ 51,2299,2547,2787,3016,3230,3426,3602,3754,3880,3978,4047,4086,4094,4071,4017,3934,3822,3683,3519,3333,3127,2905,2670,2426,2176,1924,1674,1430,1194,972,766,580,416,276,163,79,25,1,8,47,115,213,338,490,665,861,1075,1303,1543,1791,2042 }; const uint16_t noteGd[]={ 48,2314,2576,2829,3068,3290,3492,3668,3817,3936,4023,4076,4095,4079,4028,3944,3828,3681,3506,3307,3086,2848,2596,2335,2069,1802,1540,1286,1045,821,618,440,288,167,78,22,0,14,61,143,257,401,574,771,991,1228,1479,1739,2005 }; const uint16_t noteA[]={ 45,2330,2606,2872,3123,3353,3558,3734,3878,3987,4059,4092,4087,4043,3961,3842,3689,3504,3292,3056,2801,2532,2253,1970,1689,1415,1153,907,684,486,319,184,85,23,0,16,71,163,292,454,646,865,1107,1366,1639,1919 }; const uint16_t noteAd[]={ 42,2346,2639,2918,3179,3416,3624,3798,3934,4030,4083,4093,4059,3982,3864,3707,3514,3290,3039,2767,2480,2183,1883,1587,1301,1031,782,561,371,218,103,30,1,15,72,172,313,490,700,940,1203,1484,1777 }; const uint16_t noteH[]={ 40,2364,2673,2967,3238,3481,3690,3859,3985,4064,4095,4076,4009,3894,3736,3536,3301,3036,2747,2441,2126,1809,1498,1199,922,671,453,274,137,46,3,10,65,168,316,506,732,991,1274,1577,1890 }; const uint16_t noteP[]={ 1,2048 }; //, uint16_t *melody[]={ noteE,noteP,noteG,noteP, noteA,noteA,noteP,noteE, noteP,noteG,noteP,noteAd, noteA,noteA,noteP,noteP, noteE,noteP,noteG,noteP, noteA,noteA,noteP,noteG, noteP,noteE,noteP,noteP, noteP,noteP,noteP,noteP }; // uint16_t *melody2[]={ noteH,noteP,noteD,noteP, noteE,noteE,noteP,noteH, noteP,noteD,noteP,noteF, noteE,noteE,noteP,noteP, noteH,noteP,noteD,noteP, noteE,noteE,noteP,noteD, noteP,noteH,noteP,noteP, noteP,noteP,noteP,noteP }; // uint16_t *melody3[]={ noteGd,noteP,noteH,noteP, noteCd,noteCd,noteP,noteGd, noteP,noteH,noteP,noteD, noteCd,noteCd,noteP,noteP, noteGd,noteP,noteH,noteP, noteCd,noteCd,noteP,noteH, noteP,noteGd,noteP,noteP, noteP,noteP,noteP,noteP }; int main(void) { GPIO_InitTypeDef PORT; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); PORT.GPIO_Pin = (GPIO_Pin_9 | GPIO_Pin_8); PORT.GPIO_Mode = GPIO_Mode_Out_PP; PORT.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOC, &PORT); /* */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /* 6 */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE); /* */ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); TIM6->PSC = 23; // 24000-1 1000 TIM6->ARR = 99; // PSC 23 ARR 99 100 TIM6->DIER |= TIM_DIER_UIE; // TIM6->CR1 |= TIM_CR1_CEN; // ! NVIC_EnableIRQ(TIM6_DAC_IRQn); // TIM6_DAC_IRQn /* DAC1 */ DAC->CR |= DAC_CR_EN1; /* */ while (1) { GPIOC->BRR=GPIO_BRR_BR8; GPIOC->BSRR=GPIO_BSRR_BS9; do { loccurrent=i; } while (i!=loccurrent); // , GPIOC->BRR=GPIO_BRR_BR9; GPIOC->BSRR=GPIO_BSRR_BS8; current=(loccurrent/(2000))%32; // , 0 31. DAC->DHR12R1=(mnote(melody[current],1)+mnote(melody2[current],1)+mnote(melody[current],2)+mnote(melody2[current],2)+mnote(melody[current],4)+mnote(melody3[current],2))/6; } } /* 6 */ void TIM6_DAC_IRQHandler(void) { i++; TIM6->SR &= ~TIM_SR_UIF; // UIF }
, - ? ã¯ã
13:
, , STM32VLDiscovery, . :
1. Youtube Aston Martin.
2. ( ) .
3. ( Audacity ).
4. . 24 . , 2 , 2-3 -. .
5. WAV-.
6. ( WAV 2 TEXT) â -, . , .
7. 0 4095 Excel. 60 000 Notepad++ Sublime Text, . Excel 30 , â CoIDE âŠ
8. .
, over 9000 . :
, , , , , :
ãã®ãããªãã®ã