Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM input to AVR

Status
Not open for further replies.
One quick question on the same code.
I put a 100ms delay at the very end of my code just so that I could see the numbers I was puting on the terminal. Aparently, it was screwing up the timing on my receiver input signal. I have it where the program calls the LStick routine which clears the timer, then times the pulse. Then, it returns a calculated output and I display it, THEN the delay happens.
The error is when ever the pulse itself takes less than 100 timer counts, it doesn't clear out and counts twice, giving me a bad output.

I just dont see how a delay at the end of my code could cause something to mess up when it clears the timer right before it starts and displays the result onscreen before the delay.

Oh, it was a 100ms delay, but if I take it down to 97ms, it is fine and works great again. Strange. Just so you know, I will take the delay out when I put together the real program for my robot, I'm just debugging right now and making sure everything works.
~Mike
 
Its basically the same code as what you gave me...I was just wondering why a delay thats not even close to the timing sequence would have an adverse effect and only durring a certain amount of stick tilt.
Oh well, without the delay it works fine so its not a problem at all, just strange.
~Mike
 
I think the answer just came to me: The problem would occur when the delay put you in the middle of a pulse. The first while loop would exit immediatly giving an incorrect pulse start time. To fix this you would have to ensure that your measurement starts when the pulse signal is low so you only capture the time at a rising edge. A while (pulse == 1) {} at the beginning should solve the problem.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top