03 การใช้งานพอร์ทอนาลอก
จากบล็อกไดอะแกรมใน https://sites.google.com/site/eplearn/vhdl_fpga/02-serial-port บอร์ด MOJO ใช้ชิป ATmega32u4 (3.3V, 8MHz) ซึ่งมีขาแบบแอนะล็อก-อินพุต จำนวน 8 ขา ตามรูป
การทดลองใช้พอร์ทอนาลอก
ต่อวงจรตามรูป ระวังแรงดันไฟต้องเป็น 3.3 V
จากหัวข้อการใช้งานพอร์ทอนุกรม เมื่อประกอบวงจร ลองปรับค่า Potentiometer (R ปรับค่าได้) จะเห็นได้ว่าการติดของ LED บนบอร์ดจะเปลี่ยนไป
โปรแกรมในส่วนที่เกี่ยวข้องกับ ADC นี้อยู่ในไฟล์ mojo_top.vhd
ตรงส่วน
channel <= "0000"; -- use channel 0 for this test (ADC0)
last_sample <= (others => '0');
led <= "11111111"; -- flash LEDs on reset
-
-
-
if new_sample = '1' then -- if there is a new sample available then
last_sample <= sample; -- put it into last_sample register
end if;
led <= last_sample(9 downto 2); -- display upper 8-bits of last 10-bit analog sample reading