attiny.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. The Battery/Lid Controller
  2. ==========================
  3. Introduction
  4. ------------
  5. The Atmel ATTiny841 (U16) is a 8-bit microcontroller that uses very little power and is always on when there is battery power in the system.
  6. Its job is to keep track of how much current is going in and out of the battery and what voltage the battery has. It does this with the help of the voltage/current monitor chip INA260 that is connected to the ATTiny via I2C.
  7. The ATTiny works as:
  8. - Battery voltage and current monitor/gauge
  9. - System current monitor
  10. - Lid sensor
  11. Communication
  12. -------------
  13. The ATTiny is permanently connected to the i.MX6 UART2 (/dev/ttymxc1 in Linux). If you want to interrupt this connection, you can desolder resistors R48 and R50.
  14. The ATTiny firmware configures its serial port to 9600 baud 8N1. You can talk to it using the program screen (or another serial terminal):
  15. .. code-block:: none
  16. screen /dev/ttymxc1 2400
  17. It accepts commands in the form of a single letter followed by return. The current commands are:
  18. - *p*: Get battery power information (estimated capacity in amp hours, voltage, current)
  19. - *l*: Get lid state (0: open, 1: closed)
  20. - *h*: Get hall sensor raw analog value
  21. In addition, these commands can be prefixed with a decimal number (up to four digits):
  22. - *600c*: Reset the battery capacity counter to 10Ah (600 Amp minutes)
  23. - *500t*: Set the lid sensor open/closed threshold to the value 500
  24. - *10w*: Set the lid sensor open/closed hysteresis to 10
  25. Undervoltage Protection (UVLO)
  26. ------------------------------
  27. The microcontroller is supposed to detect a dangerously low voltage on the battery and switch the 5V boost converter off via its PWRON output when the voltage is below 2.8V. This way, the system will not draw power from the battery until it is charged to a reasonable level again. This functionality is still being tested and not activated in the beta boards.
  28. Lid Sensor
  29. ----------
  30. The ATTiny senses if the lid is open or closed using the hall effect sensor (Honeywell SS495A). The lid is considered closed when a magnet is close to the sensor. The ATTiny outputs the string "wake" via its serial port which can wake the i.MX6 up from sleep.
  31. Flashing the Firmware
  32. ---------------------
  33. You can find the source code of the firmware_ in the folder "reform-attiny-fw" of the Reform source repository.
  34. To change (flash) the firmware of the ATTiny, you need an Atmel ISP (In System Programmer) compatible programmer/cable. An easy way is to use an Arduino to emulate_ an ISP.
  35. The relevant pins of J34 on the Reform motherboard for connecting the ISP cable are as follows:
  36. Upper row (left to right):
  37. +-----+------+------+------+
  38. | 7 | 5 | 3 | 1 |
  39. +=====+======+======+======+
  40. | GND | MOSI | MISO | SCK |
  41. +-----+------+------+------+
  42. Lower row (left to right):
  43. +-------+------+------+------+
  44. | 8 | 6 | 4 | 2 |
  45. +=======+======+======+======+
  46. | RESET | None | None | None |
  47. +-------+------+------+------+
  48. .. _emulate: https://www.arduino.cc/en/Tutorial/ArduinoISP
  49. .. _firmware: https://github.com/mntmn/reform/reform-attiny-fw