ãããã£ãŠãäœæ¥ã®ç®æšïŒ PWMã®æŠå¿µãç¿åŸãããããLEDã®èŒåºŠã®å€æŽã«é©çšããããšã å®è£ ããã«ã¯ã Xilinx ISE Project Navigator v12.3éçºç°å¢ã§VHDLããã°ã©ãã³ã°èšèªã䜿çšããŸãã
ç®æšã®éæã«ç§»ããŸããã
å®è£ ã«ã¯ãFPGAãåããããŒããŠã§ã¢ãå¿ èŠã§ããæå ã«ããSpartan-3Eã¹ã¿ãŒã¿ãŒãããïŒ DataSheet ïŒãéžæããŸããã ã¶ã€ãªã³ã¯ã¹ISE Project Navigatorãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãïŒããŒãžã§ã³12.3ãã€ã³ã¹ããŒã«ãããŠããŸãïŒã åºæ¬çã«ããã¹ãŠãæ©èœããæºåãã§ããŠããŸãã é»æºãããŒãã«æ¥ç¶ããããã«ããã°ã©ãã³ã°ããããã«USBçµç±ã§ã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããããã ãã«æ®ããŸãã
ããŒã1. LEDã®èŒåºŠãå€æŽããçè«ã
LEDã®èŒåºŠã¯ãããŸããŸãªå€ã®å®é»å§ãïŒããšãã°ãå¯å€æµæåšã«ãã£ãŠïŒå°å ããããšã§èª¿æŽã§ããŸãã ããããããŒãã«ã¯å¯å€æµæåšã®ãªãLEDããããå€ã1ããåããå®å šãªæãããã€ãŸãã0ãã§ç¹ç¯ããŸãã ã§ã¯ããã®ãããªåçŽãªããã€ã¹ã®æãããã©ã®ããã«èª¿æŽããã®ã§ããããïŒ çãã¯PWMã§ãã å šäœã®ãã€ã³ãã¯ããã®LEDãéåžžã«éããç¹æ» ããããŠãç¹æ» ãç®ã«èŠããªãããšã§ãããèæãLEDã ããèŠããããšã§ãã ããæ£ç¢ºã«ã¯ãç¹ç«äžã«LEDã«éæž¡çŸè±¡ãçºçãããã€ãŸãç¬æã«ç¹ç¯ããªããšããããšã§ãã ããã¯ç§ãã¡ã䜿çšãããã®ã§ãéåžžã«çãæéã ããŠãããã䜿çšãããããLEDãæ倧ã®æããã§ç¹ç¯ããæéã¯ãããŸããã
ããŒã2.æ°ãããããžã§ã¯ãã®äœæã
ISE Project NavigatorãããŠã³ããŒããã[ãã¡ã€ã«]-> [æ°ãããããžã§ã¯ã]ãéžæããŸãã ãããžã§ã¯ãã®ååãæžãïŒshim_habrããããŸãïŒãä¿åãããã£ã¬ã¯ããªãéžæããäžãã[ãããã¬ãã«ãœãŒã¹ã¿ã€ãïŒHDL]ãéžæããŸãã 次ãžãã¯ãªãã¯ããŸãã
次ã«ãFPGAãéžæããŸãã ç§ã®å Žåã家æïŒSpartan3E; ããã€ã¹ïŒXC3S500E; ããã±ãŒãžïŒFG320; é床ïŒ-4ã ãããã®ããŒã¿ã¯ãã¹ãŠããããèªäœã«è¡šç€ºãããããããŒã¿ã·ãŒãã§ç¢ºèªã§ããŸãã
次ã«ãPreferred LanguageïŒVHDLãéžæããNextãã¯ãªãã¯ããŠããFinishãã¯ãªãã¯ããŸãã
ãããžã§ã¯ããäœæãããŸãã 次ã«ãã¢ãžã¥ãŒã«ãè¿œå ããå¿ èŠããããŸããããã§ãLEDã®ããžãã¯ã説æããŸãã å·Šäžã®[æ°ãããœãŒã¹]ãã¿ã³ãèŠã€ããŠã¯ãªãã¯ããŸãã
衚瀺ããããŠã£ã³ããŠã§ãVHDLã¢ãžã¥ãŒã«ãéžæããä»»æã®ãã¡ã€ã«åãæžã蟌ã¿ãŸãïŒshim_habrãããžã§ã¯ãã§ååãä»ããããšãã§ããŸãïŒã 次ãžãã¯ãªãã¯ããŸãã
次ã«ããããžã§ã¯ãã§äœ¿çšããèãèšå®ããå¿ èŠããããŸãã ä»ãããå®è¡ããŠãã®ã¹ããããã¹ãããããŠããããã¹ãŠãæã§æžãããšã¯ã§ããŸããã ãããããããžã§ã¯ãã«ã¯3æ¬ã®è¶³ããå¿ èŠãªããããããã«è¶³ãå ¥ããŸããã ãã®ãããFPGAã«æ¥ç¶ããã50 MHzããŒãã«åãä»ããããã¯ã©ãŒãããC9ãšããååã®èãŸã§ã®åºæºåšæ³¢æ°ãå¿ èŠã§ãããŸããããŒãã«æ¢ã«åãä»ããããŠãã2ã€ã®LEDã䜿çšããŸãã ããããE12ããã³F12ãšããååã§FPGAã¬ãã°ã«æ¥ç¶ããã2ã€ã®å³åŽã®LEDã§ãããšããŸãã ã¯ã©ãŒãã¬ãã°clkãåŒã³åºããæ¹åïŒINãèšå®ããŸã åšæ³¢æ°ãèªã¿åããŸããLEDã®ããèã¯led1ãšled2ã§ãããå€ã¯DirectionïŒOUTã§ãã ãããã管çããŸãã
[次ãž]ã[å®äº]ã®é ã«ã¯ãªãã¯ããŸãã ãããžã§ã¯ãã®I / OããŒãããã§ã«å ¥åããããéããããã¹ããšãã£ã¿ãŒã衚瀺ãããŸãã
ãšã³ãã£ã㣠shim_habr ã¯
ããŒã ïŒ clk ïŒ STD_LOGIC ;
led1 ïŒ STD_LOGICãã ;
led2 ïŒ STD_LOGICãã ïŒ
shim_habrãçµäºããŸãã
åã«èšã£ãããã«ãåã®æé ãã¹ãããããŠããã¹ãŠæåã§å ¥åã§ããŸãã 次ã«ãããŒãåãFPGAã¬ãã°ã®ååã«ãããããå¿ èŠããããŸãã éå±€å ã®ãã¡ã€ã«åshim_habr.vhdãå³ã¯ãªãã¯ãã[æ°ãããœãŒã¹]ãéžæããŸãã
éãããŠã£ã³ããŠã§ãImplementation Constrains Fileãéžæãããã®ãã³ãã¡ã€ã«ãåŒã³åºããŸãã [次ãž]ã[å®äº]ã®é ã«ã¯ãªãã¯ããŸãã
éãã空ã®ãã¡ã€ã«ã«ã次ã®ããã«èšè¿°ããŸãã
NET "clk" LOC = "C9" ;
NET "led1" LOC = "F12" ;
NET "led2" LOC = "E12" ;
ä¿åããŸãã
ããŒã¿ã·ãŒãã§èã®çªå·ãèŠãããšãã§ããŸãããŸãã¯ããã®å Žåãæ€çŽ¢ãç°¡çŽ åããŸãããå¿ èŠãªåšèŸºæ©åšã®é£ã®ããŒãã§çŽæ¥çªå·ãèŠãããšãã§ããŸãã
ããŒã3. LEDã®äžå®ã®èŒåºŠã®ããã°ã©ãã³ã°ã
shim_habr.vhdãã¡ã€ã«ã«åãæ¿ããŠãã³ãŒããèšè¿°ããŸãã
ã¢ãŒããã¯ã㣠shim_habrã®åäœã¯
å®æ° clk_freq ïŒ integer ïŒ= 50 _000_000 ; -ã¯ã©ãŒãåšæ³¢æ°
å®æ° shim_freq ïŒ integer ïŒ= 10 _000 ; -PWMåšæ³¢æ°
å®æ° max_count ïŒ æŽæ° ïŒ= clk_freq / shim_freq ; -PWM容é
ã·ã°ãã«æ°ïŒ æŽæ° ç¯å² 0 ãã max_count ïŒ= 0 ; -ååšåšã«ãŠã³ã¿ãŒ
å®æ° porog ïŒ integer ïŒ= max_count / 48 ; -è«çãŠãããã®ãã«ã¹å¹
å§ãã
ããã»ã¹ ïŒ clk ïŒ
å§ãã
rising_edge ïŒ clk ïŒã® å Žå
count = max_countã®å Žå
ã«ãŠã³ã<= 0 ;
ä»ã«
ã«ãŠã³ã<=ã«ãŠã³ã+ 1 ;
çµäºãã å Žå ;
çµäºãã å Žå ;
çµäº ããã»ã¹ ã
ã«ãŠã³ã< porog else ' 0 'ã®å Žåã led1 <= ' 1 ' ã
led2 <= ' 1 ' ;
ããã€ãã¢;
次ã«ããã®ã³ãŒããäœãããã®ãèŠãŠã¿ãŸãããã ãŸããè¡led2 <= '1'ã«æ³šæããŠãã ããã 2çªç®ã®LEDãæ倧èŒåºŠã§ç¹ç¯ãããããã«è«çãŠããããæäŸããŸãããã®ãããæåã®LEDã®ã°ããŒã®èŒåºŠãšæ¯èŒãããã®ããããŸãã 次ã«ã宣èšãããã¬ãžã¹ã¿ãšå®æ°ã確èªããŸãã clk_freqå®æ°ã¯ãã¯ã©ãŒãã®åšæ³¢æ°ããã«ãã§ä¿åããŸãã shim_freqã¯ããã«ãåäœã®PWMã®åšæ³¢æ°ã§ãã ãããã£ãŠãå¿ èŠãªPWMåšæãååŸããã«ã¯ãã¯ããã¯åšæ³¢æ°ãPWMåšæ³¢æ°ã§é€ç®ããå¿ èŠããããPWMåšæã«å¯Ÿå¿ããã¡ã€ã³ã¯ã©ãŒãã®ã¯ããã¯ãµã€ã¯ã«æ°ãååŸããŸãã æ¬è³ªçã«ãããã¯PWMã®å¹ ã«ãªããŸãã é€ç®ã®çµæã¯ãå®æ°max_countã«æžã蟌ãŸããŸãã 次ã«ãã«ãŠã³ã¿ãŒã«ãŠã³ããäœæããŸããããã¯ã50 MHzã®åšæ³¢æ°ã§0ããmax_countãŸã§åŸªç°ããŸãã ããã»ã¹ããã»ã¹ïŒclkïŒãäœæããŸãã rising_edgeïŒclkïŒãã¯ã©ãŒãããã®æ¬¡ã®ããã£ãã¯ããåŸ ã€å Žåã®æ¡ä»¶ã¯ãçºçããå ŽåããŠãããã«ã«ãŠã³ããè¿œå ããæ倧å€ãŸã§ã«ãŠã³ããããã©ããã確èªããŸãã 次ã«ãããã»ã¹ã®å€ã§ã次ã®è¡ãæžããŸãã
ã«ãŠã³ã< porog else ' 0 'ã®å Žåã led1 <= ' 1 ' ã
ã€ãŸããã«ãŠã³ã¿ãŒãããã€ãã®ãããå€porogå€ïŒç§ã«ãšã£ãŠã¯æéå šäœã®1/48ãå®æ°ã®å®£èšãåç §ïŒããå°ããå Žåãè«çãŠãããã¯LEDã§ãã³ã°ããLEDã®æ®ãã®æéã¯è«çãŒãããã³ã°ããŸãã ããã¯å³ã«æ確ã«ç€ºãããŠããŸãã
ããŒã4.ãã¡ãŒã ãŠã§ã¢ã
ãã¹ãŠã®å€æŽãä¿åããéå±€å ã®shim_habr.vhdãã¡ã€ã«ãéžæããéå±€ã®äžããã¿ãŒã²ããããã€ã¹ã®æ§æããã»ã¹ãæ¢ããŠéå§ããŸãã ãããžã§ã¯ãããã¡ãŒã ãŠã§ã¢ãã¡ã€ã«ã«å€æãããã®ãåŸ ã¡ãŸãããã®åŸãiMPACTããã°ã©ã ãŠã£ã³ããŠãéããFPGAã«çž«ãä»ããããŸãã
[Boundary Scan]ãããã«ã¯ãªãã¯ããŸããããŒããUSBçµç±ã§ã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ãããŠããå Žåã次ã®ãããªãã®ã衚瀺ãããŸãã
xc3s500eã®ãã¡ãŒã ãŠã§ã¢ãã¡ã€ã«ãéžæããããã«ææ¡ãããŠããªãå Žåã¯ãé©åãªãã€ã¯ããµãŒããããå³ã¯ãªãã¯ããŠã[æ§æãã¡ã€ã«ã®å²ãåœãŠ]ã¡ãã¥ãŒé ç®ãéžæããŸãã ãã¡ã€ã«éžæãŠã£ã³ããŠã§ãæ°ããäœæãããshim_habr.bitãéžæããŸãã 次ã«ãxc3s500eãå³ã¯ãªãã¯ããŠãããProgramãéžæããŸãã ãã¡ãŒã ãŠã§ã¢ããã»ã¹ãéå§ãããProgram Successfulã衚瀺ãããŸãã ãã¹ãŠããã®ããã«ãªã£ãå Žåãã¹ã«ãŒããèŠãããšãã§ããŸã=ïŒ
ããŒã5. LEDã®èŒåºŠã®æ»ãããªå€åã®ããã°ã©ãã³ã°ã
ãããã£ãŠã2ã€ã®LEDãç¹ç¯ããŠããããšãããããŸãã1ã€ã¯æããããã1ã€ã¯æãã§ãã ããã§ã¯ãæãããæ»ããã«å€ããŠã¿ãŸãããã ãããè¡ãã«ã¯ãporogãå®æ°ã§ã¯ãªãå€æ°ã«ããæå°ããæ倧ã«ã¹ã ãŒãºã«å€æŽããå¿ èŠããããŸãã
ã·ã°ãã« porog ïŒ æŽæ° ç¯å² 0 ãã max_count ïŒ= 0 ;
ãããå€ã®å€åçãèšå®ããã«ã¯ãåã³ã¯ããã¯åšæ³¢æ°ãååšããããå°ããåšæ³¢æ°ãååŸããå¿ èŠããããŸãã ããšãã°ããããå€ã1/600ç§ããšã«1ãã€å¢ãããããšããŸãã ã«ãŠã³ã¿ãŒãäœæããŸãã
å®æ° max_count_div ïŒ æŽæ° ïŒ= clk_freq / 600 ;
ã·ã°ãã« count_div ïŒ æŽæ° ç¯å² 0 ãã max_count_div ïŒ= 0 ;
ãŸãã次ã®ãtickãã®å Žåã«ããã»ã¹ïŒclkïŒã«è¿œå ããå Žåãrising_edgeïŒclkïŒã®å Žåã¯å¥ã®æ¡ä»¶ïŒ
count_div = max_count_divã®å Žå
count_div <= 0 ;
-ããã§ã¯ãé »åºŠã¯600ã«åå²ãããŸãã
ä»ã«
count_div <= count_div + 1 ;
çµäºãã å Žå ;
ããã§ãé »åºŠã600ã§å²ã£ãå Žæã«æžã蟌ã¿ããããå€ã1å¢ãããå€ãæ倧ã«éããã0ã«ãªã»ããããå¿ èŠããããŸãã
porog = max_countã®å Žå
porog <= 0 ;
ä»ã«
porog <= porog + 1 ;
çµäºãã å Žå ;
ãã®çµæãå šäœåã¯æ¬¡ã®ããã«ãªããŸãã
ã¢ãŒããã¯ã㣠shim_habrã®åäœã¯
å®æ° clk_freq ïŒ integer ïŒ= 50 _000_000 ; -ã¯ã©ãŒãåšæ³¢æ°
å®æ° shim_freq ïŒ integer ïŒ= 10 _000 ; -PWMåšæ³¢æ°
å®æ° max_count ïŒ æŽæ° ïŒ= clk_freq / shim_freq ; -PWM容é
ã·ã°ãã«æ°ïŒ æŽæ° ç¯å² 0 ãã max_count ïŒ= 0 ; -ååšåšã«ãŠã³ã¿ãŒ
ã·ã°ãã« porog ïŒ æŽæ° ç¯å² 0 ãã max_count ïŒ= 0 ; -è«çãŠãããã®ãã«ã¹å¹
å®æ° max_count_div ïŒ æŽæ° ïŒ= clk_freq / 600 ;
ã·ã°ãã« count_div ïŒ æŽæ° ç¯å² 0 ãã max_count_div ïŒ= 0 ;
å§ãã
ããã»ã¹ ïŒ clk ïŒ
å§ãã
rising_edge ïŒ clk ïŒã® å Žå
count = max_countã®å Žå
ã«ãŠã³ã<= 0 ;
ä»ã«
ã«ãŠã³ã<=ã«ãŠã³ã+ 1 ;
çµäºãã å Žå ;
count_div = max_count_divã®å Žå
count_div <= 0 ;
porog = max_countã®å Žå
porog <= 0 ;
ä»ã«
porog <= porog + 1 ;
çµäºãã å Žå ;
ä»ã«
count_div <= count_div + 1 ;
çµäºãã å Žå ;
çµäºãã å Žå ;
çµäº ããã»ã¹ ;
ã«ãŠã³ã< porog else ' 0 'ã®å Žåã led1 <= ' 1 ' ã
led2 <= ' 1 ' ;
ããã€ãã¢;
ç§ãã¡ã¯æŸéããçž«ããæåããŸãã =ïŒã»ãšãã©ã®å ŽåãLEDã¯æããç¹ç¯ãããµã€ã¯ã«ã®éå§æã«ã®ã¿æããªããšèãããããããŸããã ã«ã©ãŒãã¥ãŒãžãã¯ã«é¢ãã以åã®èšäºã§ãã®å¹æã«ã€ããŠãã§ã«æžããã äºå®ã¯ãæããããããå€ã«ç·åœ¢ã§ã¯ãªãã察æ°ã«äŸåãããšããããšã§ãã ã€ãŸããããšãã°ã1024ãããã®PWMã䜿çšããŠæãããæå°ããæ倧ã«ã¹ã ãŒãºã«å€åãããã«ã¯ãporogå€æ°ã®æ¬¡ã®å€ãé£ç¶ããŠååŸããå¿ èŠããããŸãïŒ0ã16ã32ã64ã128ã256ã512ã1024ã
宿é¡ã
ã芧ã®ãšãããLEDã¯åŸã ã«æãããå¢ããŠããããã€ã€ã«ããããšããã«0ã«ãªã»ãããããŸãïŒå®éãæžã蟌ã¿ãšååŸãå®äºããŸããïŒã ã¯ãŒã¯ã¢ãŠããšããŠãæ»ãããªæããã®ã»ãããäœæããæ倧ã®éå§ç¹ã«éãããšãæ»ããã«ãŒãã«æžå°ãããããšãã§ããŸãã ãã®ã¿ã¹ã¯ã«ç°¡åã«å¯ŸåŠã§ãã人ã®ããã«ã8ã€ã®äœ¿çšå¯èœãªLEDã®ãã©ã³ãã³ã°ã©ã€ãããäœæããããšãã§ããŸããæåã®ãã€ãªãŒããç¹ç¯ããŠæ¶ç¯ãã2çªç®ã®ãã€ãªãŒããç¹ç¯ããŸãã ããŸããããªããããããããå Žåã¯è³ªåããŠãã ãããçããŠèª¬æããããšããŸãã
ãããã«
ãã®ãããLEDãžã®PWMã®å¿çšãç¿åŸããFPGAã䜿çšããŠLEDã®èŒåºŠã調æŽããããšãåŠã³ãŸããã åãæ¹æ³ã䜿çšããŠããšã³ãžã³ã®é床ãã³ã€ã«ã®ç£åãªã©ãå¶åŸ¡ã§ããŸãã
FPGAã®ç¿åŸã«ãæåããç¥ãããŸãïŒ
PSïŒç³ãèš³ãããŸããããä»äºã§ãã®èšäºã®ãããžã§ã¯ãã®ãœãŒã¹ãå¿ããŠããŸããŸãã...ããããæŸãäžãããããã«æçš¿ããŸãïŒèªå® ã«ã¯äœãã€ã³ã¹ããŒã«ãããŠããŸããïŒã ãã ãã圌ã¯ããã§ã¯æ¬åœã«å¿ èŠã§ã¯ãããŸããããã¹ãŠãå¿ èŠã§ãïŒã§ããã°ãå¿ èŠã§ãïŒïŒã
UPDïŒ çŽæããããœãŒã¹ ã