Power Control PWM, HELP needed


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Hi,
    Without seeing your actual code it's hard to tell what you're doing and if it's "the right way" or not. If it works then I guess it's OK.
    But anyway, here are couple of random thoughts....
    You don't need an array (in RAM) since the values are constants, use a lookup table (which stores the values in program memory instead of RAM). If the values you're looking up are WORDs you need to use LOOKUP2.
    Code:
    i VAR BYTE
    DUTY VAR WORD
    MAIN:
      For i = 0 to 8
        LOOKUP2 [100,123,234,345,456,789,890,1234,2345], Duty
        PDC0L = DUTY.LOWBYTE
        PDC0H = DUTY.HIGHBYTE
        PAUSEUS 800
      NEXT
    GOTO Main
    As for the delay, again hard to tell what you're doing and I'm not sure I understand what the actual problem is. If you want higher output frequency (ie the sine output, not the actual PWM frequency) then reduce the delay between each update of the dutycycle. If the math doesn't add up, make SURE the PIC is running at the frequency you think it is.

    /Henrik.

  2. #2
    Join Date
    Jun 2013
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Re: Power Control PWM, HELP needed

    Hi,
    seems I should use Interrupt somehow which I don't have any idea about using it in such a thing..
    anyway here's the code
    Code:
    DEFINE OSC 40
     portb = 0
     latb = 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,Complementary
    PWMCON1 = %00000001 
    OVDCOND = %11111111
    DTCON = %01110010 '5us dead-time
    PTPERL = $E7
    PTPERH = $03
    i var byte
    x var byte
    z var byte
    i=0
    x=33
    z=66
    duty var byte[101]
    duty2 var byte[101]
    duty[0]=05
    duty2[0]=00 
    duty[1]=05
    duty2[1]=31 
    duty[2]=05
    duty2[2]=63
    duty[3]=05
    duty2[3]=94
    duty[4]= 06
    duty2[4]=24 
    duty[5]=06
    duty2[5]=55 
    duty[6]=6
    duty2[6]=84 
    duty[7]=7
    duty2[7]=13
    duty[8]=7
    duty2[8]=41
    duty[9]=7
    duty2[9]=68
    duty[10]=7
    duty2[10]=94
    duty[11]=8
    duty2[11]=91 
    duty[12]=8
    duty2[12]=42 
    duty[13]=8
    duty2[13]=64
    duty[14]=8
    duty2[14]=85
    duty[15]=09
    duty2[15]=05
    duty[16]=9
    duty2[16]=22
    duty[17]=9
    duty2[17]=38
    duty[18]=9
    duty2[18]=52 
    duty[19]=9
    duty2[19]=65 
    duty[20]=9
    duty2[20]=76 
    duty[21]=9
    duty2[21]=84 
    duty[22]=9
    duty2[22]=91 
    duty[23]=9
    duty2[23]=96 
    duty[24]=9
    duty2[24]=99 
    duty[25]=10
    duty2[25]=00 
    duty[26]=9
    duty2[26]=99 
    duty[27]=9
    duty2[27]=96 
    duty[28]=9
    duty2[28]=91 
    duty[29]=9
    duty2[29]=84 
    duty[30]=9
    duty2[30]=76 
    duty[31]=9
    duty2[31]=65 
    duty[32]=9
    duty2[32]=52 
    duty[33]=9
    duty2[33]=38 
    duty[34]=9
    duty2[34]=22 
    duty[35]=9
    duty2[35]=05 
    duty[36]=8
    duty2[36]=85 
    duty[37]=8
    duty2[37]=64 
    duty[38]=8
    duty2[38]=42 
    duty[39]=8
    duty2[39]=91 
    duty[40]=7
    duty2[40]=94 
    duty[41]=7
    duty2[41]=68 
    duty[42]=7
    duty2[42]=41 
    duty[43]=7
    duty2[43]=31 
    duty[44]=6
    duty2[44]=84 
    duty[45]=6
    duty2[45]=55 
    duty[46]=6
    duty2[46]=42 
    duty[47]=5
    duty2[47]=49 
    duty[48]=5
    duty2[48]=63 
    duty[49]=5
    duty2[49]=31 
    duty[50]=05
    duty2[50]=00 
    duty[51]=4
    duty2[51]=69 
    duty[52]=4
    duty2[52]=37  
    duty[53]=4
    duty2[53]=06 
    duty[54]=3
    duty2[54]=76 
    duty[55]=3
    duty2[55]=45 
    duty[56]=3
    duty2[56]=16 
    duty[57]=2
    duty2[57]=87 
    duty[58]=2
    duty2[58]=59 
    duty[59]=2
    duty2[59]=32 
    duty[60]=2
    duty2[60]=06 
    duty[61]=1
    duty2[61]=81 
    duty[62]=1
    duty2[62]=58
    duty[63]=1
    duty2[63]=36 
    duty[64]=1
    duty2[64]=15 
    duty[65]=0
    duty2[65]=59 
    duty[66]=0
    duty2[66]=78 
    duty[67]=0
    duty2[67]=62 
    duty[68]=0
    duty2[68]=48 
    duty[69]=0
    duty2[69]=35 
    duty[70]=0
    duty2[70]=24 
    duty[71]=0
    duty2[71]=16 
    duty[72]=0
    duty2[72]=09 
    duty[73]=0
    duty2[73]=04 
    duty[74]=0
    duty2[74]=01 
    duty[75]=0
    duty2[75]=0 
    duty[76]=00
    duty2[76]=01 
    duty[77]=0
    duty2[77]=04 
    duty[78]=0
    duty2[78]=09 
    duty[79]=0
    duty2[79]=16 
    duty[80]=0
    duty2[80]=24 
    duty[81]=0
    duty2[81]=35 
    duty[82]=0
    duty2[82]=48 
    duty[83]=0
    duty2[83]=62  
    duty[84]=0
    duty2[84]=78 
    duty[85]=0
    duty2[85]=95 
    duty[86]=01
    duty2[86]=15 
    duty[87]=01
    duty2[87]=36
    duty[88]=01
    duty2[88]=58 
    duty[89]=01
    duty2[89]=81 
    duty[90]=02
    duty2[90]=06 
    duty[91]=02
    duty2[91]=32 
    duty[92]=02
    duty2[92]=59 
    duty[93]=02
    duty2[93]=87 
    duty[94]=03
    duty2[94]=16 
    duty[95]=03
    duty2[95]=45 
    duty[96]=03
    duty2[96]=76 
    duty[97]=04
    duty2[97]=06 
    duty[98]=04
    duty2[98]=37 
    duty[99]=04
    duty2[99]=96 
    
    Main:
    
    pdc0l=duty2[i]
    pdc0h=duty[i]
    
    pdc1l=duty2[x]
    pdc1l=duty[x]
    
    pdc2l=duty2[z]
    pdc2h=duty[z]
    pauseus 100
    i=i+1
    x=x+1
    z=z+1
    if (x>99) THEN X=0 
    IF (I>99) THEN I=0 
    IF (Z>99) THEN Z=0
    goto main
    I'm trying to generate 3 sinwaves with a 120 shift each to use it in a 3-phase inverter ,the output sinewave frequency should be 50Hz.
    I think I can use the Lookup2 function to declare the array entries like this :
    Code:
    G VAR BYTE 
    Arrayd VAR WORD   
     For G = 0 to 99     
    LOOKUP2 [500, 531, 563, 594, 624, 655, 684, 713, 741, 768, 794, 819, 842, 864, 885, 905, 922, 938, 952, 965, 976, 984, 991, 996, 999, 1000, 999, 996, 991, 984, 976, 965, 952, 938, 922, 905, 885, 864, 842, 819, 794, 768, 741, 713, 684, 655, 624, 594, 563, 531, 500, 469, 437, 406, 376, 345, 316, 287, 259, 232, 206, 181, 158, 136, 115, 95, 78, 62, 48, 35, 24, 16, 9, 4, 1, 0, 1, 4, 9, 16, 24, 35, 48, 62, 78, 95, 115, 136, 158, 181, 206, 232, 259, 287, 316, 345, 376, 406, 437, 469], Arrayd     
    duty[G] = Arrayd.LOWBYTE     
    duty2[G] = Arrayd.HIGHBYTE   
    NEXT
    not sure if that is going to work

    but I think this is not the problem here
    Last edited by Kloney; - 5th July 2013 at 14:25.

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 : 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