{"action":"created","issue":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/1330","labels_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/1330/labels{/name}","comments_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/1330/comments","events_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/1330/events","html_url":"https://github.com/cleanflight/cleanflight/issues/1330","id":107388317,"number":1330,"title":"Current Monitor Input Selection of PA5 (ADC1_IN5) / Bottom ADC Pad \"E\"","user":{"login":"dhenrie0208","id":10443161,"avatar_url":"https://avatars.githubusercontent.com/u/10443161?v=3","gravatar_id":"","url":"https://api.github.com/users/dhenrie0208","html_url":"https://github.com/dhenrie0208","followers_url":"https://api.github.com/users/dhenrie0208/followers","following_url":"https://api.github.com/users/dhenrie0208/following{/other_user}","gists_url":"https://api.github.com/users/dhenrie0208/gists{/gist_id}","starred_url":"https://api.github.com/users/dhenrie0208/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhenrie0208/subscriptions","organizations_url":"https://api.github.com/users/dhenrie0208/orgs","repos_url":"https://api.github.com/users/dhenrie0208/repos","events_url":"https://api.github.com/users/dhenrie0208/events{/privacy}","received_events_url":"https://api.github.com/users/dhenrie0208/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-20T11:26:42Z","updated_at":"2015-10-12T11:08:18Z","closed_at":null,"body":"I'm using the Naze32 Rev5 board with Cleanflight firmware \"1.9.0 NAZE 2015-6-2 0:41 (stable)\", and I've built a basic current monitor that consists of a 2W 0.001 Ohm resistor (=44.7A max) between a 3S battery positive output and the load (the drone). The terminals of the resistor are connected to a simple op-amp circuit that removes the common mode voltage, so that the op-amp output voltage is equal to the voltage across the resistor. This setup produces 1mV per amp the drone draws with 0V DC bias - 0A = 0mV, 10A = 10mV, 20A = 20mV, etc... The schematic and simulation is viewable [here](http://falstad.com/circuit/circuitjs.html?cct=$+1+0.000005+10.200277308269968+50+5+50%0AR+256+432+256+368+0+0+40+12+0+0+0.5%0Ar+256+432+256+496+0+0.001%0Ai+256+496+256+576+0+33%0Ag+256+576+256+608+0%0Ar+256+432+368+432+0+100000%0Ar+256+496+368+496+0+100000%0Ar+368+416+480+416+0+100000%0Ar+368+512+480+512+0+100000%0Aa+368+464+464+464+1+12+0+1000000%0Ag+480+416+512+416+0%0Aw+368+480+368+496+0%0Aw+368+448+368+432+0%0Aw+368+432+368+416+0%0Aw+368+496+368+512+0%0Aw+480+464+480+512+0%0Aw+464+464+480+464+0%0AO+480+464+576+464+1%0AO+256+432+208+432+1%0AO+256+496+208+496+1%0AO+368+416+368+368+1%0AO+368+512+368+560+1%0Ax+611+472+688+475+0+24+to+ADC%0Ax+115+468+242+471+0+12+Current+Sense+Resistor%0Ax+233+347+269+350+0+24+Bat%0Ax+231+648+275+651+0+24+-Bat%0Ax+363+631+655+634+0+12+op-amp+(LM2902N,+single+supply)+powered+by+battery%0Ax+158+538+235+541+0+12+ESCs+/+Motors%0Ao+1+64+0+34+0.03653754093327257+23.945242826029514+0+-1%0Ao+16+64+0+34+0.03653754093327257+9.765625e-55+1+-1%0A).\r\n\r\nBecause I have a PWM-only receiver (Turnigy 9x8Cv2) and am using GPS, I want to avoid sacrificing another channel to connect the current monitor output to Pin 10 / ID 8 of the receiver port as indicated in the [Cleanflight 'Board - Naze32' documentation](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/docs/Board%20-%20Naze32.md).\r\n\r\nThe Naze32 Rev5 has an ADC pad broken out on the bottom (labeled \"E\" on page 4 of the [Abuse Mark manual](http://www.abusemark.com/downloads/naze32_rev3.pdf)). In [src/main/drivers/adc_stm32f10x.c](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/src/main/drivers/adc_stm32f10x.c), it is acknowledged that this Rev5 ADC breakout \"Pad 'E'\" exists, and support code for this pad is found in the files shown below. __I'd like to connect the output of my current sensor to this pad so I can keep Pin 10 / ID 8 of the RC port as a PWM channel input.__\r\n\r\nThe code that assign the ADC channel input to the current monitoring code is given in:\r\n\r\n[src/main/target/NAZE/target.h](https://github.com/cleanflight/cleanflight/blob/1f127905f70f0388449d212892d546cb50f4a8cc/src/main/target/NAZE/target.h):\r\n\r\n```c++\r\n#define CURRENT_METER_ADC_GPIO      GPIOB\r\n#define CURRENT_METER_ADC_GPIO_PIN  GPIO_Pin_1\r\n#define CURRENT_METER_ADC_CHANNEL   ADC_Channel_9\r\n```\r\n\r\n[src/main/drivers/adc_stm32f10x.c](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/src/main/drivers/adc_stm32f10x.c):\r\n\r\n```c++\r\n#ifdef CURRENT_METER_ADC_GPIO\r\n    if (init->enableCurrentMeter) {\r\n        GPIO_InitStructure.GPIO_Pin   = CURRENT_METER_ADC_GPIO_PIN;\r\n        GPIO_Init(CURRENT_METER_ADC_GPIO, &GPIO_InitStructure);\r\n        adcConfig[ADC_CURRENT].adcChannel = CURRENT_METER_ADC_CHANNEL;\r\n        adcConfig[ADC_CURRENT].dmaIndex = configuredAdcChannels++;\r\n        adcConfig[ADC_CURRENT].enabled = true;\r\n        adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_239Cycles5;\r\n    }\r\n#endif\r\n```\r\n\r\nAll of the above code is replicated for \"Pad 'E'\" for ADC12_IN5 as well (`enum ADC_EXTERNAL1`).\r\n\r\nThe code where the ADC values are used for monitoring current is the following:\r\n\r\n[src/main/drivers/adc.h](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/src/main/drivers/adc.h)\r\n\r\n```c++\r\ntypedef enum {\r\n    ADC_BATTERY = 0,\r\n    ADC_RSSI = 1,\r\n    ADC_EXTERNAL1 = 2,\r\n    ADC_CURRENT = 3,\r\n    ADC_CHANNEL_MAX = ADC_CURRENT\r\n} AdcChannel;\r\n```\r\n\r\n[src/main/sensors/battery.c](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/src/main/sensors/battery.c)\r\n\r\n```c++\r\n    switch(batteryConfig->currentMeterType) {\r\n        case CURRENT_SENSOR_ADC:\r\n            amperageRaw -= amperageRaw / 8;\r\n            amperageRaw += (amperageLatestADC = adcGetChannel(ADC_CURRENT));\r\n            amperage = currentSensorToCentiamps(amperageRaw / 8);\r\n            break;\r\n```\r\n\r\n\r\n\r\n__Can the option to select between \"RC Pin 10 / ID 8\" and \"Pad 'E'\" be made available either through the Cleanflight GUI or CLI?__ I envision a change similar to the following:\r\n\r\n[src/main/sensors/battery.c](https://github.com/cleanflight/cleanflight/blob/27db9ad0fe9a4d8abc05c59db201b8944324eea4/src/main/sensors/battery.c)\r\n\r\n```c++\r\n    switch(batteryConfig->currentMeterType) {\r\n        case CURRENT_SENSOR_ADC:\r\n            amperageRaw -= amperageRaw / 8;\r\n            if(currentSensorUseExtADCPad) {\r\n                amperageLatestADC = adcGetChannel(ADC_EXTERNAL1);\r\n            } else {\r\n                amperageLatestADC = adcGetChannel(ADC_CURRENT);\r\n            }\r\n            amperageRaw += amperageLatestADC;\r\n            amperage = currentSensorToCentiamps(amperageRaw / 8);\r\n            break;\r\n```\r\n\r\nwhere `currentSensorUseExtADCPad` would be a boolean controllable via the CLI / GUI, like so:\r\n\r\n`set currentSensorUseExtADCPad=1` - use External ADC Pad \"E\" as current sensor input\r\n`set currentSensorUseExtADCPad=0` - use RC Port Pin 10 / ID 8 as current sensor input (default)\r\n\r\nThank you for your great work and consideration. I apologize for 'yelling' with the bold font, but I wanted to easily identify the purpose of this message.\r\n"},"comment":{"url":"https://api.github.com/repos/cleanflight/cleanflight/issues/comments/147367122","html_url":"https://github.com/cleanflight/cleanflight/issues/1330#issuecomment-147367122","issue_url":"https://api.github.com/repos/cleanflight/cleanflight/issues/1330","id":147367122,"user":{"login":"Pierre-A","id":8274225,"avatar_url":"https://avatars.githubusercontent.com/u/8274225?v=3","gravatar_id":"","url":"https://api.github.com/users/Pierre-A","html_url":"https://github.com/Pierre-A","followers_url":"https://api.github.com/users/Pierre-A/followers","following_url":"https://api.github.com/users/Pierre-A/following{/other_user}","gists_url":"https://api.github.com/users/Pierre-A/gists{/gist_id}","starred_url":"https://api.github.com/users/Pierre-A/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pierre-A/subscriptions","organizations_url":"https://api.github.com/users/Pierre-A/orgs","repos_url":"https://api.github.com/users/Pierre-A/repos","events_url":"https://api.github.com/users/Pierre-A/events{/privacy}","received_events_url":"https://api.github.com/users/Pierre-A/received_events","type":"User","site_admin":false},"created_at":"2015-10-12T11:08:18Z","updated_at":"2015-10-12T11:08:18Z","body":"PR #1301 has been merged so DMA index is now correct for RSSI and External."}}