PID -Hardware needed for a software fix

Sorry, I was kinds jotting down notes/making an update.

[attachment file=53176]

I don’t think optical reflection is that safe of a indicator. The clean reading point is small and I think ambient light has a lot to do with the interference. I would much prefer an optical encoder style disk. I have nice pre-made all in one sensor and receiver boards and I think that is going to be a much cleaner signal. Hopefully a disk can be 3D printed, but there are tons of issues with that as well. http://amzn.to/2EvyBDp

The second message was just me buying an actual rpm tool and verifying the readings.

Another option would be to put a dot on the cooling fins of the 660 and get the readings from that. It is dark and a better target but the dust build up would probably make it a bad choice.

The comments are just me keeping notes. Using unsigned long just in case there was some sort of math error but a volatile word is the correct option here I think.

Dang it…I see what I did wrong there, that is still for pwm timing. I just need time between falling. Explains the 10k RPM off, doen’t fix the crappy signal.

Using the sensor board and the encoder the readings are super consistent, ± 10-15rpm @20k with many repeat readings! Super sketchy holding a router with a spinning disk and a small pcb in both hands…

 

Are you wearing safety squints?

You can use just the one callback to handle the RPMs. If you don’t have a good reason not to, just use ints for any integers. Bytes are mostly just for storing characters and words aren’t really used for anything.

The next thing we could add, since we are literally getting a measurement every 3ms, is to do some low pass filtering. It will make the response slower, but the reading smoother:

smoothed_rpm += ALPHA * (rpmmath - smoothed_rpm);

ALPHA goes from 0-1, at zero, the value never changes, at 1.0, it just copies the input. For this math, you need to just use floating point numbers.

It took me a while to understand the other ISR(? void functions). I kept think how the heck is this doing three freaking loops at the same time. About and hour ago it clicked. Only the void loop is looping, the other two ISR(?) are running once (independently, I get that) and calling each other perpetuating a loop only if the interrupt triggers a falling condition. I kept thinking the loops where piling up or something.

I feel like such a schmuck but it has been a while for fresh coding and never involving interrupts.

I understand your code and need to try it. I had already realized the need for long’s.

This is pretty fun, I do like the logic part of it. I couldn’t work out how to get the two different times in the same ISR(?) your solution makes total sense.

So how does the time work (micros), is there ever a need to zero it out? I mean 8 hours or run time could result in a giant number. Will it roll over at some point? I kept trying to loop it and zero it out each loop.

This is weird that I have questions but not the right language to ask it in. Fascinating, really, I feel like I am on a bus in a foreign country and don’t know the language. I know what I want just not how to ask properly. Each little piece of info is a minor triumph.

Aargh. I had a big post and somehow deleted it while trying to format the code in it. Did it email itself to you?

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