Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:49 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Mini servo - Tower Pro SG90

     Page 2 of 2    
Author Message
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 08:26pm 10 Mar 2013
Copy link to clipboard 
Print this post

The input pin interrupt and the settick command options both give good accurate control (checked with the 'scope) because in both cases the servo pulses are generated by the PULSE command. Any jitter in the repetition rate of the pulses doesn't matter, it's the pulse width that matters.

The PWM command on my system however has a best resolution for pulse width (i.e. duty cycle) of 0.2 mS at 50Hz which is too coarse to use directly for servo control. That 0.2 mS equates to 1% of the 50 Hz, i.e. 20 mS period, not 0.1% as given in the MMBasic Manual.

Even large variations of the PWM duty cycle are irrelevant since the output is just being used to interrupt an input pin. This pin in turn triggers the accurate servo pulse width via the interrupt routine's PULSE command.

For some uses, having the SETTICK command "tied up" (there is only one available), would be a problem. For other uses having the PWM output "tied up" would be a problem. We have the option of using either method for good control, but not using the PWM output direct to the servo.

Greg
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 10:30pm 10 Mar 2013
Copy link to clipboard 
Print this post

I was actually thinking about the accuracy of the 50hz cycle.
A hardware 50Hz ties up a PWM pin and an input pin while a SETTICK ties up nothing.

If both have the same accuracy, my preference would go to the SETTICK because it requires no hardware connections which will result in a solution that can be used by more people. For example a CMM has the PWM pins occupied with resistors and capacitors making it an analogue output and not available for digital uses without desoldering those compenents.

An argument against using SETTICK would be that it has a lower priority and lower speeds as 1 millisecond is the fastest you can set it up with. The low priority will not make a difference when no other interrupts are used.

If i read the manual correctly when using multiple interrupts it would be impossible to detect if you missed one as interrupts are disabled while in a interrupt routine.
This is making time critical interrupts only work properly when there is only one source of the interrupt and the routine that is invoked is faster then one cycle.

If more time based uses are necessary SETTICK will solve that problem in software, as long as the routine is fast enough. SETTICK can be setup only once, but in the routine you would be able to have multiple routines even on different cycles by counting the invocations.

Also something to be aware of is that the interrupts are checked by MMBasic in software between interpreting basic statements. Your program does not directly respond to an interrupt, MMBasic is the 'director'.
This will cause a small difference is reaction time and will not work during an INPUT statement.

Edited by TZAdvantage 2013-03-12
Microblocks. Build with logic.
 
Bill.b

Senior Member

Joined: 25/06/2011
Location: Australia
Posts: 226
Posted: 12:34am 11 Mar 2013
Copy link to clipboard 
Print this post

Hi Greg

I would check the ratting of the SG90 servo, the specs on DX.com
rate it at 9g not 2kg. There seems to be some conflick on rattings on there web site.

I have knock up a demo only using the pulse command to generate the
50Hz required. The servo seems very stable for each setting of the pot

The servo I am using is a STD 503 which has serveral Kg of torque.

I also used a mini servo which is equivelent to the SG90 with the same results.

[code]
' servo2.bas - Bill Brown (bill.b)
' 11th march 2013
' Test program for servo control using a pot on input 8
' Input voltage range 0 = 3.29
' Servo control requires a range of 0.5 to 2.2 for
' full range.

SetPin 15,8
SetPin 8,1

Main:

c = Pin(8) 'analogue input from pot
Pause 40
position = ((3.29-c)/1.6)+0.5 'calculate range required form analogue input
If position < 0.5 Or position > 2.5 Then 'check input range is within limits.
GoTo Main
EndIf
For a = 1 To 45 ' set servo output - 50Hz pulses mark space ratio
Pulse 15,position ' determind by input analogue.
Pause 20
Next a
Pause 20
GoTo main
[/code]

BillEdited by Bill.b 2013-03-12
In the interests of the environment, this post has been constructed entirely from recycled electrons.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:05am 11 Mar 2013
Copy link to clipboard 
Print this post

  TZAdvantage said   I was actually thinking about the accuracy of the 50hz cycle.
A hardware 50Hz ties up a PWM pin and an input pin while a SETTICK ties up nothing.

The accuracy of the 50hz pulse period (i.e. repetition rate) is not important for servos.
  TZAdvantage said  
If both have the same accuracy, my preference would go to the SETTICK because it requires no hardware connections which will result in a solution that can be used by more people. For example a CMM has the PWM pins occupied with resistors and capacitors making it an analogue output and not available for digital uses without desoldering those compenents.

Yes, modding the MM or CMM to use the PWM output at full voltage is a small issue, but they're both through-hole boards and it's a five minute job and was envisaged and described in Geoff's March 2011 Silicon Chip article. It will be more difficult for SMT versions unless the PWM output voltage divider has jumpers or something to access the full voltage.
I'm not saying the PWM/interrupt method is preferable at all - it's just an option. The SETTICK method will be better for many uses no doubt.
  TZAdvantage said  
An argument against using SETTICK would be that it has a lower priority and lower speeds as 1 millisecond is the fastest you can set it up with. The low priority will not make a difference when no other interrupts are used.

Since the SETTICK interrupt will always be at about 20mS (50Hz) it should have plenty of speed for one servo, but trying to use multiple servos might be a challenge.
  TZAdvantage said  
If i read the manual correctly when using multiple interrupts it would be impossible to detect if you missed one as interrupts are disabled while in a interrupt routine.
This is making time critical interrupts only work properly when there is only one source of the interrupt and the routine that is invoked is faster then one cycle.

Since the pulse repetition rate is not at all critical for servos, it would be interesting to see if missed interrupts were a problem at all in practice - I suspect it wouldn't matter (within reason).
  TZAdvantage said  
If more time based uses are necessary SETTICK will solve that problem in software, as long as the routine is fast enough. SETTICK can be setup only once, but in the routine you would be able to have multiple routines even on different cycles by counting the invocations.

I'm not sure how that would go in practice again, but you might be right. It's a very common requirement to control several servos (say 4 or 6) at the same time e.g. for model planes/cars/robots. Maybe Geoff could come up with a special command for multiple servo control.
  TZAdvantage said  
Also something to be aware of is that the interrupts are checked by MMBasic in software between interpreting basic statements. Your program does not directly respond to an interrupt, MMBasic is the 'director'.
This will cause a small difference is reaction time and will not work during an INPUT statement.

Yes, but again the repetition rate for servos is not critical, just the pulse width. The INPUT statement blocking interrupts though, is certainly an important issue. Programs will need to carefully watch this else someone's favourite expensive aeroplane might bite the dust!

Greg
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 02:21am 11 Mar 2013
Copy link to clipboard 
Print this post

My personal favorite way of controlling things is through I2C.
MMBasic is then the 'manager'.
I have one of these, never used in combination with a CMM though but it should be very easy:
http://www.hobbytronics.co.uk/servo-controller-12ch-ht

The chip has no markings, i suspect it to be a PIC.

I would not want to control more then 2-3 servos through basic. It gets complicated quick.

Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:28am 11 Mar 2013
Copy link to clipboard 
Print this post

  Bill.b said   Hi Greg
I would check the ratting of the SG90 servo, the specs on DX.com
rate it at 9g not 2kg. There seems to be some conflick on rattings on there web site.

Hi Bill,
I looked at a number of e-Bay and an Australian site and they all quoted 2Kg torque.
One U-tube video I saw also had the SG90 under a thick book which would have weighed close to that. It lifted it up when activated so I think 9g torque is unlikely; but then it depends on the units so maybe it's 9g/meter They should all quote the full units really. Perhaps the 9g refers to just the motor shaft and not the geared output. Mind you the SG90's pretty small and made of plastic so I wouldn't push it.

Good to see another servo type working with MMBasic - there could be lots in future. Looking at your code I can see it would work fine standalone but the PAUSES might cause you trouble when it's incorporated in a larger program. That's the reason I use the two interrupt methods.
Greg
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:45am 11 Mar 2013
Copy link to clipboard 
Print this post

  TZAdvantage said   My personal favorite way of controlling things is through I2C.
MMBasic is then the 'manager'.
I have one of these, never used in combination with a CMM though but it should be very easy:
http://www.hobbytronics.co.uk/servo-controller-12ch-ht
I would not want to control more then 2-3 servos through basic. It gets complicated quick.
That looks a very handy chip - it would be fun to try one out with the MM. I think I'll have to get one Mind you, then I'd have to get several more servos to see how they worked...hmmm... Wonder how my brownie points are going?
 
mindmadness45
Newbie

Joined: 28/04/2013
Location: Australia
Posts: 1
Posted: 10:28pm 27 Apr 2013
Copy link to clipboard 
Print this post

Hello everyone,

I know this is an old thread but I think I better chuck my opinion in before someone rips their hair out at why the MaxiMite's PWM is failing.

The problem isn't to do with the MaxiMite at all. It's to do with your PWM signal. Oddly enough, the Tower Pro SG90 you are using is one of a few small servos that don't conform to the 50Hz control signal standard.

I am currently using these servos in a Uni project with an ATmega128 development board. I initially was reading up on servos and found that most run with a 1-2ms pulse every 20ms. This is not the case with the SG90 and also some of the smaller HobbyKing motors I have been helping others with.

The SG90 actually operates on a 1-2ms pulse every >>15ms<< (so thus at 66.67Hz). When programming PWM for them using the ATmega, I was noticing a very shaky movement in what should have been a smooth rotate left and then right. After having worked to get my code to work with my friend's HK servo, I tried the same PWM signal with the SG90 and that solved the problem.

So for those using the SG90, the following stats apply:
Signal Pulse: 1-2ms (0.6-2.3ms for my SG90)
PWM Signal: 66.67Hz
PWM Period: 15ms
Voltage: 3-7.2V


Hope this helps,
Sam.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 04:28am 28 Apr 2013
Copy link to clipboard 
Print this post

Hi Sam,
I'll check that out but it doesn't seem to me to be the problem with my Maximite. When I run an exact 50Hz (20ms) pulse train to the SG90 (checked with a 'scope), using the Maximite PULSE command and timed by the interrupt driven TIMER command, the control is quite smooth. When I obtain the 20ms pulse train using the PWM command though, the servo control is not smooth - it moves in "jumps" equivalent to a pulse width difference of about 0.2ms.

From what I've read, the frequency of the pulse train can vary over quite a wide range so if the pulse train is at 50Hz or 66Hz it may not matter. I'm not sure there is a "standard" at 50Hz for the frequency, it just seems to be "the normal".

BTW my SG90 has a 0.6-2.2 pulse width range, very similar to yours and I'm using a 5v servo supply.

Greg
Edited by paceman 2013-04-29
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 04:39pm 29 Apr 2013
Copy link to clipboard 
Print this post

Hi Greg,

Did some testing on my Duinomite re PWM and I think I may have the answer for you.

I believe it comes down to definitions: Accuracy versus Resolution.

Looking at Geof's source and my tests, the resolution of the duty cycle component of the PWM command is 1% of the period. ie. integers 1 to 100; any fractional component is rounded up or down to a whole number.

For example PWM 50,2 gives a 400uS pulse every 20mS and increments 200uS for every percentage change in the duty cycle.

PWM 1000,2 gives a 20S pulse every 1mS and increments 10uS for every whole percentage point change in duty cycle.

For any testing that I can do, there is no detectable change in pulse width from pulse to pulse (in my case,that equates to less than 0.1%)

So, the resolution of the duty cycle component of the PWM command is 1% of the frequency and the accuracy of the pulse width, WITHIN THE CONSTRAINTS OF THE RESOLUTION, (not shouting, just emphasis :-) ) is less than 0.1%.

Hope this helps you,
Regards, Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 05:01pm 29 Apr 2013
Copy link to clipboard 
Print this post

Greg,

As a further thought (untested), if the PWM command is inside a loop that has a shorter cycle time than the pulse width then it will never get to complete - this may explain the need for your pause command.

Haven't tested this theory yet.

Cheers, Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 07:30pm 29 Apr 2013
Copy link to clipboard 
Print this post

Greg,

A little more on the pause issue - hope I'm not hogging the discussion :-)

When the PWM command is inside a loop, there is no way of determining, when, in the pulse train, the new PWM command will be executed. Thus if the PWM command was processed during an existing pulse period, that pulse would be truncated and the new sequence commenced.

Looking at the output of the PWM command on an oscilloscope with the following code -

Start:
PWM 50,50
Pause 1
Goto Start

With a pause of 1, there is no output. As the value of pause gets up to around 20, output is seen but it is unstable ( in that there is an asynchronous missing pulse as the PWM command is processed).

As the pause is increased up toward 50, the instability decreases steadily ( that, is less missing pulses due to conflicts). Upwards of a pause of 200, the missing pulses are barely noticeable. I will be able to be a bit more definative in a couple of weeks when my new toy, a little logic analyser arrives :-)

I guess the bottom line is, best not to use PWM inside a loop if pulse integrety is critical.

Cheers, Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:30am 30 Apr 2013
Copy link to clipboard 
Print this post

  panky said  
So, the resolution of the duty cycle component of the PWM command is 1% of the frequency and the accuracy of the pulse width, WITHIN THE CONSTRAINTS OF THE RESOLUTION, (not shouting, just emphasis :-) ) is less than 0.1%.
Doug.

Hi Panky,
Your explanation sounds right to me - a 1% resolution limit at 50Hz equates to the 0.2mS pulse width jumps I see. Whether those pulses are accurate to 0.1% or better becomes a bit irrelevant, for servo control, when they can only increment in 0.2mS steps.
  panky said  
When the PWM command is inside a loop, there is no way of determining, when, in the pulse train, the new PWM command will be executed. Thus if the PWM command was processed during an existing pulse period, that pulse would be truncated and the new sequence commenced.
Doug.
Yes, Geoff made this point earlier and you can see the effect when you add extra code (like printing volts/pulse width etc to the screen) within the loop. It's another reason that using PWM for servo control is a problem.

That still leaves us with the other two PULSE command options though, i.e. PULSE and SETTICK or PULSE triggered by interrupt pin connected PWM output. Both of these work very smoothly.

Greg
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024