Circuit debugging strategies

Status
Not open for further replies.

nav

Member
Hello,

For many days, I have been struggling with one code. I tried many suggestions from the forum but I could not get any satisfactory solution. I just wanted to ask here that how do you guys approach debugging the code (not specific to my code but in general)? Is there any software or so? Your experience will help many others.
Thank you.
 
Your question is so general its hard to say, but

First question to answer is "What precisely is not working, how do you know there is a problem, what is the expected behavior and the actual behaviour?" This meas you must document and describe the problem as carefully as possible. "Not working" is not helpful, "X should do A when Y happens but it seems to do B" is more clear, to you and folks trying to help.

Next be aware that the cause of the problem is often in other code than the one that shows the problem, like buffer overruns, global variables taking undesirable vales "side effects" from functions. Interrupt issues etc.

So next question to ask "What was the last state when the program that worked (or seemed to work), what changes has been made since then?"

Isolate subsystems, like use only a single sensor, test display separately and such things.

Run test and example programs for the use of those subsystems.

For programs working on Arduino and not Teensy, check that switch from 5V to 3.3 is still ok, lookout for Atmeg specific code in libraries.
 
Followup after checking your forum posts.

So your code almost works, you can generate 5.13MHz in sync, or 5.00MHz with clocks that have random sync.

So what is the issue, digitalWriteFast in a loop dont have the resolution you want, and PWN (analogWrite) can be precise but hard to adjust synco or phase resolution.

Is there a problem in your code ? Seems not, so the problem is how to make a fancy trick, and several phase synced 5.00MHz outputs is a fancy trick. The strategy here is to look for similar code, but probably also might need a deep dive into the hardware reference manual and timing libray codes.
 
You are right.
To generate 5MHz, code is the problem. The issue is delayNanoseconds takes extra time to execute.
For example delay of almost 100ns is generated by delayNanoseconds(69) not delayNanoseconds(100).
Also, I tried to use nanos() function to count nanoseconds. (ref. https://forum.pjrc.com/threads/60493-A-Higher-Resolution-Micros) It seemed to give some fixed delay and I guess it is because of lines execution time.
I learnt this after doing a lot of trial and error codes using an oscilloscope.
In my quest to look for a solution, I came across Arduino Pro software which has this debugging feature but it does not support Teensy. I was wondering if there is some kind of method (for eg. MATLAB has a debugging tool to break the code in between) to check the problem in code without using an oscilloscope.
 
Status
Not open for further replies.
Back
Top