AVR generated 12v pulse, just for fun

Go To Last Post
64 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also added an npn version, and changed the diodes to bat41 type to make up for the losses.

What keeps the voltage at 12V?  Prob unregulated & just happens to land near there, depending on load...Your other circuit had zeners!

 

You could prob mod the charge pump duty to perform starvation regulation  via the ADC

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>What keeps the voltage at 12V?  Prob unregulated & just happens to land near there, depending on load...Your other circuit had zeners!

 

Will probably get lucky if it makes it much over 12v, and if it does I doubt the other end will care with only couple milliamps available at most (which also drops the voltage as it ramps up the very little available current it has). I think the datasheet says max 13v on the reset pin, and I think I read somewhere its probably happy with its '12v pulse' somewhere around 2xVcc, so an exact 12v is probably not that necessary and could also get by with 'normal' diodes and stay in the 11-12v area without any problems.

 

I would like to see the result of whatever happens here, but I have given up caring about using a updi pin for gpio use. If I need to use all the available pins I will move up to the next model with more pins to keep the programming pin free. The big advantage is there is only one in this case. Maybe when using an 8pin tiny it makes more sense, but an 8pin soic vs a 14pin soic is not much difference in price or size. When you move into the higher pin counts you also have the smaller sized packages available.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to keep this alive.   I'm working on compensator design for the following:

 

with Vi = 5 v, L = 330 uH, C = 1uF, R = 12, R = 12 kOhm.    I have derived linearized TF from duty cycle, to Vo.   I'm looking to run the control loop at 10 kHz, so I've added a .5 ms delay for ADC and computation.   The compenator is (s + 8)/(s +1)*(s + 80)/(s^2 + 200*s + 10000)*100/(s + 100).   The loop transfer function C(s)*P(s) looks like

where the orange box shows 10 dB gain margin and 45 deg phase margin.  The squiggle to the right of the box is the Bode step.  The design provides dc gain of ~95 so that for 5 v offset we get ~ 0.05 v hangoff.

 

more later ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

You prob don't need any graph or equation...simply measure the output voltage with the adc perhaps 200 times a second.  If the voltage is too low, increase the duty cycle by one step.  If it is too high, decrease the duty cycle by one step.  If it is an 8bit PWM, you have 256 choices (256 different voltage levels). The voltage will then be well-maintained at the desired setting (unless you have a severe transient somewhere).

 

You can code this up in probably 15 minutes & have it working great.

 

You can get fancier---if the voltage is way too low or too high, take bigger steps.  To prevent voltages chatter you can add a few steps of hysteresis.

    You can increase the apparent number of bits, one or two, by toggling between two duty cycle counts...this will be averaged out by the load capacitor, effectively giving finer voltage levels   

    You can add equations (such as integrating the long-term error & looking at the rate of voltage change (derivative) & correcting (predicting) the stepping.  

 

 

Opamps being "dumb" devices don't have this luxury & you are back to needing equations & so forth just to get started.  You don't get as many easy ways to talk with your opamps. In his case, software is king.

 

Mr Edison appeared with a a pear-shaped glass bulb.  Mr Edison asked Upton to calculate its inner volume. Upton was a very able mathematician, who after he finished his studies at Princeton went to Germany. He drew the shape of the bulb exactly on paper, and got the equation of its lines with which he was going to calculate its contents. Mr Edison appeared later on and asked him what it was. He showed Edison the work he had already done and told him he would very soon finish calculating it. "Why," said Edison, "I would simply take that bulb and fill it with mercury and weigh it; from the weight of the mercury, I'll get it in five minutes.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. Oct 20, 2019 - 08:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I could kludge a design together, but then if you don't get the performance you want you usually end up tinkering with it (i.e., trial and error) to get it to work right.  I'd rather start from design requirements and put together a design on paper that works, and debug that.   Good control designs often provide the cheapest design for meeting performance (e..g, equations and lines of code are cheaper than bigger, or more, parts).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldn't call either method a kludge & there is probably some tweaking for both.  If you are investigating the time domain response, a method in the time domain is easier to diagnose.

 

The compenator is (s + 8)/(s +1)*(s + 80)/(s^2 + 200*s + 10000)*100/(s + 100) ...I suspect that more terms will be needed, due to nonlinearities & non-ideal parts.   What happens to the equations when few more parts (tweaks)are added?

 

The method I proposed requires essentially no computational load on the AVR & almost no programming---not even a division routine & allows fast reaction (ultimately limited by adc speed).  You can try it within minutes & see if it performs to your liking--no need to spend all day simulating. 

 

I'd be first to agree that if you want the highest humanly possible performance, a full set of equations and nitty modelling would be wonderful.   On the other hand "I need to generate 12V"  is along the lines of "I need a hamburger"  & Wendy's or Burger King is probably fine.

 

but wanting to post to keep the thread alive.  

 keep things simple ...you'd would have already had it working...and quite well. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Sun. Oct 20, 2019 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MattRW wrote:

AVR generated 12v pulse, just for fun

Emphasis mine.  No need to critique the OP's technique, he made clear at the beginning why he was doing this.

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am following this as a particularly interesting thread, don't see where any critique has been made.
avrcandies method is the same as I used, earlier on I called it "live spice", which is a term I phrased some 20 years ago.
Got it all working fine, using it in a solar charging device.

Last Edited: Mon. Oct 21, 2019 - 11:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

update: I have posted some code for handling the switch with varying duty cycle using timer0 in Fast PWM mode.  See here.

 

The next step is to create a task that operates at about 10 kHz to control the duty cycle as a function of measured output voltage.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The control loop is usually slower than the pwm freq. Reason being the capacitance on the output forms a pole so the output voltage can only change at a slower rate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For my deisign I plan PWM to have period  ~ 1/256 kHz; control loop sample rate of  ~ 10 kHz;  control loop bandwidth ~ 100 Hz.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can probably get by with a lot slower sampling rate---if you are varying the adjustment 100 times a second, that should be plenty.

I you look at a power supply do you need to check it 100 times a second?  Maybe for transients, especially if the capacitors are on the small side---otherwise, they keep things nice & steady. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I decided to try my previously shown circuit since I was testing tca on the mega4809 (and see if simulated matches reality). I had some unknown small diodes (0.5v on diode check) and a few 10uf caps handy, so just used 3 of each as the only parts, without any output control. The tca is sending out 10kHz in freq mode on tw0 cmp pins, each with opposite polarity. The Vcc measures 4.7v, and the unloaded output at the last cap is 13-14v. I only had a 1k resistor laying around which was too much load, so unable to check what it can drive at the moment. I also had a 12v zener so put that on the output to keep it at 12v (when unloaded anyway).

 

The test code-

 

//headers here

int main(){

        //set clock to 10MHz
    Clkctrl::setupHiSpeed<10_MHz>();

 

        //PE0=WO0, PE1=WO1
        //2 frequency outputs of 10kHz, opposite polarity
    Tca< Tca0_E > tca;
    tca.freqMode( tca.CMP0, tca.OUT_NORMAL, 10_kHz, 10_MHz );
    tca.freqMode( tca.CMP1, tca.OUT_INVERT, 10_kHz, 10_MHz );
    tca.on();

   

    //my control loop :)

    for(;;){}

}

 

With some fine tuning and output control added, it would probably work pretty well for updi 12v use.

 

Edit-

adding a 10k load, voltage is at 12.1v, so it can do 1.2ma anyway.

Last Edited: Thu. Nov 7, 2019 - 03:05 PM

Pages