You are on page 1of 3

Timer Interrupt เรื่อง period เพี้ยน ชวยหนอยครับ Arduino 328 ETT - AVR - Electoday....

Page 1 of 3

สมัครสมาชิก เขาระบบ

คนหาอุปกรณ กระดานขาว คนหา โปรแกรมเสริม ถาม/ตอบ

Electoday.com » AVR » Timer Interrupt เรื่อง period เพี้ยน ชวยหนอยครับ Arduino 328 ETT

ตอบก เ ริ่ ม กลับไปหนารายชื่อกระทู

win360 โพสเมื่อ 2012-1-27 01:45 | แสดงเฉพาะของคนนี้ พิมพ ขนาดอักษร: 1#

Timer Interrupt เรื่อง period เพี้ยน ชวยหนอยครับ Arduino 328 ETT

แกไขลาสุด win360 เมื่อ 2012-1-27 13:32

มาใหม
คือ ผมใช Timer Interrupt แลวใหผลไมตรงกับคา period ที่ set เอาไวครับ
UID 8482 คา Period เปน 1000000 us หรือ 1 sec ทดลองบน Proteus ใหผลถูกตอง
กระทู 42 แตพอเอามาลงบอรดจริง ๆ period มันเพี้ยนไปเลย แบบ เร็วมาก ๆ ดูไมทันครับ
เครดิต 42 ผมใชบอรด ETT 328 นะครับ ใครรูวิธีแกรบกวนหนอยนะครับ
ผลงาน 42
Money 0
1. #include "TimerOne.h"
เพศ ชาย
2. void setup()
ออนไลน 24 ชั่วโมง
3. {
เขามาลา 2012-3-24
4. Timer1.initialize(1000000);
5. Timer1.attachInterrupt(callback);
6. Serial.begin(9600);
7. }
8.
9. void callback()
10. {
11. Serial.println("Serial Test");
12. }
13.
14. void loop()
15. {
16.
17. }
คัดลอกไปที่คลิปบอรด

ชอบ สงตอ นิยม

ตอบกลับ อางอิง ติดตามอาน TOP

samira โพสเมื่อ 2012-1-27 08:52 | แสดงเฉพาะของคนนี้ 2#

ไดลองทดสอบกับบอรด DFRduino UNO ใช code เดียวกน ก็ออกมาตรงดีนี่ครบ


ใช IDE รุน 0022 ครบ
เปลี่ยน code นิดเดียว ก็ออกมาตรงดีครับ

บรรณาธิการบริหาร
1. #include <TimerOne.h>
2.
UID 25
3. void setup()
กระทู 1858
4. {
เครดิต 1208
ผลงาน 1208 5. Timer1.initialize(1000000);
Money 0 6. Timer1.attachInterrupt(callback);
เพศ ชาย 7. Serial.begin(9600);
จาก 38.64°N 8. }
ออนไลน 1648 ชั่วโมง 9.
เขามาลา 2012-4-20
10. void callback()

http://www.electoday.com/bbs/viewthread.php?tid=16673 20/4/55
Timer Interrupt เรื่อง period เพี้ยน ชวยหนอยครับ Arduino 328 ETT - AVR - Electoday.... Page 2 of 3

11. {
12. Serial.println("Serial Test");
13. }
14.
15. void loop()
16. {
17. int count = 0;
18. while ( 1 ) {
19. Serial.println( "in loop");
20. delay( 500);
21. if ( count == 10) {
22. Timer1.stop();
23. while( 1) ;
24. }
25. else count++;
26. }
27. }
คัดลอกไปที่คลิปบอรด

ผลคือ

in loop
in loop
Serial Test
in loop
in loop
Serial Test
in loop
in loop
Serial Test
in loop
in loop
Serial Test
in loop
in loop
Serial Test
in loop

จะเห็นวา ทุกๆ 2 in loop นั้น จะมี 1 serial print


และเมื่อครบ สิบ มันก็หยุดจริงๆ

หากมีเวลาไปรื้อหา Diecimila จะทดสอบใหครบ

Be not afraid of growing slowly, be afraid of standing still.


Chinese proverb.

ตอบกลับ อางอิง TOP

sodanum โพสเมื่อ 2012-1-27 10:44 | แสดงเฉพาะของคนนี้ 3#

กองบรรณาธิการ

UID 1461
กระทู 1384
เครดิต 1288
ผลงาน 1288
Money 0
เพศ ชาย
ออนไลน 781 ชั่วโมง
เขามาลา 2012-4-20
เลนดวย

ลองกับ freeduino 328 ก็ปกติดีครับ print ออกมาทุกๆ 1 sec


ใช IDE รุน 0022 ....

http://www.electoday.com/bbs/viewthread.php?tid=16673 20/4/55
Timer Interrupt เรื่อง period เพี้ยน ชวยหนอยครับ Arduino 328 ETT - AVR - Electoday.... Page 3 of 3

I love arduino
ตอบกลับ อางอิง TOP

win360 โพสเมื่อ 2012-1-27 13:23 | แสดงเฉพาะของคนนี้ 4#

ขอบคุณครับ แกไดแลวครับ ผมลง IDE และ Library ใหมหมดเลย จาก ETT ผลการทดลองออกมาถูก
ตองครับ
แตก็ยังไมรูอยูดีวามันไปผิดพลาดอะไร

มาใหม

UID 8482
กระทู 42
เครดิต 42
ผลงาน 42
Money 0
เพศ ชาย
ออนไลน 24 ชั่วโมง
เขามาลา 2012-3-24

ตอบกลับ อางอิง TOP

กลับไปหนารายชื่อกระทู

Powered by Discuz! 7.0.0 Electoday Forum Provide by Micro4you.com | ติดตอเรา | สถิติบอรด | Archiver | WAP
© 2001-2009 Comsenz Inc. GMT+7, 2012-4-20 23:40, Processed in 0.055621 second(s), 7 queries, Gzip enabled.

http://www.electoday.com/bbs/viewthread.php?tid=16673 20/4/55

You might also like