1 Continuous MCPWM at a time


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    Join Date
    Jul 2011
    Posts
    29

    Default 1 Continuous MCPWM at a time

    Hello guys,

    I am currently trying to use the MCPWM on my pic18F4331 (20 MHZ external oscillator)
    I am trying to control a brushless dc motor with 12 IGBT's so I need 12 outputs. Amongst these 6 outputs, I want to use the PMW0 to PMW5 one at a time. Because I get inputs from my encoder, telling me when to switch which PWM.

    I have been searching the forum, and it helped me a lot, I have used the code described here : http://www.picbasic.co.uk/forum/show...3820#post43820
    I'm looking over the datasheet, i'm still pretty new at this but, i can't figure out how to use one pwm at a time. (I only need one duty cycle for all of them)

    Thank you very much in advance for your answers..

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Barney,

    Have a look at this thread. One of the guys discovered that the "ovdcond" register can be used to switch
    the pwms on and off.

    http://www.picbasic.co.uk/forum/show...hlight=ovdcond

  3. #3
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Hello mark_s,

    Thank you for your quick reply, it is exactly what I was looking for.

    I Know need to adjust my pwm duty cycle with a potentiometer 1K on AN0.
    Is 1K enough ?

    Can someone help me to understand the process with that A/D module ?
    I'm not sure i'm understanding quite well the process.

  4. #4
    Join Date
    Jul 2011
    Posts
    29


    Did you find this post helpful? Yes | No

    Question

    Hello, it's me again.
    I went through the registers in the datasheet and used the example of Bruce here : http://www.picbasic.co.uk/forum/showthread.php?t=6768
    I tried to understand and apply it to my case, but it's not doing anything my duty cycle ?

    Thank you in advance for your help, it'd be really appreciated

    Code:
    Duty VAR Word
    
    TRISA  = %11111111
    TRISB  = %00000000
    TRISC  = %00000010
    TRISD  = %00000000
    TRISE  = %00000000 
    
     ' Analog setup
        ' Single shot, single channel, Group A is taken and converted, A/D converter enabled 
        ADCON0 = %00000001
        
        ' 
        ADCON1 = %00010000
        
        ADCON2 = %11001111   ' Right justified, 24 Tad, Frc
        ADCON3 = 0           ' Disable all triggers
        ADCHS = 0            ' Channel select for AN0
        ANSEL0 = %00000001   ' AN0 analog input, rest digital
        
        
    
    PORTB = 0
    PORTD = 0 ' clear port
    
    
    PTCON0=$00 'timebase
    PTPERL=$A0 ' $01A0 = 12kHz
    PTPERH=$01
    
    PWMCON0 = %01001111
    PWMCON1=%00000001
    DTCON=$00
    OVDCOND = %00000000
    OVDCONS = %00000000 'PORT PINS
    
    PDC0L=$00
    PDC0H=$00
    PDC1L=$00
    PDC1H=$00
    PDC2L=$00
    PDC2H=$00
    
    PDC0L = Duty.LowByte
    PDC0H = Duty.HighByte
    
    PDC1L = Duty.LowByte
    PDC1H = Duty.HighByte
    
    PDC2L = Duty.LowByte
    PDC2H = Duty.HighByte
    
    
    PTCON1=%10000000
    
    
     
    GoTo Main
    
    Main:
        ADCON0.1 = 1         ' Start the conversion
        While ADCON0.1=1     ' Wait for it to complete
        Wend
    
        Duty.HighByte = ADRESH ' get result from AN0
        Duty.LowByte = ADRESL  ' Increment buffer pointer
    
        OVDCOND = %00000010 'PWM on PWM1

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    Is this all of your code? If it is, can you explain what you "think" should be happening, and how you know it's not?

    Folks here love to help, but what you're showing here doesn't indicate even a modest amount of homework..;o)
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 1 Continuous MCPWM at a time

    If it is the entire code, maybe looping back to main would help? Otherwise I agree with Bruce.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 1

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