Anyway to tell why it's rebooting?

I’m assuming that it’s loosing power for a millisecond which reboots the spark but I have no idea. Could it be some other type of protection? I’m powering it with 5v through a voltage regulator that has 12v input.

Does it give any visual indications perhaps? Flashing red LED? Have you checked for any connection errors, shorts, bad connections? Would you mind sharing your code? There could be something in there that’s causing the Core to crash.

Some background:

It’s a train running on a track. Before I was using the spark to control the voltage on the track and the code and everything worked fine. 12v into the circuit, down to 5v into the spark to a h-bridge and out to the track. I decided to move the circuit onto the train and just supply a constant 12v to the track so now the track has the 12v and the train has the circuit that I had before. The only thing I can think of is maybe the motor on the train is pulling too much sometimes which causes some issues with the voltage and thus resets the spark? Should I add Decoupling capacitors? is there a way to see what failure/error is happening?

12v coming in at the top left. Left IC is the h-bridge, middle is 5v voltage regulator.

Hi @ryandetzel

I would try adding a large electrolytic cap (say 470uF or larger) plus a small 0.01uF cap to the +5 V power supply you are giving to the Spark core. This will help your device to tolerate small glitches in the power. To debug, you could also try powering the core from a small battery instead of the +5V

Cool project!

2 Likes

so I added some caps, not sure if that made the difference or if it’s the hbridge swap that did but it happens less frequently now but it still happens. Here’s a video, it seems to happen when the motor pulls more current like the second time it reboots as the train is stuck. Any other ideas?

Try to “star” the power connections all back to one central point. Right now it looks like the GND is coming in on the BLACK lead traveling down the top blue power rail, through a jumper, and then all of the way up to the H-Bridge… which runs through the ground connection to the Spark Core. So every time the H-bridge draws more juice, it’s producing a voltage drop through all of those connection, which the spark core will see.

Depending on how much current your motor draws, those jumper wires may be too small as well… creating a significant IR drop (Current (I) x Resistance ® = Voltage). I would also add a similarly large filter cap directly at the h-bridge for the instantaneous switching currents.

So 12V and ground should come in directly to the h-bridge, get filtered, then 12V and ground should run over to the buck regulator, and your blue power rails can be reserved for the spark core gnd only. 5V should come out to the spark core VIN pin directly… filter caps as close to the input as possible. Don’t connect them to the spark core’s VIN pin with long jumpers.

2 Likes

Would increasing the voltage solve this problem too, to say 16v? Would that at least prove that it is in face a voltage drop issue? What is the “star” power connection you speak of, everything else makes sense.
Thanks.

From the video it looks like you’re having trouble over the switch track part and no where else. You have trouble getting through that part at the beginning of the video, only momentum gets you through that without a reboot. But the second time it gets stuck. It’s hard to tell if you’re having current draw issues with the motor/h-bridge but more likely you are having brown-out or blackout conditions from your pickup wheels (the wheels that pickup power from the tracks). For a track that size 12v is more than enough.

Measure your current draw and size the capacitor so it can supply the power needs for the time it takes to transition the switch track.

You could also try adding another set of pickup wheels that are far enough away from each other to always have one in contact over the switcher. If memory serves the ideal difference is 1.5 times the track width or more for each set of pickups. Also check for arc spots/splashes/marks on your current pickup wheels and clean them if there are any deposits.

About the “star” thing. This one is about network topologies but it should give you and idea about them. But instead of packets, you’re transferring power :wink: http://en.m.wikipedia.org/wiki/Network_topology

I thought it was a loss of power too but there are three pickup wheels and it doesn’t actually lose power it’s getting stuck a little on the bottom of the train and it does stop elsewhere on the track randomly so it’s not just the switch. I think the switch causes more issues because when it gets stuck it draws a lot more current. I think it’s a spike issue, maybe with my ground or something when the motor kicks in hard.

Here’s a quick way to prove the extra load of the motor is causing the reset really quick… I’m used to doing this on systems with electric motors. Basically what you do is try to stall the motor and see if the system fails gracefully and recovers. To stall your train, it’s very easy… just put your hand on the engine as it’s moving and slowly push down until it stops. You can also try an abrupt stop… be sure to push down to lock the wheels. Technically, you probably DON’T want to completely stall it if you know you don’t have auto resettable fuses or any kind of protection circuitry. But you can just momentarily add load with your hand and see if you can force a Core reset every time. If you can make this very repeatable, you’ll have a great test to evaluate different wiring/circuit configurations.

I would not increase the input voltage. Based on how it’s wired now, you won’t have any advantage by doing that. Since the voltage to the Core is regulated to 5V… it always has 5V no matter what the input voltage is (in theory). It’s the long ground path that develops the IR drop (aka voltage drop) because the motor current is flowing through the same connection that feeds the Core’s ground. The star topology is like the asterisks symbol

Think of the center as where power enters from the source, and the branches are individual “paths” to your various devices. When high current from the motor is flowing through one of those paths, you can see it does not flow through the path that leads to the Core. Therefore there is no voltage drop. Now your power source does need to run to this center point first with some decently thicker wire to make this scheme effective as well. I would probably beef up your source wires and motor wires since they are running a pretty long length, perhaps 18AWG on the heavy side, and 20AWG on the lighter side. Higher AWG numbers are actually thinner wires. Right now it looks like 24AWG maybe?

Interesting…so I put the train on it’s side and hooked it up, ran fine on multiple speeds for 10 minutes. I then put load by pushing on the wheels so it stalled, amps shot up to 600mA while under load and I could not get it to stop. Intrigued I put the track together in a simple oval and ran it around…went for about a dozen rotations and then stopped but it stopped on the only break in the track where the leads are attached. Now I’m thinking it is actually losing power for a brief second again causing a reboot. So either I would have to add a big? capacitor in there to carry it over the gaps or a battery?

It’s much better though so I think it was a combination of the two, as I’ve been typing this it hasn’t stopped once (30-40 rotations)

In case you’re curious here it what it looks like and the one gap that causes it to randomly stop.

I would be very tempted to, if you didn’t mind the added complexity, to add a “coal car” to the train which had the sparkcore and a lipo battery (11.1v or so). It would allow you to run the train on unpowered tracks if you wished and you could charge the lipo while it is powered. Might be interesting to find a lipo charger that would be ok with such a setup however…

In the mean time I would personally just add more caps to the setup.

Once I figure this out the circuit is going into the engine so I don’t have to pull any cars. A battery would be nice but I doubt it will fit in with the circuit so I’ll have to pass on that for now.

I did add some more capacitors, the largest I have are 470uf so I put four of those in parallel (I think) before the voltage regulator and so far no issues. I even widened the gap in the tracks and added an insulated joiner to the track and it goes over that fine.

1 Like

Aha… definitely more caps then on the Spark Core… and two of these super caps in series (to make them effectively 5F 5V) would be pretty sweet. That would be 165 seconds of holding time! Conversely to just get a couple seconds with normal capacitors you’d need like 50,000uF which is a lot of space. Check out the calculator here:
http://hyperphysics.phy-astr.gsu.edu/hbase/electric/capdis.html#c2

And enter 33 ohms, 5V and 5000000uF (5F) to see the 165s discharge time. The 33 ohms was calculated knowing the average current draw of a Core, which is 150mA. So 5V/150mA = 33 ohms.

1 Like

okay, time to look into SC. :slight_smile: I don’t think I need that much, the 1F ones would probably be enough and in series would give me 0.5F so about 16s of runtime. Would I want more than 5v so I don’t kill them, I always thought you should do 25% more so they don’t die?

Running some more experiments and I’m not sure I need them. I removed the caps I added and got it to fail again and now I’m adding them back 1 by 1 to see how many I need. So far one 470uf seems to do the trick.

If this is true that means it was losing power for less than 0.015 seconds? That seems odd to me but I guess possible…?

Regarding capacitor voltage, the higher you overrate the caps, the longer their life will be… so 10V caps in a 5V system will run way longer than 5V in 5V system. I was originally thinking of attaching them to the 3.3V node of the Spark Core, but changed my mind. You’re right, you should get the cap’s voltage rating higher. If you add one you’ll be fine.

What’s probably happening is when the tracks momentarily drop their connection to the system, the h-bridge puts a huge drain on the input supply and creates a voltage drop that effectively browns out the power to the Spark Core. When that happens the PWM stops, and the voltage drop stops. Adding the caps holds up the supply better in that instant when the PWM turns on and there is no supply anymore from the tracks.

Basically, this is why everyone that dabbles with electronics needs an oscilloscope eventually. The problems become complicated enough that you just need to “see” what’s going wrong instead of guessing what’s going wrong :slight_smile:

EDIT: btw, there is something really cool about your last video… when you see the train changing speeds wirelessly. I love the Polar Express O-Gauge train that I bought many years ago for our Christmas Tree. I’m not sure I’d want to control it wirelessly though, because there’s a certain feeling you get when you roll up the big orange lever of the control transformer… but at the same time the wireless aspect does get me excited :slight_smile: Maybe if a nice web app was created with a beefy slider it could replace this feeling? I’m not sure but I’d love to try it. Hah, what if a web app was kind of like a video game as well… and you had to control the train as it commanded or you would lose… all while the real train was whizzing around the tracks.

Thanks, that’s why I’m doing this. Trains are cool (and geeky) but if I can control it wireless without the expensive DCC stuff it opens up all kinds of options. With little kids < 3 and a nephew who loves trains it allows me to create basic apps (stop, start) for the kids to control the train with. I’m planning on adding basic AI so it’s all but impossible to derail the train like if the switch it closed ahead to auto stop (or switch the switch). I can also do interesting things like fuel gages (based on current usage), auto driving trains on the track that pick/drop off “things” to different industries and even a teaching tool for how to read train signals. Here’s an updated video showing what I have now.

Thanks for your help!

1 Like