DCC++ESP32 Base Station

Atani Dec 10, 2017

Tags:
  1. Curn

    Curn TrainBoard Member

    599
    138
    23
    I raised the mA from 980 to 2000 on line 103 of the MotorBoard.ccp, but it had little impact. The serial monitor is reading this:
    Code:
    [I][Locomotive.cpp:49] showStatus(): Loco(2) locoNumber: 220, speed: 35, direction: FWD
    [I][MotorBoard.cpp:77] check(): [MAIN] Overcurrent detected 2059.57 mA
    [I][MotorBoard.cpp:50] powerOff(): [MAIN] Disabling DCC Signal
    [I][MotorBoard.cpp:92] check(): [MAIN] Overcurrent cleared, 9750 ms before re-enable
    Then in counts down, re-enables track power and continues on for a little while, and then trips again. So far I have seen the problem on an N scale MRC 4-4-0 with sound and a Kato GS4 with a Tsunami sound decoder under load. I doubt both engines are drawing anywhere near 2 amps but the MRC engine trips it much more often. I'm also seeing the problem on Wemos Uno ESP32 board. I don't have a great way to measure the actual current that these locomotives are drawing, but I will set back up my DCC++ systems and see what current it is reading with the DCC++ controller tomorrow night. At least that will show if the problem is an internal short in the locomotive or layout.

    Matt
     
  2. Curn

    Curn TrainBoard Member

    599
    138
    23
    I think the current readings need to be investigated. I hope someone else can at least confirm my observations.

    I used Arduino DCC++ using the DCC++ controller (processing IDE application) to look at what current that software reads with the same motor shield hardware using a N scale MRC Sound 4-4-0. The observed mA was about 200 mA at 40/128 throttle. This seems to be more in line with what I expect a N scale locomotive to draw as far as current goes.
    MRC440mA.png

    With the ESP32 DCC++ system I also as a reality check measured to voltage of the current sense pin and found a voltage of about 200 mV at 40/128 throttle. Now I'm not sure on the conversion of the analog current sense voltage to mA. One site says that it should be a simple conversion factor of 2.96 mA/mV, which would put my manual reading at 600 mA. I'm not sure if square wave AC DCC power requires some other calculation to get a current reading or if the driving voltage (12V in my case) impacts the current sense voltage. Arduino DCC++ looks to be using the conversion of 1mv = 1mA, which might also be wrong.

    -Matt
     
    Last edited: Apr 12, 2018
  3. Atani

    Atani TrainBoard Member

    524
    496
    14
    We have observed some instability in the past and a few bugs in the same area.

    The conversion on the Arduino side is based on 1023 steps from 0.0 to 1.1VDC on the analog pin. This doesn't directly convert to a 1:1 ratio but is pretty close.

    Which site is that? The ESP32 has a much higher resolution ADC than the Arduino. The code on the master branch for DCC++ESP32 does not use any scaling factors so if you are feeding more than ~1.1VDC on the analog pin it is entirely possible the readings are off. If you try the development branch (warning, it could be unstable!) you can reconfigure this via Config.h, or on the master code check this line, the values you can specify for the second parameter are defined here. I would recommend trying ADC_ATTEN_DB_11 instead of ADC_ATTEN_DB_0.
     
  4. Curn

    Curn TrainBoard Member

    599
    138
    23
    I will give the development branch a try.

    I found several websites that all told me different things. I kind of just chose one that gave reasonable results, but have little confidence that it is correct. By measuring current sense (motor shield A0) with a multimeter, my intention was to bypass the the controller board ADC and code to see what is really being measured. I figured that the analog output of current sense pin could be easily correlated to mA. Then the code could be evaluated to match reality. You and a few others state that A0 should range from 0. to 1.1 VDC. The specs for the L298 chip says they should range from 0 to 2.3 VDC. A third source said 0 to 3.3 VDC. To my surprise, the motor-shields current sense output and correlation to mA doesn't seem to be well documented for open hardware. I measured 0.2 VDC (200mVDC). How many mA is that?
     
  5. Atani

    Atani TrainBoard Member

    524
    496
    14
    DCC++ESP32 uses the 12bit mode (4096 steps) and the default of ADC_ATTEN_DB_0 means that the raw value will be processed as-is by the SAR ADC component. The L298 spec may say that it can send up to 2.3VDC on the current sense pins but this may also get further reduced by the motor shield, it depends entirely on the voltage divide circuit. Other motor shields will send higher values (BTS7960 sends up to 5VDC!).

    Now, the ADC voltage values can be scaled via the ADC_ATTEN_DB_XX values, these are described here: https://esp-idf.readthedocs.io/en/v2.0/api/peripherals/adc.html#_CPPv211adc_atten_t. in the default case on master it is ADC_ATTEN_DB_0 which caps the voltage at ~1VDC (which is not right!!) any voltage *OVER* this limit would result in 4095 being returned to the MotorBoard code which would result in the over-current detected message to be displayed.

    The actual draw should be a lot closer to ~48mA if I did my math correctly, if you set the attenuation to ADC_ATTEN_DB_11 it should match up to this roughly as well. You can change this line to test this in your current code without having to switch to the development branch if you like.
     
    Curn likes this.
  6. Shdwdrgn

    Shdwdrgn TrainBoard Member

    193
    168
    8
    I've also been wanting to investigate this further with the BTS board. Not only do I seem to get inconsistent results when I try to check what is being read, but I also seem to get different values between the two BTS boards I have. I need to find a lightbulb that can handle the full 16V supply I'm using and ideally pull around 2-3amps of current so I have a good reading to work from.

    I'm also curious if the ADC_ATTEN_DB settings drop the readings by a linear or exponential amount? It seems like that could also affect the reading across a large scale, while a regular resistor-based voltage divider would more likely give an accurately-scaled output for the ESP to read? I don't have much experience with analog circuits so this is all just a stab in the dark for me, but I think if I could get reasonably accurate readings at 100mA and again at 3000mA then the rest of the scale would likely also fall in line.
     
  7. Jimbo20

    Jimbo20 TrainBoard Member

    178
    146
    7
    My understanding is that the L298 chip itself does not include any current sense logic. The chip spec says "The emitters of the lower transistors of each bridge are connected together and the corresponding external terminal can be used for the connection of an external sensing resistor."

    This i believe is where the confusion arises; different shield designs appear to use different sensing resistor values, and many use a resistor with an op amp to multiply the sensed voltage.

    The Arduino Motor Shield Rev3 uses a 0.15 ohm sense resistor and an op amp circuit configured with a 1k and a 10k resistor giving an amplification factor of 11 ( (1K+10K)/1K)

    When the Shield is passing 2 amps, the sense resistor drops 0.3volts (2amp x 0.15 ohms)
    The op amp multiplies this by 11, giving 3.3 volts (or 1.65v for 1 amp) output on the current sense pin.

    The Arduino gives a 0-1023 ADC reading when 0 - 5 volts is fed to it.

    Therefore when the Rev3 Motor shield is providing 1 amp output, 1.65 sense volts is produced, which the Arduino ADC input would read as 338 (1.65 x 1023/5)

    The Arduino ADC reading increments 1 for each 2.95 mA increase of current output by the motor shield (1000mA/338). Note that this is not the same as 2.95mA/mV which I think is erroneously mentioned in a post above

    https://www.arduino.cc/en/uploads/Main/arduino_MotorShield_Rev3-schematic.pdf
     
    Curn and Atani like this.
  8. Curn

    Curn TrainBoard Member

    599
    138
    23
    Thank you Jimbo for explaining this clearly! This means that the 0.2 volts I was reading should correspond to 0.121 amps (0.2v/11/0.15ohms) at the motor shield, which should be read as 41 (0.2V*1023/5) as the raw number by an Arduino. Thank you Atani for providing a fix to the code and explaining how the ESP 32 processes the signal.

    Matt
     
    Jimbo20 likes this.
  9. Shdwdrgn

    Shdwdrgn TrainBoard Member

    193
    168
    8
    There had been some discussion on previous pages regarding the Lolin32+OLED board to use SVP/25/26 for driving the main track and SVN/16/5 for the programming track. Last night I transferred my setup to a larger breadboard so I could add a transistor for the NOT logic of running the programming track and discovered that the above pinout caused my setup to lock up during initialization. It took me a bit to remember why -- pin 5 is actually being used by the OLED display! I redefined my programming track for pins SVN/16/14 (avoiding pins 0 and 2 since those also have a special purpose) and that seems to be working fine now. It really surprises me though that I didn't find any other problems with the display in the past since I've been using these pin definitions the whole time I've had the base station running. Anyway I have an L298 board modified with current-sense resistors now and hope to get that connected to a short programming track today. I know there was also a brief discussion about adding a third 'track' to the configuration specifically for accessories, did anything ever come of that?

    Meanwhile I also performed some minor surgery on my raspberry pi components last night. I have a setup with a 3.5" display built into a Pi case, and I received an RTC board recently that I wanted to add. Unfortunately the display had a 2x2 header occupying the same space required by the RTC, however the two conflicting pins on the display were marked as NC. I took a hobby saw and removed those two pins. Turns out those pins truly were not being used (whew) and this provided the space to plug in the clock board. Now I don't have to wait for the Pi to find an internet connection before I have an accurate time set. It's just a small thing, but I think this may come in handy later on down the road...
     
    Atani likes this.
  10. Atani

    Atani TrainBoard Member

    524
    496
    14
    Nothing specific has come of the accessories bus for the dcc signal. You should be able to add a third motor board define for current sense and enable pin and leverage the see main track signal pin.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  11. Shdwdrgn

    Shdwdrgn TrainBoard Member

    193
    168
    8
    Well it's not *quite* that easy on this particular board... you have to use pins from the ADC1 set since ADC2 is apparently blocked when wifi is initialized... and this particular board only exposes SVN and SVP from ADC1. So to actually add a third track I will need to solder a wire directly to the ESP, not a difficult thing to do but I've been debating if I want to experiment with such a setup and possibly implement it when I finally get around to building my full layout. I should probably spend more time getting as ESP set up on a loco again though so I can see if I can get a decoder working on it.
     
  12. dompondaco

    dompondaco TrainBoard Member

    32
    3
    2
    Thanks for posting the picture I have been looking all over the net for the connection of the arduino/motor shield to the ESP32 (BTW I am using the Hiletgo EPS shield and its working out ok) so far. Did have a driver issue (for Win 7), but once installed everything was fine. Question, what is the small device in the lower left in your picture, a voltage regulator? I noticed a DCC++ ESP32 logo on it like its a commercial product.
     
  13. Atani

    Atani TrainBoard Member

    524
    496
    14
    That is an OLED screen. It will display the base station status and has a rotating status line for various details of the operations.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  14. Atani

    Atani TrainBoard Member

    524
    496
    14
    As best I can tell that looks like a DevKitC clone. It should work very nicely.



    Sent from my ONEPLUS A5010 using Tapatalk
     
  15. Shdwdrgn

    Shdwdrgn TrainBoard Member

    193
    168
    8
    I dunno, I still like the board with the OLED screen built in (mis-marked as a Wemos board, but it's really just a Chinese clone board). I have three of them now and have been using them for various projects. The setup is rather handy and compact except for the limitation of the ADC ports brought out to the header pins, and the board is rock-solid. When Spring came around and I started working on outdoor projects I forgot about my DCC++ setup and left it running. I think it was sitting for for about three months and still responding to commands before I finally shut everything down last week. (And good on you, Atani, for writing excellent code! Wish I could say the same, my greenhouse monitor on the same board never ran more than a few days at a time before locking up.)
     
    Atani likes this.
  16. dompondaco

    dompondaco TrainBoard Member

    32
    3
    2
    Thanks for the quick reply. I googled OLED to see what it was all about. Question is will a regular LCD work with the base station, if so where can i look for how to hook up.
     
  17. Atani

    Atani TrainBoard Member

    524
    496
    14
    A 2x16 or 4x20 I2C LCD can be wired up and configured in Config.h as well.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  18. dompondaco

    dompondaco TrainBoard Member

    32
    3
    2
    hello Atani, I understand these instructions go back to Dec 2017, but was wondering if the links are still good. Tried the first link ending with windows.md and got a 404 error back from github.
     
  19. Atani

    Atani TrainBoard Member

    524
    496
    14
    You can follow these instructions from the arduino-esp32 page: https://github.com/espressif/arduino-esp32/blob/master/README.md

    The libraries links should work still. If there are more libraries needed let me know.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  20. dompondaco

    dompondaco TrainBoard Member

    32
    3
    2
    Thanks for the information. Will let you know if I need any libraries.
     

Share This Page