Power Control PWM, HELP needed


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    but shouldn't it be "Fosc/4" if I'm using (1:1) prescale ? (1MHz/4 in our case ) which gives PWM frequency 1655Hz ?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Hi,
    Note that I said - If the timer is driven with a frequency of 1MHz - which it would be if you run the PIC at 4MHz and select Fosc/4 as the PWM Timebase input.
    Apart from that you are correct. If you'd run the PIC at 1MHz and set the PWM timebase to derive it's clock from Fosc/4 then the timebase will run at 250kHz and you'd get a PWM frequency of 1655.5Hz with the values in the previous example.

    /Henrik.

  3. #3
    Join Date
    Jun 2013
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    My bad
    Once again Thanks Henrik

  4. #4
    Join Date
    Jun 2013
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Last two questions (I hope so )
    in Bruce's Example he's multiplying pdcx by (Lowbyte,Highbyte) Low and high byte of what and what is the purpose of doing that ?
    also
    anyway I'm going to post the Code since I can't find the problem yet .. what I'm Trying to do is to generate a sinewave from pwm0 with an offset to use that later in a three phase inverter.. so I made this test which gives unexpected results
    what I'm trying to do is using entries from a lookup table to generate pulses with duty cycles starting from 1000 to 2000 then back to 1000 (Positive half Cycle) after that going from 1000 to 0 and going back again to 1000 (Negative half Cycle) which isn't happening ..
    I'm using 10MHz osc 18f4431, and a lookup table of 25 Entries (Which isn't enough for a smooth wave but this is for testing)

    Code:
    PORTB = 0
    TRISB = %11000000 ' pwm0-5 output
    PTCON0 = %00000000 '   (1:1) prescale , Free-Running mode 
    PTCON1 = %10000000 'time base is on, Counting is up
    PWMCON0 = %01000000 'Pwm0-5 enbbled for pwm output, pwm0-5 complementary mode
    PWMCON1 = %00000001 
    OVDCOND = %11111111  
    PTPERL = $D0
    PTPERH = $07     'PTPER = 2000
    Main:
    PDC0L = 00 
    PDC0H = 10
    
    PDC0L = 59
    PDC0H = 12
    
    PDC0L = 00
    PDC0H = 15
    
    PDC0L = 07
    PDC0H = 17
    
    PDC0L = 66
    PDC0H = 18
    
    PDC0L = 66
    PDC0H = 19
    
    PDC0L = 00
    PDC0H = 20
    
    PDC0L = 66
    PDC0H = 19
    
    PDC0L = 66
    PDC0H = 18
    
    PDC0L = 07
    PDC0H = 17
    
    PDC0L = 00
    PDC0H = 15
    
    PDC0L = 59
    PDC0H = 12
    
    PDC0L = 00
    PDC0H = 10
    
    PDC0L = 41
    PDC0H = 07
    
    PDC0L = 00
    PDC0H = 05
    
    PDC0L = 93
    PDC0H = 02
    
    PDC0L = 34
    PDC0H = 01
    
    PDC0L = 34
    PDC0H = 00
    
    PDC0L = 00
    PDC0H = 00
    
    PDC0L = 34
    PDC0H = 00
    
    PDC0L = 34
    PDC0H = 01
    
    PDC0L = 93
    PDC0H = 02
    
    PDC0L = 00
    PDC0H = 05
    
    PDC0L = 41
    PDC0H = 07
    
    PDC0L = 00
    PDC0H = 10 
    
     GoTo Main
    Thanks
    Last edited by Kloney; - 4th July 2013 at 08:19.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Hi,
    You are currently updating the dutycycle register at a very fast rate, much much faster than the PWM frequency. Try insterting a short delay ( PAUSE 5 or whatever) between each duty cycle update. If that doesn't help try explaining what it does and what the problem is.

    I'll have to look at Bruce's example to see if I can answer the other (first) question.

    /Henrik.

    EDIT: OK, looked at Bruce's example but I don't see where he's multiplying the pdcx with anything....could you clarify?
    Last edited by HenrikOlsson; - 4th July 2013 at 11:12.

  6. #6
    Join Date
    Jun 2013
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    I added a "1 us" delay and it worked quite well but the wave took longer duration time, the output frequency is 16.6hz instead of 50hz becaus of the delay
    I'm using 25 entry and the output should be 50hz (Fpwm = 50 * 25 = 1250 I guess ?) how can I fix that ?
    Also for the DTCON I can't get this part I need a 5us dead-time and I'm using (Fosc/4) settings what are the calculations needed for "5-0" bits in DTCON to set such a dead-time ?

    For Bruce's Example this is the part I'm talking about :

    Duty = 800 ' ~50% PDC2L = Duty.LowByte ' maintain a fixed 50% duty cycle on PWM4,5 PDC2H = Duty.HighByte
    But i don't think that I'm going to need that in my case I just was wondering to understand the whole thing what are the LowByte and HighByte ?

    Thanks Henrick , I can't find words to describe how much you helped me

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Hi,
    I suspect you added 1ms delay, not 1us.
    Correct, if the table is 25 entries for a full cycle and you want 50Hz output you need to index the table at 1250Hz. The delay between each update of the dutycycle should then be 1/1250=800us (so use PauseUs 800 and see what happens). Then, of course, the actual updating of the dutycycle registers takes some small amount of time so if it's critical you'll need to tweak the delay.

    The first and last entry in your "lookup table" are one and the same ($1000) - you'll get a "flat spot" in the cycle.

    Ah, OK, now I see what you're asking....Bruce is not multiplying anything.
    He has a WORD-sized (two bytes) variable, called Duty. He's then assigning the high byte of Duty to PDC0H ( PDC0H=Duty.HighByte ) and the low byte of Duty to PDC0L ( PDC0L = Duty.LowByte ).

    I'll have to read the datasheet for the deadtime thing and I don't have time for that at the moment, I'll try to get back to it later.

    /Henrik.

Similar Threads

  1. Power advice needed
    By bearpawz in forum Schematics
    Replies: 4
    Last Post: - 29th October 2010, 21:17
  2. CCP vs power control PWM
    By luminas in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th September 2008, 03:09
  3. Help needed - MOSFET driven by PWM
    By bcd in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd April 2008, 05:02
  4. Servo control / UART / SPI help needed
    By Blackhawk in forum mel PIC BASIC
    Replies: 10
    Last Post: - 10th November 2006, 03:40
  5. Replies: 5
    Last Post: - 23rd February 2005, 17:35

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