Flyback/forward power supply using comparator and hpwm/timer, possible?
+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2013
    Posts
    471

    Default Flyback/forward power supply using comparator and hpwm/timer, possible?

    Hello.

    I have a following idea. Say we have hpwm configured to deliver 30khz. It drives external mosfet which operates flyback transformer to deliver 170V 10mA at output. Rectified output is fed to comparator, which, according to output voltage, enables-disables hpwm. All this done via config, no CPU cycles stolen from main code. Will it work? I don't need spot-on voltage stability, +-5% variation is absolutely ok.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    I have to ask, What is the 170 Volts being used for? Possibly Nixie tubes?
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Sep 2009
    Posts
    733

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    I've done step up on PIC18LF14K50, without using CPU. And done regulated SEPIC battery charger.
    But DO NOT USE HPWM!
    When you use HPWM it stops timer, so it cause pin to hold current state. And if stays on too long, then magic smoke appear.

    Use register configuration, set duty cycle to desired maximum current. and use comparator to turn off pwm, and have auto start enabled.
    For low power supply you can use mosfet directly driven.
    Here is register config for PIC18LF14K50(5V usb to 40V):
    Code:
        TRISA = $00
    	TRISB = $30  '%00110000
    	TRISC = $07  '%00000111
    	LATC = 0
    
    	ANSEL=%00100000
        ANSELH=%00000100
    
    	REFCON0=%10010000
    	REFCON1=%10001000
    	REFCON2=$14 '1420
    
    	CM1CON0=0 'cmp1 off
    	CM2CON0=%10011110
    	CM2CON1=%00011000
    
    	PWM1CON=%10000000
    	ECCP1AS=%00100000
    
        CCPR1Con CON 60
    	CCPR1L = CCPR1Con
    	CCP1CON = %00011100  ' Set CCP1 to PWM
    	T2CON = %00000100    ' Turn on Timer2, Prescale=1
    	PR2 = 140            ' Set PR2 to get 48KHz out
    
        T1CON=%00110001     'System Ticks
    
        ADCON1=%00001000 'FVR
        ADCON2=%10111111 'Right, 20Tad, RC
        PAUSE 100
        ADCON0=%00010101
    Name:  stepup.png
Views: 36
Size:  23.4 KB
    Last edited by pedja089; - 31st March 2019 at 02:18.

  4. #4
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    282

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    I'm using NCO and a comparator to do pretty much the same thing. I just turn them on and ignore. Works completely through hardware in the background.
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  5. #5
    Join Date
    Feb 2013
    Posts
    471

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    Yes, this will be used as nixie power supply.

    HPWM will stop timer, if same part is used, but many PICs have separate HPWM and timer channels, so it should not be an issue?

    I'm planning to use PIC16F886.

    idea with NCO and comparator is great, can we have look at code?

  6. #6
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    282

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    This is on a PIC16F18426, which PBP3 doesn't yet service -- so I used MPLABX and ASM. However, here is the important stuff translated to PBP:
    Code:
    ; --- NCO SFRs: Generates Pulse to Inductor for HV ---
    NCO1CON = $81 ; Pulse Mode, bit-7 = 1/0 (on/off)
    NCO1CLK = $21 ; 2 CLK cycles of HFINTOSC
    NCO1INCU = 1
    NCO1INCH = $E4
    NCO1INCL = 0
    ; --- DAC SFRs: Used as a Positive Reference for Comparator ---
    DACCON0 = $84
    DACCON1 = $11
    ; --- Comparator SFRs: Compare HV to DAC ---
    CM1CON0 = $82
    CM1NCH = $03
    CM1PCH = $05
    ; Configurable Logic Cell SFRs: Modulates NCO & Comparator Outputs ---
    CLC1CON = $82
    CLC1POL = 0
    CLC1SEL0 = $14 ; NCO1_OUT
    CLC1SEL1 = $1B ; C1_OUT
    CLC1GLS0 = 2
    CLC1GLS1 = 8
    CLC1GLS2 = 8
    CLC1GLS3 = 8
    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.

  7. #7
    Join Date
    Feb 2013
    Posts
    471

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    Interesting, is it possible to integrate Microchips CLC graphical configurator output into picbasic pro?

  8. #8
    Join Date
    Sep 2009
    Posts
    733

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    Quote Originally Posted by CuriousOne View Post
    HPWM will stop timer, if same part is used, but many PICs have separate HPWM and timer channels, so it should not be an issue?
    As far as I know it will. Because it will set new frequency(even if it same as previous )

  9. #9
    Join Date
    Sep 2009
    Posts
    733

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    Quote Originally Posted by CuriousOne View Post
    Interesting, is it possible to integrate Microchips CLC graphical configurator output into picbasic pro?
    If it can output ASM, you can use it directly. Just copy/paste.

  10. #10
    Join Date
    Sep 2009
    Posts
    733

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    I give a try mcc. It outputs only C, even if I selected MPASM when creating project.
    Here is generated config for ADC
    Code:
    void ADC_Initialize(void)
    {
        // set the ADC to the options selected in the User Interface
        
        // GO_nDONE stop; ADON enabled; CHS AN0; 
        ADCON0 = 0x01;
        
        // PVCFG VDD; TRIGSEL CCP5; NVCFG VSS; 
        ADCON1 = 0x00;
        
        // ADFM left; ADCS FOSC/2; ACQT 0; 
        ADCON2 = 0x00;
        
        // ADRESL 0x0; 
        ADRESL = 0x00;
        
        // ADRESH 0x0; 
        ADRESH = 0x00;
        
    }
    To use that code in PBP, just remove ; and replace 0x with $. In notepad it can be done in few second.
    But it generates include file for each peripheral that you use.
    If there is enough interest, I could put simple C to PBP translator. To gather all configuration into single place, and remove ; and replace 0x with $.
    But I must omit routines like this
    Code:
    uint16_t FLASH_ReadWord(uint32_t flashAddr)
    {
        return ((((uint16_t)FLASH_ReadByte(flashAddr+1))<<8)|(FLASH_ReadByte(flashAddr)));
    }

  11. #11
    Join Date
    Feb 2013
    Posts
    471

    Default Re: Flyback/forward power supply using comparator and hpwm/timer, possible?

    Thanks, will give try it later, now I'm fighting with writing and reading DS1302 RAM...…..

Similar Threads

  1. power supply help ?
    By iugmoh in forum Schematics
    Replies: 10
    Last Post: - 27th February 2009, 20:01
  2. Digital Power Supply
    By tump in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 3rd December 2007, 13:11
  3. Alternative power supply
    By The Master in forum Off Topic
    Replies: 2
    Last Post: - 20th November 2007, 13:38
  4. Backup Power Supply
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2007, 19:37
  5. OT - power supply problem
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd March 2006, 00:14

Members who have read this thread : 13

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts