SM0VPO Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Yet another new project on www.sm0vpo.com

2 posters
Post new topic   Reply to topic

Go down

Yet another new project on www.sm0vpo.com Empty Re: Yet another new project on www.sm0vpo.com

Post by Ivan Fri Apr 26, 2024 7:58 am

Hi Harry,

there are usually several paths of executing the same job in programming. It is much about the habits of each author, but some ways may be prone to errors or consume more resources.


1 - Jumping around to call a defined routine takes time
Unmistakably, but division etc. takes time, too. As I wrote some days before, the code interpreter in the MCU takes a huge part of the processor power and makes the user application to run MUCH slower than a fully pre-compiled machine code.


2 - If I call a routine 10 times then the timing value becomes increments of 10, and not 1
I had a conditional cycle in mind. Like this:


int argument = 123456;
while (argument>1000) {
   delayMicrosecods (1000);
   argument = argument - 1000;
   }

delayMicroseconds (argument);


The switch command seems to be perfect to personalize the length of pulse mapping:

    int pulseWidth;
    switch (i) {
       case 1:
          pulseWidth = map(joystickValue, 0, 1023, 630, 2300); // Map joystick 1 value to pulse width
          break;
       case 2:
          pulseWidth = map(joystickValue, 0, 1023, 900, 1500); // Map joystick 2 value to pulse width
          break;
       default:   
          pulseWidth = map(joystickValue, 0, 1023, minPulseWidth, maxPulseWidth); // Map other joystick value to pulse width
          break;
    }   
    delayMicroseconds(pulseWidth); // Delay based on joystick value


VBR from Ivan

Ivan

Posts : 793
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

Yet another new project on www.sm0vpo.com Empty Re: Yet another new project on www.sm0vpo.com

Post by sm0vpo Fri Apr 26, 2024 1:08 am

Ivan wrote:Hi Harry,

thank you for another application of the Arduino based pulse generator. Just little comments:

The frame timing loop
// Calculate remaining time to end-of-frame (milliseconds and microseconds)
(timerCalculation) = (timerCalculation) - (pulseWidth); // Subtract channel pulse from frame length counter
(timerMilliseconds) = (timerCalculation / 1000); // 25000μs is too big for delay, convert to ms (integer)
(timerMicroseconds) = (timerMilliseconds * 1000); // How much was lost generating the ms integer (in μs)?

can be calculated more easily using div and mod. Or you can use the technique of repeated calling of the microsecond delay in a while loop like in the multichannel encoder.

The pictures
"This is the joystick potentiometer set to minimum = 650μs"
and
"This is the joystick potentiometer set to maximum = 2400μs"
seem to be identical. You maybe inserted a wrong file?

Very nice work  anyway!
VBR from Ivan

Hello Ivan,
Thank you very much indeed for the comments. I must admit that the 650 and 2400 are the same file. I copied the picture link three times, editied the comments, but forgot to change the filename. This I will do in the morning. But I really appreciate your comments.

"div and mod" - I think I have got to do some more learning, and I wil look into that The problems with calling a time delay several times are that:
1 - Jumping around to call a defined routine takes time
2 - If I call a routine 10 times then the timing value becomes increments of 10, and not 1
Otherwise I would have done just that, the same as I used to do with GW-Basic or the Microlabs PIC processors. But with a bit of thought it can be done by subtract/call, say 1000 per call, then if the remainder is less than 1000 then just call the timer with the remainder. This is something to think about. But divide by 1000 and execute ms timer, then the μs time with what is left was easy and quick to implement. But you are right, I do have a lot more to learn.

One other thing is the joystick range and mapping. I presently have the multi-channel in a loop, but this is one thing I must change to have several bits of code, one for each potentiometer. The reason is:

1 - If I use a knob then I can rotate a full 300° - 0V-5V divider works
2 - If using a joystick then a seperate code for that will allow to map different values since they only cover 90°
3 - If you map the numbers backwards then the servo movement is reversed, eg.;
       int pulseWidth = map(joystickValue, 0, 1023, 2400, 650)
       int pulseWidth = map(joystickValue, 0, 1023, 650, 2400)
These are exactly the same but the first has the servo direction reversed.

Another point is that I have used two miniataure pots to limit the total range to 100° (90° plus +/-5° trim), but it is a lot of fiddling about. It would be nicer to make a simple joystick "potentiometer driver" circuit that uses a constant current, so that a 47K pot in a 90° + 10° joystick only needs two terminals if fed by a 280μA constant current source.

I also saw that different servos have very different properties that can require different ranges. All this means is that access to "personalising" individual joysticks means that an Arduino in one application can have each channel individually, custom programmed, just two lines of code for each channel.

So thank you for the valuable info you have given. I will have to do more reading and learning. But I am very grateful for your help.

I have checked and I have not received any e-mail from you for the 6-CH (8-CH) encoder update. I presume you have sent it to harry.lythall@sm0vpo.com?

Very best regards from Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

Yet another new project on www.sm0vpo.com Empty Re: Yet another new project on www.sm0vpo.com

Post by Ivan Wed Apr 24, 2024 9:19 pm

Hi Harry,

thank you for another application of the Arduino based pulse generator. Just little comments:

The frame timing loop
// Calculate remaining time to end-of-frame (milliseconds and microseconds)
(timerCalculation) = (timerCalculation) - (pulseWidth); // Subtract channel pulse from frame length counter
(timerMilliseconds) = (timerCalculation / 1000); // 25000μs is too big for delay, convert to ms (integer)
(timerMicroseconds) = (timerMilliseconds * 1000); // How much was lost generating the ms integer (in μs)?

can be calculated more easily using div and mod. Or you can use the technique of repeated calling of the microsecond delay in a while loop like in the multichannel encoder.

The pictures
"This is the joystick potentiometer set to minimum = 650μs"
and
"This is the joystick potentiometer set to maximum = 2400μs"
seem to be identical. You maybe inserted a wrong file?

Very nice work  anyway!
VBR from Ivan

Ivan

Posts : 793
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

Yet another new project on www.sm0vpo.com Empty Yet another new project on www.sm0vpo.com

Post by sm0vpo Wed Apr 24, 2024 3:34 pm

Hi again all, yes I am still on the RC servo control projects.

A little while ago I posted a new project regarding a single-channel PWM encoder to test servos.  http://sm0vpo.com/use/rc-servo-tester-1.htm

It is an all analogue PWM generator, but it works really great. However, I have dug out all my old RC gear dating back almost 45 years and found that the standards and performances change. Sometime the pulses must be well within a narrow range or the servos can do funny things. Now re-timing a multivibrator may not be the quickest of things to do, especially if you are adjust the range to start from 800μs instead of 500μs or 650μs.

So I created a new Arduino project to do the same thing. This time it takes but a few seconds to change the timing, and I listed a few mechanical and timing differences with four of the types of servos I am presently using. With this you can now put servos to find their limits, or tailor the timing to form a reliable project, such as remote tuning. The new project can be found at https://sm0vpo.com/pic/rc-servo-tester-2.htm and the homepages have been updated to include the links to the new projects.

I want to thank Ivan for his assistance with the 6-CH (8-CH) encoder. There will be changes to that project to improve the code, but for the moment the existing code works perfectly and without errors.

Very best regards from Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

Yet another new project on www.sm0vpo.com Empty Re: Yet another new project on www.sm0vpo.com

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

Post new topic   Reply to topic
 
Permissions in this forum:
You can reply to topics in this forum