RMweb Premium melmerby Posted February 12, 2021 RMweb Premium Share Posted February 12, 2021 54 minutes ago, Simond said: I’d definitely serial print some data to the monitor in every branch of the program to assure myself that the logic inputs & outputs are doing what you think they should. atb Simon You can't (AFAIK) serial print to the monitor while using serial comms. I did a search for that and it said the USB & serial pins cannot be used at the same time. Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 12, 2021 RMweb Premium Share Posted February 12, 2021 (edited) I have made some progress. When response to the switches stops, it is the Arduino freezing and the code stops running. I found that by inserting a monitor pin out into the loop and scoping it. There was a continuous 5v 50uS pulse when it was active (various changing of the switches for Direction and Enable). When it stopped responding the pulse also vanished, so the loop wasn't looping any more. I removed the TMC2208 from the circuit and the pulse and hence the Arduino carried on ad infinitum. It's something about the TMC2208 that it doesn't like. Next step is series resistors from the Arduino pins to the TMC2208 Also been checking my soldering to make sure there are no whiskers across tracks. Edited February 12, 2021 by melmerby 1 Link to post Share on other sites More sharing options...
Simond Posted February 12, 2021 Author Share Posted February 12, 2021 44 minutes ago, melmerby said: You can't (AFAIK) serial print to the monitor while using serial comms. I did a search for that and it said the USB & serial pins cannot be used at the same time. ah, that’s that idea in the bin then. Like the idea of scoping a pin. Neat. 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 12, 2021 RMweb Premium Share Posted February 12, 2021 Looks like it might now be working. I fitted 1k0 between each used Arduino pin and the TMC2208, I also ran a blade up and down the stripboard to remove any solder whiskers and redid a couple of iffy spotface cuts to make sure the tracks were really severed. It now seems to be working I can change direction, motor runs, change switches, motor stops, change direction again and motor runs again and so on. I did it for about 5 cycles and it didn't freeze. Next is to rig it up with something to move and proper end stops switches before commiting it to the traverser this is the code (complete with scope pin): TraverserTest2.ino 1 1 Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 12, 2021 RMweb Gold Share Posted February 12, 2021 (edited) Seeing as once you get to the loop it is just the digitalWrite(StepPIn, ! digitalRead(StepPin)) and the delay(1) either there is something going wrong with that either the loop is going to fast and is unable to Read the StepPin correctly. I would try increasing the delay just in case the stepper need a bit more time. Or there is something added rom the .h files included that causes an interrupt. If you wanted to be able to use the serial monitor via USB you would need to declare alternative pins for the software serial link these should be any digital pins and not the tx AND rx pins Don I had just hit this before your reply came. It may well be that something was interferring with the step pin read. Well at least you are getting there. Developing software can be like this you seem to be hitting a brick wall and then something is done which sorts it out. Edited February 12, 2021 by Donw adding post script 2 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 20, 2021 RMweb Premium Share Posted February 20, 2021 OK Following my faultless test, the next time I tried it it was completely gone, logic just did not work.Arduino just locked up and wasn't looping. Bearing in mind the DIR and EN work fine (and the Arduino works ad infinitum) if operated manually by switches I thought it was time for a change of tack. Hardwired logic using CMOS gates, just let the Arduino do the stepping and bring the logic calculation out of the loop. Using a 4011 Quad 2 input Nand and a 4070 Exclusive Or I can reproduce the required sequence of events. I have wired these up on a breadboard and I have also mocked up a test rig with the stepper motor & some limit switches, so I don't need to operate the switches manually. Just need to connect all together. 1 Link to post Share on other sites More sharing options...
Simond Posted February 20, 2021 Author Share Posted February 20, 2021 That’s very odd. Are you sure there isn’t a dodgy connection somewhere off board? After all, one of the strengths of “computer control” is that it does the same thing, very reliably, time after time. Most curious. atb Simon 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 20, 2021 RMweb Premium Share Posted February 20, 2021 6 minutes ago, Simond said: That’s very odd. Are you sure there isn’t a dodgy connection somewhere off board? After all, one of the strengths of “computer control” is that it does the same thing, very reliably, time after time. Most curious. atb Simon I've been over the connections several times and when testing the only things "off board" are the switches, which were new and unused and the motor. The supply is rock solid at 5.1v and more than capable of driving the motor. What I can't understand is how an Arduino can lock up. Why does the loop stop operatin g? Why if it's locks up, I can turn the power off and back on again and it will start again, without anything else being touched? All I'm doing is changing some logic levels and the Arduino goes funny sometimes. I've used two different Arduinos and they are the same. Could it be the timing is somehow critical at this level? Link to post Share on other sites More sharing options...
Simond Posted February 21, 2021 Author Share Posted February 21, 2021 I really don’t know. I’m almost tempted to set up an experiment to copy what you’ve done, using the same hardware, just out of curiosity, but I’ve got so many things on the go, it’s just not going to happen. What we want is a classroom full of eager students with boxes of hardware to play with, and set them the problem to solve! Are there no computing teachers/lecturers/students on here? You’ll recall that I wrote a sketch for Paul Ashton a year or so ago, longer, we hadn’t heard of Covid, which pretty much does what your sketch does, only with manual inputs, and the old A4988 driver board. If you didn’t have a route to a solution, I’d suggest copying that, and then adding your decoder control, but it seems like you have a solution so I guess it will remain “one of those things”. cheers Simon Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 21, 2021 RMweb Gold Share Posted February 21, 2021 (edited) If both step1 and step2 are HIGH the loop will just keep cycling. The scope pin will alternate but at at a one millisecond display may not seem so. If it works with you manually operating the switches it could be something to do with them. Don Edit I would suggest putting a 500 millisecond delay before and after the digitalwrite(scope, LOW) just for a test, With a LED on the output it would show whether the loop was just running non stop by blinking. Edited February 21, 2021 by Donw adding post script Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 21, 2021 RMweb Premium Share Posted February 21, 2021 Hi Don. As part of the commands in the loop, one of the Arduino input pins is taking the DCC decoder output (via an optocoupler) HIGH or LOW and sending it via an output pin to the DIR input of the TMC2208. Surely if the Arduino was still looping, irrespective of what else was/was not happening changing this input pin would change the output pin? It doesn't. Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 21, 2021 RMweb Gold Share Posted February 21, 2021 2 hours ago, melmerby said: Hi Don. As part of the commands in the loop, one of the Arduino input pins is taking the DCC decoder output (via an optocoupler) HIGH or LOW and sending it via an output pin to the DIR input of the TMC2208. Surely if the Arduino was still looping, irrespective of what else was/was not happening changing this input pin would change the output pin? It doesn't. Unless of course it is failing to read the DCC Input pin correctly which seems no less likely than the Arduino stopping running. Unless there is something in those parameters which can be set by software that limits the numbers of steps the motor can take. Or there is some overheating and the tmc2208 is shutting it down. Perhaps there is some kind of interrupt triggered by the TMC2208. The only difference from your description was that it was ok with manual operation of the end stop switches. When something stops working the firt question I ask is what has changed? What I suggested should prove whether the Arduino has stopping running the loop or not. If the loop is still running you look at the logic and whether the digital reads and writes are working correctly. If the loop has stopped running it is something outside of your coding. Don 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 21, 2021 RMweb Premium Share Posted February 21, 2021 (edited) Hi Don I doubt the TMC2208 is overheating as the current to the motor averages between 200 & 300mA and it remains cool I might have a look at the serial interface with the scope to see what data is being fed back to the Arduino whilst it is working and when it appears to freeze. (the scope can decode these signals) Edited February 21, 2021 by melmerby 1 Link to post Share on other sites More sharing options...
Simond Posted February 21, 2021 Author Share Posted February 21, 2021 Or slow it right down, and use the on-board LED to confirm that something is happening (or not)? 1 Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 21, 2021 RMweb Gold Share Posted February 21, 2021 2 hours ago, Simond said: Or slow it right down, and use the on-board LED to confirm that something is happening (or not)? Which is what I suggested. Don 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 21, 2021 RMweb Premium Share Posted February 21, 2021 8 hours ago, Donw said: Edit I would suggest putting a 500 millisecond delay before and after the digitalwrite(scope, LOW) just for a test, With a LED on the output it would show whether the loop was just running non stop by blinking. And this. 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 22, 2021 RMweb Premium Share Posted February 22, 2021 Hi Don. I have done as suggested and put in the delay and at the same time operate the on-board led Yes it flashes when the program starts, but stops when the program appears to stop after a few switch operations, it stays either permanently on or permanetly off. 1 Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 22, 2021 RMweb Gold Share Posted February 22, 2021 Now we know something is jamming the Arduino I cannot see anything in your code that would just stop the arduino unless with the ENPin HIGH it cannot perform the DigitalWrite(step_PIN, !digitalRead(step_PIN));// step motor and is stuck on that instruction. I would move that statement by putting a copy following the Digitalwrite(ENPIN, LOW) statement within the if brackets. So if it fails both if conditions it will not try the step . It may then just stop stepping but keep looping. Don Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 22, 2021 RMweb Premium Share Posted February 22, 2021 (edited) 2 hours ago, Donw said: Now we know something is jamming the Arduino I cannot see anything in your code that would just stop the arduino unless with the ENPin HIGH it cannot perform the DigitalWrite(step_PIN, !digitalRead(step_PIN));// step motor and is stuck on that instruction. I would move that statement by putting a copy following the Digitalwrite(ENPIN, LOW) statement within the if brackets. So if it fails both if conditions it will not try the step . It may then just stop stepping but keep looping. Don Hi Don I have just put a DigitalWrite(step_PIN, !digitalRead(step_PIN)); directly after the Digitalwrite (ENPIN, LOW) statements in the "if..else" part of the sketch (I commented out the original) and it does exactly the same thing. It manages a few cycles, then it stops. Edited February 22, 2021 by melmerby Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 22, 2021 RMweb Gold Share Posted February 22, 2021 31 minutes ago, melmerby said: Hi Don I have just put a DigitalWrite(step_PIN, !digitalRead(step_PIN)); directly after the Digitalwrite (ENPIN, LOW) statements in the "if..else" part of the sketch (I commented out the original) and it does exactly the same thing. It manages a few cycles, then it stops. When you say it stops I presume that means the arduino stops running too or does the on board led continue flashing? Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 22, 2021 RMweb Premium Share Posted February 22, 2021 1 minute ago, Donw said: When you say it stops I presume that means the arduino stops running too or does the on board led continue flashing? The Led stops flashing, Link to post Share on other sites More sharing options...
RMweb Gold Donw Posted February 22, 2021 RMweb Gold Share Posted February 22, 2021 The only thing I know about that could do that is to go into Sleep Mode. There is a a Sleep mode which shuts down most activities although it should hold current data in memory and wait for an external stimulus to restart. However I can see nowhere were the Sleep function would be called and you would need the appropriate includes . So I do not think it is that. I would check the Arduino is ok by running something simple that just blinks a few leds and is not connected to the stepper just in case the Arduin is faulty. If that is ok I would have a look atusing the legacy mode just to see if that works. This is really puzzling. The only other thing I can think of is whether there is some electrical noise of the pins from the STepper. Don 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 22, 2021 RMweb Premium Share Posted February 22, 2021 Back to the breadboard. Operating the EN and DIR straight from switches between HIGH & LOW and it works just fine, you can start & stop it and change direction as many times as you like and it works every time. Next is to put my piece of CMOS logic into circuit and try that. 1 Link to post Share on other sites More sharing options...
RMweb Premium melmerby Posted February 24, 2021 RMweb Premium Share Posted February 24, 2021 This is starting to bug me. 1) Breadboard with the Arduino, TMC2208 & CMOS logic all connected - works fine. This proves the basic concept is sound. 2) Stripboard with just the TMC2208 & Arduino with EN & DIR directly operated by switches - works fine. 3) Stripboard with just the CMOS plugged in to check logic to EN & DIR pins - works fine. 4) Stripboard with full circuit of CMOS, Arduino & TMC2208 - works for a couple of cycles then Arduino goes bananas! Just what is going on? The only thing that is different between the stripboard and the breadboard is that the stripboard has a buck convertor to reduce 12v wall supply to 5v for the IC supplies and the breadboard is fed directly from a 5v wall supply I have now put extra decoupling (100nF + 100uF) on both the 5v inputs to both the TMC 2208 & the Arduino but haven't yet tested it. Link to post Share on other sites More sharing options...
Simond Posted February 24, 2021 Author Share Posted February 24, 2021 I'm sure it shouldn't, and I guess you already checked, but is the buck failing to give sufficient current, causing a brown-out? Worth clipping your scope to the 5v rail? fingers crossed Simon Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now