Mosfet stable Volt out


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    here's something to play with
    Code:
    ' PIC18F2220 
    DEFINE OSC 20
    
    TRISC = 0 ' PORTC as output
    TRISA = 3 ' RA0 & RA1 as input
    
    PR2=$FF ' load frequency period (PWM freq=1.2 KHZ)
    
    ADCON1 = %00001101 ' Set RA0 & RA1 as analog
    ADCON2 = %10000110 ' Right justified result
                       ' Fosc/64
                       ' Tad = 0
                       
    ADCON0.0 = 1       ' enable a/d
    
    TMR2DutyVar     var word
    AdResult        var word
    Voltage         var word
    Source          var word
    SelectedVoltage var word
    Quanta          con 125 ' (5Volt/1024)*256=0.125 = 125
    
    SelectedVoltage = 110 ' mean 1.1 volt
    tmr2dutyvar = 156 ' according duty to get 1.1Volt = (1.1/7.2)*1024
    
    Start:
        gosub InitPWM
        
        ' Read Motor voltage supply line
        ' ------------------------------
        '
        ADCON0 = %00000101 'select channel 1 
        pauseus 100
        ADCON0.1 = 1 'start conversion
        while ADCON0.1 ' wait for end of conversion
        wend   
        Adresult.highbyte = ADRESH
        adresult.lowbyte = ADRESL
        Source = (adresult */ quanta )
        Source = source * 288 ' to have a range of 7.2volt
        Source = div32 100 
    
        ' Read feedback motor voltage
        ' ---------------------------
        '
        ADCON0 = %00000001 ' select channel 0
        pauseus 100
        ADCON0.1 = 1
        while ADCON0.1 ' wait for end of conversion
        wend   
        Adresult.highbyte = ADRESH
        adresult.lowbyte = ADRESL
        voltage = (adresult */ quanta )
        voltage = voltage * 144 ' to have 7.2V range
        voltage = div32 100     
        voltage = source - voltage 
    
        ' Voltage regulation
        ' ------------------
        '
        if voltage < selectedvoltage then 
           if tmr2dutyvar < 1023 then TMR2DutyVar=TMR2DutyVar+1
           gosub initpwm
        endif
    
        if voltage>Selectedvoltage then
           if tmr2dutyvar then TMR2DutyVar=TMR2DutyVar-1
           gosub initpwm
        endif
        goto start
    
    
    InitPWM:
        'set Duty cycle
        CCP1CON.5=Tmr2dutyvar.1
        CCP1CON.4=Tmr2dutyvar.0
        CCPR1L =(tmr2dutyvar>>2)
        
        T2CON=%00000110 ' start timer 2
                        ' set prescaler = 16
    
        CCP1CON = %00001100 ' pwm mode for CCP1
        return
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Lightbulb MosFet out volt

    Hi thanks for the help...

    Hi what type of software do you use for draw the Schematics ...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi jetpr, I use P-CAD. I heard also some good comment on something called EAGLE.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Help needed - MOSFET driven by PWM
    By bcd in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd April 2008, 05:02
  3. Mosfet problems
    By Agent36 in forum General
    Replies: 7
    Last Post: - 2nd February 2008, 22:37
  4. Driving a mosfet directly?
    By passion1 in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 12th July 2007, 07:45
  5. Decent 24 volt Pic power supply
    By rwskinner in forum Schematics
    Replies: 7
    Last Post: - 18th December 2006, 12:27

Members who have read this thread : 0

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