Search This Blog

Saturday, August 4, 2018

Single servo for propulsion and steering

Projects / Wacky hacks

Most of the bots etc employs multiple servos. It is possible to do more with a lot less?

This is a Sampai that uses a single long sculling oar called a yuloh for both propulsion and steering. The operator row the oar back and forth similar to a fish's tail.


Analysis

When the oar pushes against the water, it causes an opposite reaction force. This force can be resolved into a vertical (Fy) and horizontal (Fx) vector components along the axis of the boat. Fx moves the boat forward while Fy tries to move it sideways.


The sideways force (Fy) cancels out over time when the oar swings symmetrically side to side.


What happens when the Oar is offset to one side?
The vertical component no longer cancels out (Fy' - Fy >0), and so the boat turns right.

When the angle ɵ is small, most of the force is in the side way direction. By slowing down the swing during small ɵ, this thrust can be minimized.
So what happens if the forward motion is faster than the return?
There will be more force produced in the forward pass. (In theory) the boat can be made to move backwards.

Could all of this be duplicated using a single servo using some clever programming?

Links:
http://www.theholidayspot.com/chinese_new_year/crafts/chinese_sampan/ How to make a model
http://freepages.genealogy.rootsweb.ancestry.com/~fassitt/cranks/cranky_sampans.html

I have written a table driven servo driver for my STM8 breakout board.
ServoStep.Table point to a table that contains the From, To values as well as the number of Steps.

const ServoTable_t Forward_Tbl[]=
{
 { TIM2_SERVO_SCALE(0),TIM2_SERVO_SCALE(30),5 },
 { TIM2_SERVO_SCALE(30),TIM2_SERVO_SCALE(90),1 },
 { TIM2_SERVO_SCALE(90),TIM2_SERVO_SCALE(90),5 },
 { TIM2_SERVO_SCALE(90),TIM2_SERVO_SCALE(-30),20},
 { TIM2_SERVO_SCALE(-30),TIM2_SERVO_SCALE(-90),1},
 { TIM2_SERVO_SCALE(-90),TIM2_SERVO_SCALE(-90),5},
 { TIM2_SERVO_SCALE(-90),TIM2_SERVO_SCALE(0),15}, 
 { END_TABLE,END_TABLE,0},
};

The forward thrust is produced when the servo moves rapidly between (30° to 90°) and (-30° to -90°). The servo moves slowly between these end points to minimize the unwanted thrust.

Once the Timer and interrupt is initialized, channel 2 of timer2 (pin 20) is used to generate a PWM waveform to drive a servo. The period is set at 20ms (50Hz) and the waveform is 1ms to 2ms.

The following IRQ gets called at the end of each cycle and the servo is incremented/decremented. If it reach the maximum steps, then the next entry of the table is executed. If it reaches the end, it wraps around to the beginning of the table.

// Call everytime TIMer2 overflows (50Hz)
@far @interrupt void TIM2_Update_IRQ(void)
{ 
  TIM2->SR1 &= ~TIM2_SR1_UIF;     // Clear update IRQ

  if(!ServoStep.Table)      // turn off servo
  {
    ServoStep.PWM = SERVO_OFF;
    ServoStep.Index = 0;
   }
  else
  { 
    if(!ServoStep.Steps)     // Initialize PWM parm
    {
      if(ServoStep.Table[ServoStep.Index].From == END_TABLE)
        ServoStep.Index = 0;
   
      ServoStep.PWM = ServoStep.Table[ServoStep.Index].From;
      ServoStep.Delta =(ServoStep.Table[ServoStep.Index].To -
                        ServoStep.Table[ServoStep.Index].From)/
                        ServoStep.Table[ServoStep.Index].Steps;
            
      ServoStep.Steps = ServoStep.Table[ServoStep.Index].Steps;
      ServoStep.Index++;   
     }
     else                            // Step the servo
     {
       ServoStep.PWM += ServoStep.Delta;
       ServoStep.Steps--;
     }
   }
 
   if ((ServoStep.PWM >= SERVO_MIN) && (ServoStep.PWM <= SERVO_MAX))
   { // Set PWM
     TIM2->CCR2H = ServoStep.PWM >>8;
     TIM2->CCR2L = ServoStep.PWM;
    }
}

I made a "C" shaped cutout on a foam board. I screwed in a standoff with a pan head screw on one end and glue it to a styrofoam tray. I used some White Glue. (It wasn't strong enough, so I added in some hot glue to the side afterwards.)


The "Tower 9g microservo" is mounted on a small piece of clear plastic (from a dollar store picture frame).


The servo arm is attached to the oak with the wire from a couple of paper clips.


I used the insert from a "wire spicing" connector to extend the length of the paper clip.


The servo is powered from a USB battery pack. The inertia from heavy battery pack helps to stabilize the erratic movement of the boat.


I ported the IR Remote code from my Automatic audio source switching project.  Straightly speaking this has nothing to do with propulsion, but it makes life a bit easy for running a demo without a tether.

I have to make a few minor modifications as STM8S003 (8-bit) has less resources than STM32F030 (ARM M0).

  • I have to share timer 2 for both servo and IR remote.  Servo PWM is set for 50ms timer reload (0x9c40).  Measuring input pulse width is slightly more work as the code has to keep track of whether or not a timer reload has occurred.
  • STM8S003 input capture cannot be triggered on both edges, so the code has to toggle between rising and falling edge.
  • The usual I/O register, IRQ difference.
The rest of the IR  code seems to work as is.

I am using my TV remote with NEC2 IR protocol.    Each byte sent is followed by its 1's complement for error checking.  NEC2 extends the 8-bit address code to 16-bit by sneaking it into the 2nd byte.  Byte 3 is 1's complement of command byte in byte 2.

The following shows the raw IR code captured from the debugger.  The device code for my Insignia (Bestbuy house brand) TV is 0x8615 and the command code is 0x15.

IR Commands for the menu navigation buttons:  Left = 22, Right = 21, Up = 66, Down = 67, Select = 24.


My logic analyzer can only decode NEC1 IR protocol, so it complains about address error and stopped processing.  :(


I added a 7 segments LED for visual feedback for the IR commands.  F= forward, L = Left, r = Right and Off = Stop.


 IR receiver is at lower left hand corner.

The dog almost eat my homework.  STVD delete 1 of the source file, failed to update 2 files before it crashed. It did managed to write the deleted file to a temp file.    Ooops.  :(


I got the IR remote code and servo code working together.  The row boat can now be controlled from my TV remote.   I have added left turn and right turn to the code.

I have recorded a new video of the boat in action for the contest entry:
Source code have been pushed to github: https://github.com/FPGA-Computer/rowboat



PSU - Chinese current sensing modules

Projects / Smart Bench Supply

I guess I forgot to look at those popular Hall Effect current sensors from China using ACS712.


The parameters Noise and Total Output Error are the ones of interest.  The total output error isn't too bad and in some cases can be calibrated out.


There is a tradeoff between the amount of noise vs bandwidth.

Resolution: 21[mV] / 185 [mV/A] = 0.114A (typ) for a 47nF cap. This is the part that fails this application.


I guess that's why those Chinese ACS712 modules are cheap.  The ACS723 based modules are available elsewhere, but not yet from China until the existing cheaper stocks of ACS712 runs out.


The new replacement part seems to be improvement on the noise, but worse on the accuracy.



The other popular modules are MAX471 (pdf)  which is also designated ''Not for New Design''.


Here are the gotchas: minimum input voltage and large error at current below 0.1A.


PSU - MIC29302A graph makeover

Projects / Smart Bench Supply

I was trying to find the ripple rejection spec for the MIC29302, but found a pre-Microchip MIC29302A datasheet: here  It seems to be a slightly different version (low cost) of the chip for 20V operation.  While it is a different chip, it would be from the same base design and can give some rough idea what to expect.


It is hard to read off the log scale.  A bit of messing around with Excel graphing option, I got myself a semi-log graph.


After some image editing and fooling around with transparency and scaling, I superimposed the grid onto the graph.


The ripple rejection drop to about 5dB at around 250kHz.  Above that, it is mostly the bulk decoupling cap doing most of the filtering work.

XL6009 Buck-Boost converter switches at 400kHz, the ripple rejection is ~15dB. What this means is that if the ripple at the LDO input is 10mV p-p, the amount of ripple at the output:

10mV * 10^(-15/20) = 1.77mV p-p

Chances are that the ripple from cheap Chinese modules could be pretty bad.  They have a small LC filter using a small inductor and a MLCC.   I don't know the extent of its performance until it arrives.

PSU - Proof of concept - low voltage supply

Projects / Smart Bench Supply

I need an analog supply for testing my energy harvesting project as my switch mode bench supply can be a bit too noisy.  This is what got me thinking about building an analog supply.

I have used a resistor divider up to this point, but needed something that can source a bit more current.

This is a quick and dirty proof of concept hack of a MIC29152 (1.5A Adjustable) to show that it is possible for its output to go below the 1.24V reference with the help of feedback magic.


It is wired as an inverting amplifying of gain -1 and reference point at 1.24V (instead of usual 0V)  The 10 ohms provides a minimum load (>5mA) for the LDO and needs to be reduced for output below 50mV.

This is just a quick hack.  The voltage adjustments are bit finicky.  Without properly closing the feedback loop to a more stable reference, it isn't all that great.  It is already an improvement over a resistor divider.


I have notice that the LDO needs at least 1.6V to operate correctly.  Reading between the lines of the following dropout characteristics points to a similar value.  Officially they don't list the minimum operating voltage spec as they expect its output to be >=1.24V, so by the time you add in the minimum dropout for the load, you would have meet the requirement.


This has been accounted for in the control voltage design.  I might need to increase the voltage slightly.

PSU - High side current sense

Projects / Smart Bench Supply

I have decided to move this topic outside of my main page as I am still not happy with what I have.  Some of you might question my sanity of not using a proper part.   They all look fine at first glance until you go and read the datasheet.  That's why I still have some INA201 unused.

7.4.2.4 Low V SENSE Case 2: V SENSE < 20 mV, 0 V ≤ V CM ≤ V S

For my application, it can fall within this condition.  One way to get around this is to add 20mV offset to the input.

For the INA201, this is a 50V/V * 20mV = 1V offset at the output that I have to remove.
It is ~1/3 of the input range of my ADC.

LT6100:


The common mode range is Vcc + 1.4V to 48V.  This means that the part has to be sitting on a negative rail and the output needs to be level shifted.  Unfortunately I only have one of these in questionable condition.

Old details page archive as follows:

High Side Current Sense

The high side current sense circuit is a lot more complicated because of requirement 2.

  1. The load current can be sensed at the output of the LDO as it draws different amount of currents based on supply voltage, temperature and load requirements. The feedback resistor needs to be connected after the sense resistor to compensate for the drop.
  2. VCC rail can reach 0V.


R3 is the current sampling resistor.  This adds up to 0.05R x 3A = 0.15V drop at full load.

The I*R voltage drop is level shifted to a negative rail via a voltage controlled current source (R5, R2, U3 and M2).  The negative rail provides a DC offset for the circuits to work as V2 can sometime drops to 0V.  The voltage gain is set by resistor ratio of R2/R1. A gain of 20 gives 1V/A.

Voltage across R2 drive a voltage controlled current sink (U2, R1 and M1). This current is converted back to a ground reference voltage using a transimpedance amplifier (U1 and R4). The ratio of R4/R1 determines the voltage gain.


---------------------------------------------------------

This is a revised version.  The constant current circuit has been replaced. The 20K resistor is on a DC offset as the opamp buffer U1 cannot swing to 0V. The offset is subtracted off with the different amplifier.


There is an issue with the opamp Vos interfering with low current reading. LTSpice thinks it is about 20mA, but it'll be better or worse depending on luck. 


Note: the constant current sink, level translating circuits are left out.  Revise circuit here.

This is not easily solvable with common parts as the common mode input of opamp needs to include the positive supply rail.  A precision opamp with low dc offset does not usually reach the positive rail.  A rail to rail opamp compromises by using two complementary input stages to cover the entire input range resulting in the following type of performance - good in the middle but worse off on either ends of the rail.  If we are talking about trimmed parts, but those are unicorns.


Fixes:

The value of sampling resistor can be increased so that this nonlinearity will only show up for a lower current. The minimum LDO load can be used to move the operating point above this.

2. TI INA201
As mentioned before, this requires a 20mV offset to be inserted into input and 1V removed from the output.  A precision voltage reference, a voltage divider, a floating supply and opamp for subtracting the output are needed.  I do have some samples of this.

3. Analog/LinearTech LT6100
This requires operating from a negative supply to meet the common mode requirement and an opamp to convert the output back to ground reference. This approach has the least complexity with less gotcha.  I only have one sample.


There are some non-linearity below 8.6mA.  We can operate above that by increasing minimum LDO load slightly.


The -5V rail can be provided by a switched cap converter.  A RC filter is needed to clean up the output.


As the negative rail is initially ramped up, there is a glitch at the output.  It is not something that would cause any issues.



While looking through my own project directory under Current sensing, I rediscovered a part: MAX44284  So far I have not found any flaws yet. It is worth looking at if you require accurate current sensing.

  • Very Low 2μV Input Offset Voltage (MAX44284F/H)
  • Extremely Low 50nV/°C Input Offset Tempco
  • Low 0.05% Gain Error
  • -0.1V to +36V Wide Input Common-Mode Range - covers full range without needing a work around.


The only reason why I might not be using this is that I don't own any of these parts. It is much hard to get free samples these days.


PSU - AC/DC front end noise considerations

Projects / Smart Bench Supply

Over the years I have seen a lot of DIY bench supplying using modified PC PSU or laptop supply as their AC/DC frontend.  Instead of the blanket statement of "SMPS is bad news", I am going to sit down and explain why I won't be doing that and rather be using a big heavy hunk of copper and iron for my front end AC/DC conversion.

This is the block diagram of a common AC/DC converter.  There are two type of high frequency noise: Differential and Common Mode.  The differential noise is filtered with an inductor (or leakage inductance of a common mode choke) and a "X-cap". The common mode noise is filtered with a common mode choke and forces to go to "Earth" ground a pair of "Y-caps".  (see pdf for filtering)  The amount of conductive and radiated noise is governed by regulatory standards such as FCC part 15.


The story doesn't end there as some of the high frequency common mode noise can reach the second side by means of parasitic capacitive coupling.  The problem is when the secondary side is not grounded.

Those old boat anchor 50/60Hz transformers don't have a high enough frequency for the capacitive coupling to work.


The following picture shows such a power supply.  There is a yellow Y-cap sitting between the Primary and Secondary side.  Usually it is right next to an opto-isolator that is part of the feedback loop.  The Y-cap is connected  between the low voltage 0V and the "Earth" ground.  It allows the Common mode noise to flow back to the "Earth" ground.  The AC grounding isn't perfect as the capacitor has a non-zero impedance.  Some of the noise still persists on the secondary side.  It'll try to go to the "Earth" ground through whatever least impedance path e.g.  I/O in your device.


It gets even worse for those laptop supplies without a "Earth" ground connection. Let's say that tingling sensations when you touch the metal part of a laptop are not your spider senses.  It is small enough to not hurt you too much but will cause enough of a noise problem for sensitive analog circuit.

Reference:
Block diagrams are from:

Journal of Engineering and Development, Vol. 16, No.1, March 2012  ISSN 1813- 7822 , "Practical Approach in Designing Conducted EMI Filter to Mitigate Common Mode and Differential Mode Noises in SMPS", By: Nidhal Y. Nasser Assistant Lecturer, Electromechanical Eng. Dept.,University of Technology
(pdf)

Smart bench supply

Projects / Smart Bench Supply

This is a work in progress.  It is a bit on the low priority side as I already have 2 60V 5A bench supplies.  I found that I need a low noise supply with very fine and precise voltage adjustments that can go to tens of mV in part of my Boost converter for low voltages project.  My usual bench supply just wasn't good enough for this type of work.

I attempt to improve its output current, range and efficiency by using switch mode supply with LDO post regulation. The voltage accuracy and resolution is only limited by the ADC.

One thing to take away from this project is learning to read between the lines in the datasheet and understand the limitations of parts in the fine prints. Simulations are useful to find potential issues before building or even committing to the parts.

Simulation

Simulation is a good way to try to build something without building it.  You can measure things in circuits that are difficult to do so in real life.

Here it is the block diagram Microchip/Micrel MIC29xxx series LDO that span the range of 1.5A  to 7.5A.


There are a lot of features built into a LDO like this: Thermal shutdown, Enable pin, Over-voltage protections etc that are messy to replicate in a discrete design.  You can get higher output current by simply upgrading the chip.

The ripple rejection performance is probably similar to this.

Minimum load requirement 

The LDO has a minimum load of about 7mA required.  Normally this is factored in the feedback circuit, but I have decided to separate this out with a constant current sink at about 7.5mA. This removes the thermal and high voltage rating away from the feedback circuits.



Here is the simulation result.  The circuit sinks about 7.5mA (Cyan) over most of the output range except when the voltage drops below 0.7V.  It is effectively a 82R load below 0.7V.  An opamp based circuit could reduce this voltage.


It is not a LDO if you don't intend to use it as such

The big problem with designing a linear supply is the output current and range is limited by the thermal budget.  A switch mode supply can be very flexible and efficiency.  It has a bad reputation of being a bit more noisy, but the noise can be reduced with filtering and post regulation.

For the MIC29302, the dropout voltage over the full temperature range is about 0.5V.  The power dissipation is only 1.5W at 3A load at 0.5V drop.  It gets a bit higher for the 7.5A part, but it is still easily manageable with a heat sink.


So the big question is how to servo the switch mode supply?

Both linear and switch mode supplies can be view at as an inverting amplifier at the DC level.  The usual opamp summing circuits works here. There are no need for haphazard control circuits like this.

This can be simplified to the figure below.  It is simply an opamp + output stage circuit connected to an internal reference.  I have made a proof of concept supply that shows the output can be set close to 0V.



Similarly a switch mode power supply at steady state can be simplified to something like that too.

LDO


U1 and V2 simulates the LDO.  The control voltage is set at R8, R1 is the voltage feedback from the output. In this case, I subtracted ~0.6V to account for the dropout voltage by using R9.

Switch Mode Supply

U3, R3, R5 and V5 simulates the switch mode supply.  There is a bit of a twist as the voltage voltage is not allowed to drop all the way to 0V.


Since U3 is wired in an inverting amplifier, it means that I have to stop the control voltage from going above a certain point.  I wired U4 as a regulator with the output set by voltage divider R4 and R12.  The output follows the input untils it tries to rise above the threshold.  U4 counteracts and maintain the voltage by reducing the bias to M2.

These are buck converters based on XL Semi XL4015 (180kHz 5A) pdf


A buck-boost converter allows the output to have a wider range than the input voltage source. Common ones based on a fake "XL Semi XL6009" are fairly cheap. It is probably a remarked XL6019 (180kHz 5A) instead of the "400kHz" because I can see the 180kHz switching waveform.  As a result, the ripples are a lot higher than advertised.


I have ordered both of these and they are going to take a very long time.

This is how everything fits together.  U2, U4 are the opamp for the control circuits. Blocks with U1 and U3  simulates the power supplies.


Control voltage

Each of the supplies regulates its voltages independently but are controlled and trimmed by U2.  U2 will be replaced by an integrator and a microcontroller feedback control similar to this.

The integrator approach has a lot of advantages.
  • It is cheaper than a DAC as it uses a cheap opamp and a capacitor.
  • Its output voltage resolution is only limited by the ADC.  Both the ADC and DAC resolution can probably be increased to 13 or 14-bit (if needed) using Over-sampling.  External ADC e.g. ADS1115 Delta Sigma 16-bit ADC (available as $2 modules) can also be used.
  • It is not a noisy reference like PWM. The change to the output voltage is very gradual and quiet.
Because the control voltage is from a inverting input (vs non-inverting in the original design), this doesn't suffer from the power up glitch as the integrator cap charges up during power on.

The two regulators are decoupled from each other by design.  The changes to the feedback circuit does not affect the AC load transient response of the regulators. The control voltage is merely a low frequency component applying a DC offset to the output.

 The following simulation waveforms shows the output of the LDO (Red) and the switch mode supply feeding it (Blue).  The green traces show the voltage difference which is normally about 0.6V.  The switch mode output does not go all the way to 0V (even though it can) to provide a minimal operating voltage for the LDO. The two regulators have slightly different reference voltages, so there is a slight voltage variation over the entire range.


High Side Current Sense

High side current sense
Chinese current sensing modules - tl;dr They are all useless for this application

Overcurrent limit

The overcurrent limit is set by using a PWM as a cheap DAC.  For a 3A full scale output, 10-bit resolution corresponds to 3A/1023= 2.93mA

With a 48MHz timer clock, 10-bit PWM produces a 46.9kHz output signal which can be filtered easily.


The opamp compares the current limit threshold vs the current sense signal.  Its output overdrives and raises the control signal to decrease the output voltage. The opamp output level will be above 2 diode drops which guarantees the NPN transistor will be able to turned on to drive a LED. The diodes prevent the circuits from interfering with normal operation.


AC/DC front end noise considerations

Links:
Analog Device/LinearTech AN105: Current Sense Circuit Collection
Diode Inc: AN39 Current measurement applications handbook
Current sensing