You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

312 lines
17 KiB

3 years ago
3 years ago
  1. ### TODO
  2. 1. The shunt resistor R31 and R32 might need to change the values.
  3. ### STATUS
  4. BMP280 -- [ WORKING ]
  5. GYRO ---- [ WORKING ]
  6. RX ------ [ WORKING ]
  7. OSD ----- [ ]
  8. VMETER -- [ WORKING ]
  9. CMETER -- [ WORKING ]
  10. ### Configurator
  11. Planning to design a web-base for configuring the quad settings and so on. Everything using Javascripts and HTML.
  12. This will greatly reduce the need of the configurator to be downloaded. Purely configure by its own.
  13. ### REFERENCES
  14. +-----------------------+
  15. | O | USB | O |
  16. | ------- |
  17. 3V3 | [ ] [ ] | VIN
  18. GND | [ ] [ ] | GND
  19. [ ] Touch3 / HSPI_CS0 / ADC2_3 / GPIO15 | [ ] [ ] | GPIO13 / ADC2_4 / HSPI_ID / Touch4 [ ]
  20. [ ] CS / Touch2 / HSPI_WP / ADC2_2 / GPIO2 | [ ] [ ] | GPIO12 / ADC2_5 / HSPI_Q / Touch5 [ ]
  21. [ ] Touch0 / HSPI_HD / ADC2_0 / GPIO4 | [ ] [ ] | GPIO14 / ADC2_6 / HSPI_CLK / Touch6 [ ]
  22. [ ] U2_RXD / GPIO16 | [ ] [ ] | GPIO27 / ADC2_7 / Touch7 [ ]
  23. [ ] U2_TXD / GPIO17 | [ ] [ ] | GPIO26 / ADC2_9 / DAC2 [ ]
  24. [ ] V_SPI_CS0 / GPIO5 | [ ] ___________ [ ] | GPIO25 / ADC2_8 / DAC1 [ ]
  25. [ ] SCK / V_SPI_CLK / GPIO18 | [ ] | | [ ] | GPIO33 / ADC1_5 / Touch8 / XTAL32 [ ]
  26. [ ] U0_CTS / MSIO / V_SPI_Q / GPIO19 | [ ] | | [ ] | GPIO32 / ADC1_4 / Touch9 / XTAL32 [ ]
  27. [ ] SDA / V_SPI_HD / GPIO21 | [ ] | | [ ] | GPIO35 / ADC1_7 [ ]
  28. [ ] CLK2 / U0_RXD / GPIO3 | [ ] | | [ ] | GPIO34 / ADC1_6 [ ]
  29. [ ] CLK3 / U0_TXD / GPIO1 | [ ] | | [ ] | GPIO39 / ADC1_3 / SensVN [ ]
  30. [ ] SCL / U0_RTS / V_SPI_WP / GPIO22 | [ ] | | [ ] | GPIO36 / ADC1_0 / SensVP [ ]
  31. [ ] MOSI / V_SPI_WP / GPIO23 | [ ] |___________| [ ] | EN
  32. | |
  33. | | | ____ ____ | |
  34. | | | | | | | | |
  35. | |__|__| |__| |__| |
  36. | O O |
  37. +-----------------------+
  38. Power Pins
  39. ----------
  40. VIN - VIN pin can be used to directly supply the ESP32 and its peripherals, if you have a regulated 5V voltage source.
  41. 3V3 - 3.3V pin is the output of an on-board voltage regulator. This pin can be used to supply power to external components.
  42. GND - Ground pin(s)
  43. GPIO Pins
  44. ---------
  45. ESP32 development board has 25 GPIO pins which can be assigned to various functions programmatically.
  46. Each digital enabled GPIO can be configured to internal pull-up or pull-down, or set to high impedance.
  47. When configured as an input, it can also be set to edge-trigger or level-trigger to generate CPU interrupts.
  48. ADC Channels
  49. ------------
  50. The board integrates 12-bit SAR ADCs and supports measurements on 15 channels (analog enabled pins).
  51. Some of these pins can be used to build a programmable gain amplifier which is used for the measurement of
  52. small analog signals. The ESP32 is also designed to measure the voltages while operating in the sleep mode.
  53. DAC Channels
  54. ------------
  55. he board features two 8-bit DAC channels to convert digital signals into true analog voltages. This dual DAC
  56. can drive other circuits.
  57. Touch Pads
  58. ----------
  59. The board offers 9 capacitive sensing GPIOs which detect capacitive variations introduced by the GPIO’s direct
  60. contact or close proximity with a finger or other objects.
  61. UART Pins
  62. ---------
  63. ESP32 development board has 2 UART interfaces, i.e. UART0 and UART2, which provide asynchronous communication
  64. (RS232 and RS485) and IrDA support, and communicate at up to 5 Mbps. UART provides hardware management of the
  65. CTS and RTS signals and software flow control (XON and XOFF) as well.
  66. SPI Pins
  67. --------
  68. SPI Pins ESP32 features three SPIs (SPI, HSPI and VSPI) in slave and master modes. These SPIs also support the
  69. following general-purpose SPI features:
  70. - 4 timing modes of the SPI format transfer
  71. - Up to 80 MHz and the divided clocks of 80 MHz
  72. - Up to 64-Byte FIFO
  73. - All SPIs can also be used to connect to the external Flash/SRAM and LCD.
  74. PWM Pins
  75. --------
  76. The board has 25 channels (Nearly All GPIO pins) of PWM pins controlled by Pulse Width Modulation (PWM) controller.
  77. The PWM output can be used for driving digital motors and LEDs. The controller consists of PWM timers and the PWM
  78. operator. Each timer provides timing in synchronous or independent form, and each PWM operator generates the waveform
  79. for one PWM channel.
  80. EN Pin
  81. ------
  82. Used to enable ESP32. The chip is enabled when pulled HIGH. When pulled LOW the chip works at minimum power.
  83. GPIO PINS LAYOUT NOTES
  84. ----------------------
  85. +------+--------+--------+--------------------------------------------------------------------------------+
  86. | GPIO | INPUT | OUTPUT | Notes |
  87. +------+--------+--------+--------------------------------------------------------------------------------+
  88. | 0 | PULLUP | [OK] | Output PWM signal at boot |
  89. | 1 | TX PIN | [OK] | Debug output at boot |
  90. | 2 | OK | OK | |
  91. | 3 | [OK] | OK | HIGH at boot |
  92. | 4 | OK | RX PIN | |
  93. | 5 | OK | OK | Output PWM signal at boot |
  94. | 12 | [OK] | OK | Boot fail if pulled high |
  95. | 13 | OK | OK | |
  96. | 14 | OK | OK | Output PWM signal at boot |
  97. | 15 | OK | OK | Output PWM signal at boot. If grounded, it will disable the bootup messages. |
  98. | 16 | OK | OK | |
  99. | 17 | OK | OK | |
  100. | 18 | OK | OK | |
  101. | 19 | OK | OK | |
  102. | 21 | OK | OK | |
  103. | 22 | OK | OK | |
  104. | 23 | OK | OK | |
  105. | 25 | OK | OK | |
  106. | 26 | OK | OK | |
  107. | 27 | OK | OK | |
  108. | 32 | OK | OK | |
  109. | 33 | OK | OK | |
  110. | 34 | OK | | |
  111. | 35 | OK | | |
  112. | 36 | OK | | |
  113. | 39 | OK | | |
  114. +------+--------+--------+--------------------------------------------------------------------------------+
  115. CAPACITIVE TOUCH GPIO
  116. ---------------------
  117. NAME: T0, T1, T2, T3, T4, T5, T6, T7, T8, T9
  118. GPIO: 4, 0, 2, 15, 13, 12, 14, 27, 33, 32
  119. ADC CHANNELS
  120. ------------
  121. NAME: ADC1_CH0, ADC1_CH1, ADC1_CH2, ADC1_CH3, ADC1_CH4, ADC1_CH5, ADC1_CH6, ADC1_CH7
  122. GPIO: 36, 37, 38, 39, 32, 33, 34, 35
  123. NAME: ADC2_CH0, ADC2_CH1, ADC2_CH2, ADC2_CH3, ADC2_CH4, ADC2_CH5, ADC2_CH6, ADC2_CH7, ADC2_CH8, ADC2_CH9
  124. GPIO: 4, 0, 2, 15, 13, 12, 14, 27, 25, 26
  125. DIGITAL TO ANALOG CONVERTER (DAC)
  126. ---------------------------------
  127. NAME: DAC1, DAC2
  128. GPIO: 25, 26
  129. REF
  130. ---
  131. - [PINOUT] https://randomnerdtutorials.com/esp32-pinout-reference-gpios/
  132. https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
  133. - [EXAMPLES] https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
  134. - [DSHOT] https://github-wiki-see.page/m/betaflight/betaflight/wiki/DSHOT-ESC-Protocol
  135. TODO
  136. ----
  137. 1. RECEIVER ---------------------------------------------- [ 80% DONE ]
  138. 2. ESC --------------------------------------------------- [ 80% DONE ]
  139. 3. Accelerometer ----------------------------------------- [ 50% DONE ]
  140. 4. Flight Mode ------------------------------------------- [ ]
  141. - Acro ------------------------------------------------ [ ]
  142. - Angle ----------------------------------------------- [ ]
  143. 5. Fail Safe --------------------------------------------- [ ]
  144. 6. Baro -------------------------------------------------- [ DONE ]
  145. 7. GPS --------------------------------------------------- [ ]
  146. 8. Telemetry --------------------------------------------- [ ]
  147. 9. OTA --------------------------------------------------- [ DONE ]
  148. 10. SoftAP ----------------------------------------------- [ DONE ]
  149. 11. Turtle Mode ------------------------------------------ [ ]
  150. 12. TRAMP ------------------------------------------------ [ ]
  151. 13. Voltage Reading -------------------------------------- [ 90% DONE ]
  152. 14. Ampere Reading --------------------------------------- [ 50% DONE ]
  153. 15. Kalman Filtering ------------------------------------- [ ]
  154. 16. PID -------------------------------------------------- [ ]
  155. DSHOT
  156. -----
  157. DSHOT150: 4kHz max
  158. DSHOT300: 10.6kHz max (10,6khz is only available on 32khz gyro boards)
  159. DSHOT600: 16kHz max
  160. DSHOT1200: >32khz max (Currently only KISS24 supports DSHOT1200)
  161. DSHOT Digital Values:
  162. 0 : DISARMED
  163. 1 to 47 : RESERVED FOR SPECIAL COMMANDS
  164. 48: 2047: ACTIVE THROTTLE CONTROL
  165. 0 DSHOT_CMD_MOTOR_STOP, // Currently not implemented
  166. 1 DSHOT_CMD_BEEP1, // Wait at least length of beep (380ms) before next command
  167. 2 DSHOT_CMD_BEEP2, // Wait at least length of beep (380ms) before next command
  168. 3 DSHOT_CMD_BEEP3, // Wait at least length of beep (400ms) before next command
  169. 4 DSHOT_CMD_BEEP4, // Wait at least length of beep (400ms) before next command
  170. 5 DSHOT_CMD_BEEP5, // Wait at least length of beep (400ms) before next command
  171. 6 DSHOT_CMD_ESC_INFO, // Currently not implemented
  172. 7 DSHOT_CMD_SPIN_DIRECTION_1, // Need 6x, no wait required
  173. 8 DSHOT_CMD_SPIN_DIRECTION_2, // Need 6x, no wait required
  174. 9 DSHOT_CMD_3D_MODE_OFF, // Need 6x, no wait required
  175. 10 DSHOT_CMD_3D_MODE_ON, // Need 6x, no wait required
  176. 11 DSHOT_CMD_SETTINGS_REQUEST, // Currently not implemented
  177. 12 DSHOT_CMD_SAVE_SETTINGS, // Need 6x, wait at least 12ms before next command
  178. 20 DSHOT_CMD_SPIN_DIRECTION_NORMAL, // Need 6x, no wait required
  179. 21 DSHOT_CMD_SPIN_DIRECTION_REVERSED, // Need 6x, no wait required
  180. 22 DSHOT_CMD_LED0_ON, // Currently not implemented
  181. 23 DSHOT_CMD_LED1_ON, // Currently not implemented
  182. 24 DSHOT_CMD_LED2_ON, // Currently not implemented
  183. 25 DSHOT_CMD_LED3_ON, // Currently not implemented
  184. 26 DSHOT_CMD_LED0_OFF, // Currently not implemented
  185. 27 DSHOT_CMD_LED1_OFF, // Currently not implemented
  186. 28 DSHOT_CMD_LED2_OFF, // Currently not implemented
  187. 29 DSHOT_CMD_LED3_OFF, // Currently not implemented
  188. DSHOT_CMD_MAX = 47
  189. Frame Structure:
  190. Every digital protocol has a structure, also called a frame. It defines which information is at which position
  191. in the data stream. And the frame structure of DSHOT is pretty straight forward:
  192. - 11 bit throttle: 2048 possible values. 0 is reserved for disarmed. 1-47 are reserved for special commands.
  193. Leaving 48 to 2047 (2000 steps) for the actual throttle value.
  194. - 1 bit telemetry request - if this is set, telemetry data is sent back via a separate channel.
  195. - 4 bit CRC: (Cyclic Redundancy) Check to validate data (throttle and telemetry request bit)
  196. Resulting in a 16 bit (2 byte) frame with the following structure:
  197. SSSSSSSSSSSTCCCC
  198. +-------+------------+-------+-------+---------+-----------+
  199. | DSHOT | Bitrate | T1H | T0H | Bit(µs) | Frame(µs) |
  200. +-------+------------+-------+-------+---------+-----------+
  201. | 150 | 150kbit/s | 5.00 | 2.50 | 6.67 | 106.72 |
  202. | 300 | 300kbit/s | 2.50 | 1.25 | 3.33 | 53.28 |
  203. | 600 | 600kbit/s | 1.25 | 0.625 | 1.67 | 26.72 |
  204. | 1200 | 1200kbit/s | 0.625 | 0.313 | 0.83 | 13.28 |
  205. +-------+------------+-------+-------+---------+-----------+
  206. Signal Pattern (From Oscilloscope):
  207. 1.670uS --------------------------------- 400.8064129026064 cycles in total
  208. 0.625uS high, 1.045uS low --- 0 --------- 150.0024000384006 cycles HIGH, 250.8040128642058 cycles LOW
  209. 1.250uS high, 0.420uS low --- 1 --------- 300.0048000768012 cycles HIGH, 100.8016128258052 cycles LOW
  210. |-|-|
  211. _
  212. - __| |__
  213. Every data = 16bits
  214. Specs (per bit):
  215. 1. HIGH time : 1.25 uS
  216. 2. LOW time : 0.625uS
  217. 3. Total Time Frame: 1.67 uS
  218. 4. Max Time Frame : 26.72 uS
  219. Commands 0-36 are only executed when motors are stopped. Some commands need to be sent multiple times in order for
  220. the ESC to act on it - those are marked with Needs nx - where n is the amount of times the command has to be sent
  221. in order for the ESC to act upon it.
  222. 5: 0001 0010 0100 0111 | 00010010010 0 0111
  223. 6: 0001 0101 1100 1000 | 00010101110 0 1000
  224. 7: 0001 1000 0010 1011 | 00011000001 0 1011
  225. 100: 1111 1111 1110 1110 | 11111111111 0 1110
  226. Calculating the CRC:
  227. The checksum is calculated over the throttle value and the telemetry bit, so the "first" 12 bits our value in the
  228. following example:
  229. crc = (value ^ (value >> 4) ^ (value >> 8)) & 0x0F;
  230. Let’s assume we are sending a throttle value of 1046 - which is exactly half throttle and the telemetry bit is not set:
  231. value = 100000101100
  232. (>>4) = 000010000010 # right shift value by 4
  233. (^) = 100010101110 # XOR with value
  234. (>>8) = 000000001000 # right shift value by 8
  235. (^) = 100010100110 # XOR with previous XOR
  236. (0x0F) = 000000001111 # Mask 0x0F
  237. (&) = 000000000110 # CRC
  238. So the two bytes transmitted from flight-controller to ESC would be:
  239. 1000001011000110
  240. ESP32 CLOCKs:
  241. 240MHz clock
  242. 240000000 cycles = 1 second
  243. 240000 cycles = 1 mili second
  244. 240 cycles = 1 micro second
  245. 1 cycle = 4.167 nano second
  246. ### HOWTO UPLOAD
  247. ./upgrade.py http://192.168.1.1/update .pio/build/esp32dev/firmware.bin
  248. Flight Controller
  249. -----------------
  250. - Sequencer Task
  251. +> ICM20602 -> BMP280 -> NRF24L01+ -> AT7458
  252. ^ |
  253. | |
  254. +----------------------------------+
  255. REF:
  256. - https://brushlesswhoop.com/dshot-and-bidirectional-dshot/
  257. - https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/FreeRTOS/FreeRTOS.ino (TRY THIS)
  258. - https://www.digikey.at/en/maker/projects/introduction-to-rtos-solution-to-part-12-multicore-systems/369936f5671d4207a2c954c0637e7d50
  259. - BMP280 - https://community.blynk.cc/t/esp32-bmp280-st7735-mcp2301-blynk/38933