Atmega328P Datasheet 14. PM - Power Management and Sleep Modes

Started by tha, November 01, 2017, 11:51:44 AM

Previous topic - Next topic

tha

รอตัวโปรแกรม ET-AVR ISP mkII ยังไม่ได้สักที จะขึ้นเรื่องใหม่เรื่อง clock ก็ยังไม่จบ ยังไม่ได้ลองกับตัวเอง จะขึ้นเรื่องใหม่ก็จะมั่วกันไปมา พรายกระซิบบอกให้ขึ้นหัวข้อใหม่แยกกันไปเลย จะได้ไม่สับสน ก็ดีเหมือนกัน

14. PM - Power Management and Sleep Modes

14.1. Overview
Sleep modes ทำให้ the application สามารถ shut down โมดูลที่ไม่ได้ใช้งานใน the MCU,  ซึ่งช่วยประหยัดพลังงาน. The device จัดให้มี sleep modes อย่างหลากหลายทำให้ผู้ใช้สามารถปรับการใช้พลังงานให้เหมาะสมกับความต้องการใช้งาน

เมื่อเปิดใช้งาน, the Brown-out Detector (BOD) จะโมนิเตอร์ตรวจสอบ the power supply voltage ในระหว่าง the sleep periods. เพื่อประหยัดพลังงานมากขึ้นคุณสามารถปิดการใช้งาน the BOD ในบาง sleep modes. ดูที่หัวข้อ BOD Disable ด้วย.
Note: BOD disable มีให้ใช้แต่ใน ATmega328P เท่านั้น.

14.2. Sleep Modes
ตารางต่อไปนี้แสดง sleep modes ต่างๆ, ความสามารถของ BOD disable และ wake-up sources ของพวกมัน.



Note:
1. แนะนำเฉพาะกับ external crystal หรือ resonator ถูกเลือกเป็น clock source เท่านั้น.
2. ถ้า Timer/Counter2 กำลังรันใน asynchronous mode.
3. สำหรับ INT1 และ INT0, มีเพียง level interrupt เท่านั้น

เพื่อที่จะเข้า the six sleep modes ใดโหมดหนึ่ง, the Sleep Enable bit ใน the Sleep Mode Control Register (SMCR.SE) ต้องถูกเขียนให้เป็น '1' และ a SLEEP instruction ต้องถูกปฏิบัติ. Sleep Mode Select bits (SMCR.SM[2:0]) ที่เลือก sleep mode ใดโหมดหนึ่ง(Idle, ADC Noise Reduction, Power-down, Power-save, Standby, or Extended Standby) จะถูกทำให้เป็นผลโดยคำสั่ง the SLEEP instruction.

หมายเหตุ: The block diagram ใน the section System Clock and Clock Options จัดให้มีภาพรวมที่คอบคุม the different clock systems ต่างๆใน the device, และการแจกจ่ายของมัน. รูปนี้เป็นตัวช่วยในการเลือก an appropriate(ที่เหมาะสม) sleep mode.

ถ้า an enabled interrupt เกิดขึ้นขณะที่ the MCU อยู่ใน a sleep mode, the MCU จะ wakes up. จากนั้นThe MCU จะหยุดเป็นเวลา 4 cycles นอกเหนือจาก the start-up time, การปฏิบัติ the interrupt routine, และหวนคืนปฏิบัติการคำสั่งที่ต่อจาก SLEEP. สิ่งที่บรรจุอยู่ใน the Register File and SRAM จะไม่เปลื่ยนแปลงเมื่อ the device ตื่นจาก sleep. ถ้า a reset เกิดขึ้นในระหว่าง sleep mode, the MCU จะ wakes up และปฏิบัติการจาก the Reset Vector.

9arduino


tha

พรายกระซิบมาบอกว่าให้เรียงลำดับไป ไม่เอาข้าม เลยไล่มาตามคำขอ ก็ดีเหมือนกัน ข้ามไปบางทีก็ไม่รู้เรื่อง  :)

14.3. BOD Disable
เมื่อ the Brown-out Detector (BOD) ถูกเปิดใช้งานโดย BODLEVEL fuses (ดูที่ section Fuse Bits ด้วย), the BOD จะทำงานคอยตรวจสอบ the power supply voltage ในระหว่าง a sleep period. เพื่อประหยัดพลังงาน, มันสามารถปิดการใช้งาน the BOD โดย software สำหรับบาง the sleep modes. ดังนั้น The sleep mode power consumption จะอยู่ในระดับเดียวกันเหมือนกับเมื่อ BOD ถูกปิดใช้งานโดยรวมโดยการเซท fuses. ถ้า BOD ถูกปิดใช้งานใน software, the BOD function จะถูก turned off โดยทันทีหลังจากการเข้าสู่ the sleep mode. เมื่อ wake-up จาก sleep, BOD จะเปิดใช้งานอย่างอัตโนมัติอีกครั้ง. นี้เพื่อให้แน่ใจว่าการทำงานจะปลอดภัยในกรณีที่ the VCC level ลดลงในช่วง the sleep period.

เมื่อ the BOD อยู่ในระหว่างการปิดใช้งาน, the wake-up time จาก sleep mode จะอยู่ประมาณ 60μs เพื่อให้แน่ใจว่า the BOD ทำงานได้ถูกต้องก่อนที่ the MCU จะปฏิบัติ code ต่อไป

