Hi,
Still trying to figure out servos and have read a great deal about them. Now I need to know if I understand them, and how timed INT factors in to the equation.
Servo's operate by sending a pulsed output to them, which tells them what position to go to. Hitec typically is 1100us for -45, 1500 for 0, 1900us for +45.
Down and dirty code would be.....
turn on output
delay 1.9ms (go to +45)
turn off output
delay 20ms
repeat to hold
Servo's require this pulse be sent every 20ms or less to hold position, less time is OK, longer == not held in position.
Is the above correct?
If it is.......
How does INT block work in flowcode since flowcharts are inherently sequential by design. I place my INT block as the second block of the flowchart, just below a decision block that is waiting for Switch to go ON to start my sequence of motions.
Since switch has not been pressed yet, are INT macros running?
Does the INT routines run in "parallel" with the "sequential" solving logic?
I want to be able to have "sequential" logic solve, pneumatic motions that can take several seconds to complete or time delay logic while I count down extended time delay BUT still have the servos move or hold a position while doing these other things.
Will the INT logic solve even if I am sitting in a decision block waiting for an input to go on OR at a delay block while waiting for the 8 seconds to end?
Assuming the INT macros do solve in parallel with the sequential logic can I have several INT blocks in a row using the same TIMER, trigger different macros, each controlling a particular servo?
This way my "sequential" logic solves, but all the connected servos will move to and/or hold position?
Is this correct?
I realize that servos are not the responsibility of this forum, I am hoping to figure out how to use standard flowcode logic blocks to create multi axis servo control.
Next thing is how do I count in micro-seconds using standard flocode blocks?
Thanks
Ron
Multiple Servo Axis and Timed INT flowcode block
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Ron
I think you are correct in saying the servos need a 20ms frequency. However this would make your quick and dirty code something like this.
turn on output
delay 1.9ms (go to +45)
turn off output
delay 18.1ms
repeat to hold
The INT block in Flowcode works to enable or disable interrupts. If you are say using the RB0 Interrupt then as soon as it is enabled an interrupt can occur if the pin RB0 goes high or low depending on your settings.
The Interrupt will switch in as long as it is enabled. You can also have different interrupts calling different macros. However there are only a few easily accessable individual interrupts.
A good way to go would be to use the timer0 interrupt to occur at a fairly high frequency (at least every 2.5ms to allow enough time for each servo to be serviced twice in 20ms). To allow more flexibility you want the interrupt to service each servo at least 10 times in 20ms. This will give you 10 individual possibilities of output. Every time it interrupts you can have a count of 1 to 4 which chooses the servo you require and services it. You would have to do a bit of research into the timer interrupts though. The flowcode help file is a good place to start. After that try google or microchipc for examples.
I think you are correct in saying the servos need a 20ms frequency. However this would make your quick and dirty code something like this.
turn on output
delay 1.9ms (go to +45)
turn off output
delay 18.1ms
repeat to hold
The INT block in Flowcode works to enable or disable interrupts. If you are say using the RB0 Interrupt then as soon as it is enabled an interrupt can occur if the pin RB0 goes high or low depending on your settings.
Interrupts do not run in parrallel. There is only one eight bit processor. Instead as soon as the interrupt occurs it switches itself into the program counter and adds a layer to the program stack. Then as soon as the interrupt routine has finished it removes itself from the stack and resets the program counter to where it was before the interrupt occurred.How does INT block work in flowcode since flowcharts are inherently sequential by design. I place my INT block as the second block of the flowchart, just below a decision block that is waiting for Switch to go ON to start my sequence of motions.
Since switch has not been pressed yet, are INT macros running?
Does the INT routines run in "parallel" with the "sequential" solving logic?
Will the INT logic solve even if I am sitting in a decision block waiting for an input to go on OR at a delay block while waiting for the 8 seconds to end?
The Interrupt will switch in as long as it is enabled. You can also have different interrupts calling different macros. However there are only a few easily accessable individual interrupts.
A good way to go would be to use the timer0 interrupt to occur at a fairly high frequency (at least every 2.5ms to allow enough time for each servo to be serviced twice in 20ms). To allow more flexibility you want the interrupt to service each servo at least 10 times in 20ms. This will give you 10 individual possibilities of output. Every time it interrupts you can have a count of 1 to 4 which chooses the servo you require and services it. You would have to do a bit of research into the timer interrupts though. The flowcode help file is a good place to start. After that try google or microchipc for examples.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Timer INT, more questions.....
Hi,
I realize that the logic does not solve in parallel, it just solves so fast that it appears to.
Good catch on the 18.1 by the way, someone as detailed as me, I love it.
If the timer0 INT is set for 2ms, and the longest pulse timed value is 1.9ms (Move to +45 degrees), will the next INT start .1ms after the macro ends or 2.5ms after it ends?
What this is leading to is simple. I want to control the position and "speed" of the servo. Now, we all know that we cannot control the speed of these RC servos directly.
BUT
If I can keep track of where the servo is by keeping track of the number of 10us - 100us pulses I send instead of sending the servo directly to 1900 from 1500. I would send it to 1510, then 1520, then 1530, then 1540 with slight time delays in between each step this might give me pseudo speed control (this is like pseudo parallel logic solving, just an illusion).
Thanks........
This is great!
You guys are the best!
Ron
I realize that the logic does not solve in parallel, it just solves so fast that it appears to.
Good catch on the 18.1 by the way, someone as detailed as me, I love it.
If the timer0 INT is set for 2ms, and the longest pulse timed value is 1.9ms (Move to +45 degrees), will the next INT start .1ms after the macro ends or 2.5ms after it ends?
What this is leading to is simple. I want to control the position and "speed" of the servo. Now, we all know that we cannot control the speed of these RC servos directly.
BUT
If I can keep track of where the servo is by keeping track of the number of 10us - 100us pulses I send instead of sending the servo directly to 1900 from 1500. I would send it to 1510, then 1520, then 1530, then 1540 with slight time delays in between each step this might give me pseudo speed control (this is like pseudo parallel logic solving, just an illusion).
Thanks........
This is great!
You guys are the best!
Ron
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Ron
As soon as the Timer interrupts it will begin counting again. Or in simpler terms the timer once started will run and run. This can be changed by writing values to the timer using a C code icon
So in answer to your question. If the macro that handles the interrupt is 1.9ms long and your interrupt macro is 2ms long then the timer will interrupt 0.1ms after leaving the interrupt macro.
As soon as the Timer interrupts it will begin counting again. Or in simpler terms the timer once started will run and run. This can be changed by writing values to the timer using a C code icon
Code: Select all
tmr0 = 0; //Resets the timer
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel