PID -Hardware needed for a software fix

Yeah I got it. Quoted below so everyone can see the info.

It is an unsigned long, which is 2^64 on an Arduino, I think. It starts at zero when the processor boots. 2^10 is 1024, so you have about 2^44 seconds. There are 525,600 minutes in a year (thanks Rent!). So 30M seconds/year. So that’s about 2^19 years? I wouldn’t worry about it. The brushes on the dewalt are not going to last as long as those 64 bits.

It really is strange. Anthropologists should be studying the whiteboard meetings between software engineers. I would really like to know why some things are so easy to explain in programming but hard in English. Plus, when you’re starting out, you don’t know what the algorithms are called.

Glad you’re enjoying it. Just remember how many hours you have burned in CAD and design and don’t expect to immediately have success in software. It takes practice, like anything else. I’ve put in my 10,000 hours, but I still have to look stuff up all the time and the computer is constantly complaining about my work. :slight_smile: You’re doing great already.

The loop() is an Arduino specific thing. I don’t know why they did that, but normal c++ doesn’t have a setup or loop. In Arduino, they basically add this to the very end of the code:

int main()
{
setup();
while (true)
{
loop();
}
}

ISR is an “interrupt service routine”. And that tells you exactly what it does. The hardware actually stops execution of the main code, and goes to “service” that interrupt. The ISR is running whenever the physical hardware senses the change, and it stops whatever else is running. That’s why you don’t do much work in the ISR, because nothing else is happening as long as it’s running (including other ISRs). So when the hardware detects that falling edge, it will quit printing to the serial port (as an example), and copy the micros out. If you were doing something really slow, then it might miss timing on the serial port or something. The attach call resets the interrupt to fire again. I moved it to the end because I’m paranoid, but you don’t want the interrupt to fire while your still in the ISR.

Everything I know about programming I learned from arduino’s build in examples, and you! Even the crazy programming courses I had to take in school were not broad focus, it was more about how to program an equation. Excel is harder to do math in and we had to learn that in Chemistry 1.

This Interrupt thing, feels like you gave me a key to something huge. Again a million thanks for your patience and guidance.

Back on track.

The encoder disk is such a clean signal I don’t it is even worth it to try to do it any other way. I will continue with it and the other way will always work if we can figure out a better way with the reflection thing. The reflection is also picking up a ton of electrical noise so it needs some sort of filter. This was mentioned in the Instructables thing about his OLED. So far the encoder board is clean and I feel much safer way to play with mains power control.

 

Just wanted to say I like the work you are doing on the speed controller.

Keep up the good work.

1 Like

[attachment file=53216]
No, it is not the final design, this is just to keep my fingers a little further away. The actual mount will need to get tucked in real good and be able to swing out of the way I think, I would love just epoxy a disk to the top end of the shaft.

Now…let the real programming begin. First a little speed control test. Might try top get a video snippet of it. Then figure out some PID stuff.

Crap, Sh%t, #%^&#%^(V @#)#%$@#.

I think the speed control died. I have no idea what happened. Tried to put the 660 on it, nothing, and then out of the blue full speed. Nothing but full speed since. I guess that was the wrong part.

Even with the control powered off it is still running the power and it didn’t do that before. I really have no idea what happened but I ordered new triacs for that board, and a new board.

And I got a face full of that encoder while while it happened, so that isn’t a good idea.

 

Whoa! The encoder flew off or your printed part?

If you can dodge an encoder, you can dodge a ball.

Maybe we have to go back to the HF speed control with a servo moving the knob.

1 Like

BOOOO! Maybe, but I am not giving up so quick. That board though, I do not like how it dies wide open…It could have been my fault I used two different outlets, maybe I was on separate circuits?

The printed part popped in half. I knew the split design wasn’t the best idea but it was fast to CAD. Got my hand and my face…Safety squints from now on. You tried to warn me.

The new triacs work! So just tested the simple speed control for the rambo, M3 s15000 and m4, work! The router spins at real low power even, of course I haven’t test the strength but it is promising).

It is a bit disturbing though when I plug in the dewalt to the triac board I do get a usb disconnect and reconnect…powered off. I will leave it alone for now because of the rat nest of wires could be an issue and I can just say before turning anything on make sure the router is plugged in.

So back to integrating the encoder side.

Okay the speed sensing and speed control are on the same nano and working. That is a great step.

So we have a gas pedal and a speedometer. Now refine the logic a bit, and then start working on the cruise control (PID).

Always good when this start to come together.

Keep up the good work.

Yessss ! That’s great news :slight_smile:

Thanks… I am sitting here staring at it kind of afraid to mess with the code. I think next will be a basic speed control. Average the current speed try and use basic math to get it close to the desired speed. before I try and decipher Heffe’s PID math link from earlier.

1 Like

Good work Ryan. I really wish I had taken advantage of that semester of computer science in high school and actually learned C++

It’s never too late to start! I’ve spent about the last 2 weeks of evenings immersed in “Beginning C for Arduino: Learn C Programming for the Arduino”. I wouldn’t say I really understand it all yet, but it is starting to make a whole lot more sense.

True! I highly suggest getting a super cheap Arduino “beginner kit”. They have example code built in kinda like lesson that are truly lego blocks to making super crazy code. I seriously started with a nano kit from sainsmart and used it for a 1 year long 4 person team project from my engineering final, and used another nano and the same kit for a solar tracker project for a professor that was part of a larger NASA funded project…Insane what these can do and how little code you actually need. The two easiest A’s I got is school were built on Arduino!

All my years of school never taught this kind of programming, just more of like loop logic and iterations. You can see in this thread I am learning so much from Heffe’s snippets.

 

1 Like

Just throwing out encouragement that learning Arduino doesn’t require pre-existing knowledge of C or C++. The tutorials on their site will get you through some basic things like making an LED blink or spinning a small motor. There are also tons of projects on the web to use for reference. :slight_smile:

Any time I’ve tried to do something more than the basics, there’s usually a pre-existing library to leverage. Ryan, have you looked at any of the PID libraries out there?

No I haven’t?! Heffe linked a good doc earlier in the thread, but I haven;t gotten that far yet.

Starting with just the P part will get you going. The larger the error, the more you correct. Can’t get simpler than that.

Don’t average results. Just use the low pass filter code I pasted.

My rule of thumb for choosing a P gain is to pick what error would require the max response. If the desired rpm is X below the measured, what is X where you would want to output 255? If you decided 2k was right, then you would choose 255/2000.

If you hit a wall, send me the code (you have my email). There are some type gotchas that could make it act funny.

Got the filter in, simplifying the rpm as you have it next.

I don’t have any sort of control in yet, I hit another crummy e-mail earlier that took a bunch of time. But I am on it now.

I seriously took too much time to understand your filter…maybe I should stop avoiding math so much it is starting to fade. But I like it now that I can put it into words. It is just adding a percentage (adjustable) of change. It is going to be hard to tune I think.