Since you are doing a gated oscillator switching converter, you could 
consider using the on-board comparator of this particular MCU instead of 
the ADC. Might save you some code/CPU time.

Alex

On Monday, November 25, 2013 7:55:12 PM UTC, petehand wrote:
>
>
>
> On Monday, November 25, 2013 7:13:52 AM UTC-8, Chris Stalin wrote:
>>
>> LOL, Love it. Great work!
>>
>> Are you PWMing a FET for power from the atmega158?
>>
>> Yes I am. Given the current discussion here about AVR and Arduino, the 
> technical details are probably of some interest.
>
> Timer 0 is set up as fast PWM on the undivided 8MHz clock, with PWM output 
> to the OC0B pin (PORTD.5 in this case). The register settings are TCCR0A = 
> 0x23, TCCR0B = 0x09. I have the output compare register A (OCR0A) set at 
> 250 – this is the top limit of the counter and sets the PWM rate about 
> 40kHz. You can make it lower for higher frequency operation. Output compare 
> register B (OCR0B) sets the pulse width and is initially set low, around 
> 40. The OC0B pin goes high when the counter resets to 0 from 250, and goes 
> low again when the count matches OCR0B. The FET gate is connected to this 
> OC0B pin and turns on when the output is high. This counter is completely 
> free running and never stops, but the OC0B pin only drives the FET when its 
> port pin is set as an output, so the converter can be suspended without 
> disturbing the PWM by changing the port to an input. The port is 
> initialized as an input to avoid accidents, and is only set as an output by 
> the regulating routine once this is on the job.
>
> Regulation is performed with ADC channel 0. This is set to interrupt on 
> completion. The register settings are ADMUX = 0xE0, ADCSRA = 0xDE, ADCSRB = 
> 0. The high voltage is divided down with a couple of resistors – 200k to 
> the high voltage, 1k to ground, with the ADC input connected to the 
> junction. The ADC then reads 1/200 of the high voltage, comparable with the 
> ADC internal reference of 1.25V. The interrupt routine compares the read 
> value to a constant setpoint value, determined by experiment (200 for 175V 
> in my circuit). If the voltage is lower it increments the value of OCR0B, 
> and if higher, decrements it. If OCR0B is ever decremented to zero it sets 
> the OC0B port pin as an input to suspend the PWM, otherwise it sets it as 
> output. Finally it triggers a new conversion. Everything then happens 
> automatically, with no program intervention. Timer 0 OCR0B ramps up until 
> the set point is reached and thereafter hunts around that point as the load 
> changes, giving essentially constant voltage output. 
>
> For switching, I use an IRL640 MOSFET. This is a logic level FET with a 
> 200V rating, about the highest voltage rating you can get in logic level 
> devices. Its gate is connected directly to the AVR OC0B pin, with a 2.2k 
> resistor to ground to make sure it stays turned off when the pin is set as 
> input. The inductor is a Coilcraft MSD-1278-224 – this is a 220uH SEPIC 
> choke with dual coils. In my application the coils are connected in series. 
> The FET drain is connected to one end of the pair, the other end to the 
> rectifier, and 12VDC comes in at the junction. With this arrangement the 
> FET only sees half the peak voltage, so it has a good overload margin.
>
>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neonixie-l+unsubscr...@googlegroups.com.
To post to this group, send an email to neonixie-l@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/neonixie-l/9b90a928-68b6-4b0d-b4e7-541059792e89%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to