DCC-EX / BaseStation-EX

Partial re-write of DCC++, maintained for historical purposes. Not actively bug-fixed or developed
https://dcc-ex.com
19 stars 8 forks source link

How to handle current sense for reading and writing CVs in packetRegsiter.cpp? #7

Closed FrightRisk closed 4 years ago

FrightRisk commented 4 years ago

When I was changing all my current code to deal with milliamps (but also keeping the raw pin reading) I saw that this code separately handles reading the current sense pin. Reading a CV, for example:

fills 8 registers by: taking ACK_BASE_COUNT number of readings averages them sends 3 reset packets, 5 verify packets and 6 idle packets (In DCC++ classic, the last one was 1 reset) takes ACK_SAMPLE_COUNT number of readings subtract the base reading to get the difference smooths it then sees if that value is greater than our ACK_SAMPLE Threshold If so, the decoder sent a current spike acknowledge, then does a bWrite

then repeats this all again to verify and at the end, we added one more reset packet

  1. Does that look good now? Who can test?

  2. How does this handle different motor controllers? If current sense device reports a different number of amps per millivolts on that pin, Don't the variables have to be tweaked experimentally for each board??

  3. If I change this to actual current in milliamps, would that make the math better or worse? With pin values can be 11 or 12 for a BTS7960B at 5 Amps (I think). But we know the Uno is 300 means about 890mA. And we know programming needs to be 250ma or less or we are supposed to throw an overcurrent condition. Regardless of max current, we are always looking for a difference of some amount. What is that amount? And again, does that mean a table for every board?

  4. Last, what about stay alive caps? Is DCC++ designed so that there is voltage on the track so the caps are charged or does it only pulse during the small time something is sent to the loco? That would mean we have to account for caps blocking us sensing the pulse since they may filter it.

kwledbetter commented 4 years ago

So I would like to add a related to this. The current Sample Max is currently set manually in the Currentmonitor.h tab. I would like to make it a variable (instead of hardcoded number) that is defined for each motor shield. My initial recommendations would be to put it just below the motor shield rating (maybe 0.25 A) except in the super high power like 43A we would probably want to limit it at 10A or something like that or give a high and low power option. Concern is do you blow your power supply before your motor board

questions above #1 I think this is ready for testing now

2 see my opening statement. Yes is the answer the current sense currently is a number between 0 and 1023 and really depends on the shield what it needs to be set at. See here for the best info I have found on it. http://trainelectronics.com/DCC_Arduino/DCC++/ and locoduinos latest favorite https://www.locoduino.org/spip.php?article253 so will need some testing and experimenting for each motor shield.

3 yes table for every board but I do think useful if you could pull off actual amps rather than the cryptic 0-1024 so people could experiment more easily

4 out of scope but it has been shown that anything above about ~500uF can cause issues and really should have a way of disconnecting for programming. Info http://cs.trains.com/mrr/f/744/p/265541/3001586.aspx and more http://www.sbs4dcc.com/tutorialstipstricks/esuloksound5keepalive.html solution may well be power on and then idle packets to let capacitors fully charge before starting programming but like I say I would move this way down the priority list