Hi all,
so I am trying to control two brushless motors with BLHELI ESC and using potentiometer(5kOhm) as encoder.
Control of motors are done by reading pwm from RC receiver with interrupts and passing them raw to esc with writeMicroseconds function. Esc's are always powered from battery.
The problem is that I get quite some variation in the potentiometer readings as seen below:
AOA POTI: 519 STEER POTI: 360 AOA IN: 1496 AOA OUT: 1427 STEER IN: 1512 STEER OUT: 1726
AOA POTI: 485 STEER POTI: 343 AOA IN: 1500 AOA OUT: 1551 STEER IN: 1512 STEER OUT: 1754
AOA POTI: 507 STEER POTI: 371 AOA IN: 1496 AOA OUT: 1470 STEER IN: 1512 STEER OUT: 1708
AOA POTI: 528 STEER POTI: 358 AOA IN: 1500 AOA OUT: 1390 STEER IN: 1508 STEER OUT: 1734
AOA POTI: 506 STEER POTI: 376 AOA IN: 1496 AOA OUT: 1474 STEER IN: 1512 STEER OUT: 1701
AOA POTI: 521 STEER POTI: 373 AOA IN: 1496 AOA OUT: 1420 STEER IN: 1512 STEER OUT: 1706
AOA POTI: 500 STEER POTI: 367 AOA IN: 1496 AOA OUT: 1496 STEER IN: 1508 STEER OUT: 1715
AOA POTI: 507 STEER POTI: 375 AOA IN: 1496 AOA OUT: 1466 STEER IN: 1512 STEER OUT: 1707
AOA POTI: 517 STEER POTI: 352 AOA IN: 1500 AOA OUT: 1430 STEER IN: 1512 STEER OUT: 1744
AOA POTI: 507 STEER POTI: 367 AOA IN: 1496 AOA OUT: 1470 STEER IN: 1512 STEER OUT: 1720
AOA POTI: 503 STEER POTI: 382 AOA IN: 1496 AOA OUT: 1485 STEER IN: 1512 STEER OUT: 1691
AOA POTI: 522 STEER POTI: 383 AOA IN: 1496 AOA OUT: 1416 STEER IN: 1512 STEER OUT: 1689
AOA POTI: 489 STEER POTI: 345 AOA IN: 1500 AOA OUT: 1536 STEER IN: 1508 STEER OUT: 1750
AOA POTI: 492 STEER POTI: 413 AOA IN: 1496 AOA OUT: 1526 STEER IN: 1512 STEER OUT: 1641
AOA POTI: 504 STEER POTI: 351 AOA IN: 1500 AOA OUT: 1481 STEER IN: 1508 STEER OUT: 1740
AOA POTI: 509 STEER POTI: 357 AOA IN: 1496 AOA OUT: 1458 STEER IN: 1512 STEER OUT: 1731
AOA POTI: 511 STEER POTI: 350 AOA IN: 1500 AOA OUT: 1456 STEER IN: 1512 STEER OUT: 1743
AOA POTI: 523 STEER POTI: 369 AOA IN: 1500 AOA OUT: 1413 STEER IN: 1508 STEER OUT: 1712
AOA POTI: 484 STEER POTI: 356 AOA IN: 1496 AOA OUT: 1554 STEER IN: 1516 STEER OUT: 1738
AOA POTI: 492 STEER POTI: 384 AOA IN: 1496 AOA OUT: 1526 STEER IN: 1512 STEER OUT: 1692
AOA POTI: 512 STEER POTI: 395 AOA IN: 1496 AOA OUT: 1448 STEER IN: 1512 STEER OUT: 1674
AOA POTI: 487 STEER POTI: 354 AOA IN: 1500 AOA OUT: 1544 STEER IN: 1512 STEER OUT: 174

So I thought maybe it was noise picked up on the potentiometer cables(ca 10cm) going to the arduino. So to check this I added a second arduino to just read the potentiometer, but then the problem disappeard. So I then assume this is not the case.

Then I added a 100nF capsitor between the wiper and GND, however this seems to have no effect as well

I tried powering arduino circuit(with poti) with USB cable, USB charger, another battery with separate step down converter. Nothing helped.

It gets better when I change the output pwm refresh interval:

#define REFRESH_INTERVAL 2000//2500//20000 // minumim time to refresh servos in microseconds*
Motor is more responsive when outgoing pwm refresh interval is lower(higher freq). Makes some sense, this esc can support very high freqs. So it would be nice to keep the refresh interval low.
So what can be the issue? Has it to do with interrupts and analog read or is there some electrical noise?
One way to solve it would of course be to add an ADC to i2c and read it in the arduino, but I feel thats a bit overkill instead of finding the issue.