KIR Misc Functions.ino: Difference between revisions

From AnalysIR WiKi
Jump to navigation Jump to search
Line 33: Line 33:
== initF_CPU ==
== initF_CPU ==


This function sets the clock divider to match the MCU effective clock frequency to the one defined in the Arduino IDE (usually 8MHz for battery operation). Ther is a particular code sequence that must be followed to achieve this. It is highly unlikely that any user will need to change this code.
This function sets the clock divider to match the MCU effective clock frequency to the one defined in the Arduino IDE (usually 8MHz for battery operation). There is a particular code sequence that must be followed to achieve this. It is highly unlikely that any user will need to change this code.
 


We test the F_CPU value passed from the Arduino IDE and set the CLKPR register to reflect that clock rate.
We test the F_CPU value passed from the Arduino IDE and set the CLKPR register to reflect that clock rate.


We have designed KontroLIR with a 16MHZ crytal. This delivers optimal operation when used with AnalyIr firmware or IRremote firmware. By dividing the rate by 2 we get teh optimal rate for KontroLIR opertion with 2xAAA batteries.
 
We have designed KontroLIR with a 16MHZ crytal. This delivers optimal operation when used with AnalyIR firmware or IRremote firmware. By dividing the rate by 2 we get the optimal rate for KontroLIR operation with 2xAAA batteries.


== checkBattery ==
== checkBattery ==

Revision as of 14:35, 24 October 2019

> KontroLIR Home


These miscelaneous functions cover:

  • Low Power Operation
  • Low power sleep mode
  • Setting MCU oscillator frequency
  • Supply voltage measurement
  • Reading average supply votage from ADC
  • Printing out ATmega328PB fuse settings and lockbits, in debug mode.

initPins

This function sets the pinMode for the non row/col pins and sets their HIGH/LOW level as appropriate. This essentialy covers the 2 IR receivers, The IR emitter, the 2 I2C pins and the GPIO power supply pins for the optional IR receivers and I2C EEPROM (Both of which are powered off by default).

initLowPowerSleep

This function configures the relevant AVR registers to obtain optimal low power current usage, when sleeping. The sleep mode is set to SLEEP_MODE_PWR_DOWN, which usese the least amount of current when sleeping.

goToSleep

This function is called from the main loop every time a button press is processed.

Before sleeping, the LED is turned off, the UART is disabled, PCINTs are enabled, and then the sleep process is initiated.

When a button is pressed, control automatically returns to the latter part of this function, where we initially disable sleep mode, and if in debug mode we re-enable the UART and insert a small delay to allow the BAUD rate generator to stabilise.

Finally we check if the battery level is too low for stable operation. If it is too low we enter a permanent power down mode to avoid potential corruption.

initF_CPU

This function sets the clock divider to match the MCU effective clock frequency to the one defined in the Arduino IDE (usually 8MHz for battery operation). There is a particular code sequence that must be followed to achieve this. It is highly unlikely that any user will need to change this code.


We test the F_CPU value passed from the Arduino IDE and set the CLKPR register to reflect that clock rate.


We have designed KontroLIR with a 16MHZ crytal. This delivers optimal operation when used with AnalyIR firmware or IRremote firmware. By dividing the rate by 2 we get the optimal rate for KontroLIR operation with 2xAAA batteries.

checkBattery

checkLowBattery

readAvgVCC

printFuses

> KontroLIR Home