BOD disable ถูกควบคุมโดย the BOD Sleep bit ใน the MCU Control Register (MCUCR.BODS). การเขียนบิทนี้เป็น '1' จะ turns off the BOD ใน relevant sleep modes, ในขณะที่เขียนศูนย์ในบิตนี้ทำให้ BOD ทำงานอยู่ ค่าเริ่มต้นที่เซทไว้คือ BODS = 0 ทำให้ BOD ทำงาน

Note: การเขียนถึง the BODS bit ถูกควบคุมโดย a timed sequence และ an enable bit.
Note: BOD disable มีให้ใช้งานเฉพาะสำหรับ ATmega328P เท่านั้น


tha

14.4. Idle Mode
เมื่อ the SM[2:0] bits ถูกเขียนให้เป็น '000', คำสั่ง the SLEEP instruction ทำให้ the MCU เข้าสู่ Idle mode, จะหยุด the CPU แต่ยอมให้ the SPI, USART, Analog Comparator, 2-wire Serial Interface, Timer/Counters, Watchdog, และ the interrupt system ทำงานต่อไป. sleep mode นี้จะหยุด clkCPU และ clkFLASH, ขณะที่ยอมให้ clocks อื่นๆรัน.

Idle mode เปิดใช้งาน the MCU ให้ wake up จาก external triggered interrupts เช่นเดียวกันกับอินเตอร์รัพท์จากภายในอย่างเช่น the Timer Overflow และ USART Transmit Complete interrupts. ถ้า wake-up จาก the Analog Comparator interrupt ไม่ถูกต้องการ, the Analog Comparator สามารถถูกลดพลังงานลงโดยการเซท the ACD bit ใน the Analog Comparator Control และ Status Register – ACSR. นี้จะลดการกินพลังงานใน Idle mode ลง.

tha

14.5. ADC Noise Reduction Mode
เมื่อ the SM[2:0] bits ถูกเขียนด้วย '001', คำสั่ง the SLEEP instruction ทำให้ the MCU เข้าสู่ ADC Noise Reduction mode, จะหยุด the CPU แต่ยอมให้ the ADC, the external interrupts, the 2-wire Serial Interface address watch, Timer/Counter2(1), and the Watchdog to  ทำงานต่อไป (ถ้าเปิดใช้งาน). sleep mode นี้โดยทั่วไปแล้วจะหยุด clkI/O, clkCPU, และ clkFLASH, ขณะที่ยอมให้ clocks อื่นๆรัน

นี้จะปรับปรุง the noise environment สำหรับ the ADC ให้ดีขึ้น, ทำให้สามารถทำการวัดด้วยความละเอียดที่สูงขึ้น. ถ้า the ADC ถูกเปิดใช้งาน, การแปลง ADC จะเริ่มโดยอัตโนมัติเมื่อเข้าสู่โหมดนี้. นอกเหนือจาก the ADC Conversion Complete interrupt, เหตุการณ์เหล่านี้สามารถ wake up the MCU จาก ADC Noise Reduction mode:

• External Reset
• Watchdog System Reset
• Watchdog Interrupt
• Brown-out Reset
• 2-wire Serial Interface address match
• Timer/Counter2 interrupt
• SPM/EEPROM ready interrupt
• External level interrupt on INT
• Pin change interrupt
Note: 1. Timer/Counter2 จะรันต่อไปใน asynchronous mode เท่านั้น.

tha

ลองทำ Idle Sleep Mode ดู ใช้บอร์ด atmega328p ที่ทำเอง ทำทั้งแบบ เซท register และใช้ library
ถ้าเซท register ก็เช็ค register ใน data sheet บิทไหนเป็นบิทไหนบ้าง
ถ้าใช้ library ก็ดูไฟล์ตาม folder นี้  C:\WinAVR-20100110\avr\include\avr

การต่อสวิทช์ใช้ R pull up ภายนอก เลยต้องเช็ค interrupt ที่ขอบขาลง ของ INT0 ขา PD2 เพื่อ wake up จาก idle sleep mode

http://www.mediafire.com/file/51dyu5j7jk5898o/sleep1.rar
http://www.mediafire.com/file/x98xj8ukp7ip81v/sleep2.rar

tha

ตัวอย่างโปรแกรมผมก็เอามาจากหนังสือ การเขียนโปรแกรมควบคุมไมโครคอนโทรลเลอร์ AVR ด้วยภาษา C กับ WinAVR (C Complier) นั่นแหละ มาดัดแปลงเอา ในหนังสือเขาใช้ atmega16 ส่วนผมใช้ atmega328p ใครอยากรู้รายละเอียดแน่นๆ ก็หาซื้อหนังสือมาอ่านเอานะครับ
http://www.appsofttech.com/store/product/view/C_Programming_for_AVR_Microcontroller_Book_1-19590643-en.html

tha

นี่ก็มี http://www.thaieasyelec.com/products/education/books/avr-programming-using-c-vol-1-detail.html

เรื่อง ADC Noise Reduction Mode คงยังไม่ได้ทำ เพราะว่ายังทำ ADC ไม่เป็นครับ