Generating 3-phase sine wave..


Closed Thread
Results 1 to 39 of 39

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    "Ah ha..."

    Funny.. I'm trying to imagine the Eureka's face you had done...

    Well, I kind of did not get it. You are saying that the program is wasting time at this statement?
    Code:
     va = (v*(100-sag[0]))/100
    Why would it be happening? 125us just to make 1 subtract, 1 mult and 1 div?

    Thanks Darrel!
    Last edited by sirvo; - 9th August 2008 at 01:40.
    Sylvio,

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Yup, multiplication and division takes a LOT of loops to do.

    In this thread I had measured a single 16/16 divide at over 76us (382 instructions).

    Keep in mind that in PBP, ALL mutiplications and divisions are done as a 16-bit operation. So even though the variables are BYTE's, it takes the same time as if they were WORD's.

    I haven't timed a 16*16 multiply yet, but from these results I'd say it's probably just under 50us.

    Time to find a new way to do the math.
    <br>
    DT

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Keep in mind that in PBP, ALL mutiplications and divisions are done as a 16-bit operation. So even though the variables are BYTE's, it takes the same time as if they were WORD's.
    And if I remember right, ALL mult's and div's done with PBPL in 2.50B are done as signed-31-bit operations. So, now it's even 'worse'!
    Sounds like it might be time for a small assembly routine for 8 and 16 bit math when speed counts...something like: @ mult16, @ mult8, @ div16, @ div8
    I've been meaning to do it...sometime...when I get time...to save time...

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Sounds like it might be time for a small assembly routine for 8 and 16 bit math when speed counts...something like: @ mult16, @ mult8, @ div16, @ div8
    I've been meaning to do it...sometime...when I get time...to save time...
    That would be really handy. And if you do, here's a good place to start ...

    PIC Microcontoller Basic Math Methods
    http://www.piclist.com/techref/microchip/math/basic.htm
    <br>
    DT

  5. #5
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Time to find a new way to do the math.
    <br>
    OR, increase timer1 interrupt and decrease the number of the sine table points..

    However, I think that 71 points is on the edge for generating a good signal in this aplication. Reducing this number would not let the application to create good harmonics distortion due to the big step between these number...Well, all of this would be answered trying, right?

    I'll get an osc. next thursday... until there I've got to wait...

    Thanks again!
    Sylvio,

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    sirvo> OR, increase timer1 interrupt and decrease the number of the sine table points..

    Actually, I was thinking you should have a larger table at a faster rate.

    But it'll take a few changes.
    Here's a couple things that will help speed things up.

    First, change the interrupt TYPE for TMR1_INT to ASM.
    The handler only set's the flag and loads the timer, so it doesn't need to save all the PBP system registers. This should save about 40us.<hr>
    Then if the SAG() values ranged from 0-255 instead of 0-100, this could replace what you had ...
    Code:
            va = v */ (255-sag[0]+1)
    It will save 75us each time, which brings the whole loop down to 220us. Just barely under the Timer1_INT period. But if you want to add more features, or increase the sin table, there won't be any time left.
    <hr>
    Going a bit further, here's a little asm routine that'll really help.

    It Scales an 8-bit value to another 8-bit value.
    Essentially it does Result=Value*(Scale+1), with the actual result being in the HighByte of the R2 variable.

    With this you can do ...
    Code:
    ;        va = (v*(100-sag[0]))/100
            R0 = V              ; Put the value in R0
            R1 = 255-SAG[0]     ; Inverted SAG to R1
            CALL Scale8         ; Scale R0*(R1+1)
            VA = R2.HighByte    ; result is in R2.HighByte
    Here's the ASM part. Put it somewhere above the Main loop.
    Code:
    ASM ; ---- [Scale8 - Scale an 8-bit value]----------
    ;  Input:   R0 = Value to scale                    |
    ;           R1 = Scale (0-255)                     |
    ;  Output:  R2 = R0*(R1+1)                         |
    ;           Result is in  R2.HighByte              |
    ;---------------------------------------------------
        goto OverScale8
    _Scale8
        clrf     R2          ; result LowWord
        clrf     R2 + 1      ; result HighWord
        movlw    8
        movwf    R3          ; Loop counter
    
        movf     R1, W       ; Load Scale in W reg
        bcf      STATUS, C   ; clear carry
    
    Scale8Loop
        rrf      R0, F       ; Rotate the Value, lsb goes to carry
        btfsc    STATUS, C   ; if the carry = 1 then
        addwf    R2 + 1, F   ;   add Scale to result.highbyte
        rrf      R2 + 1, F   ; rotate the result.highbyte, lsb goes to carry
        rrf      R2, F       ; rotate carry into result.lowbyte
        decfsz   R3, F       ; next loop
        goto     Scale8Loop
    
        addwf    R2, F       ; add 1 more Scale
        btfsc    STATUS, C   ; if carry
        incf     R2 + 1, F   ; inc highbyte
    
        return
    
    ;----[Macro to make things easier]------------------
    Scale8  macro Value, Scale, Bout
        MOVE?BB  Value, R0
        MOVE?BB  Scale, R1
        L?CALL   _Scale8
        MOVE?BB  R2 + 1, Bout
      endm
    
    OverScale8
    ENDASM ; ---- [End of Scale8]-----------------------
    Using the above code, each call to Scale8 takes about 18us or 54us for all three. With 70us for the rest, it ends up doing the whole thing in about 125us. Well within the 230us periods. And time left over for a bigger/faster table.

    I'm not using the macro at this point. It's just there for future reference.

    Just remember ... SAG is 0-255 now. So if you need to convert it...
    Code:
    SAG(0) = SAG0value*255/100
    Which is much like what you had in the beginning. But now it's only done when setting the SAG values, instead of 12000 times a second.

    HTH,
    DT

  7. #7
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Question

    I'll try all of this as soon as possible...

    Hey, Does 16LF777 work with @20Mhz? (LF)

    In the datasheet DS30498C.pdf page 208, I see a graph showing that this Industrial model does not achieve the 20MHz frequency... Am I crazy?
    Sylvio,

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    I'll try all of this as soon as possible...

    Hey, Does 16LF777 work with @20Mhz? (LF)

    In the datasheet DS30498C.pdf page 208, I see a graph showing that this Industrial model does not achieve the 20MHz frequency... Am I crazy?
    That's what it looks like to me. No updates on Microchip's site for the datasheet or the part itself. I'd be inclined to think that it would run at 20Mhz though. That graph and some parameters a few pages later in the datasheet seem to conflict a bit.

  9. #9
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Smile

    Hello..

    This is just a feedback of the tri-phase generator.
    The video is not so good but you can get it...

    It uses serial comm to make choices of the sinal generated.



    I really appreciate the support!

    Thanks!
    Last edited by ScaleRobotics; - 15th February 2011 at 09:39. Reason: embeded video
    Sylvio,

Similar Threads

  1. To Generate Sine Wave Using PCPWM of PIC18F4331 (Issue)
    By Cyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 22nd March 2014, 13:39
  2. Sine wave
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th May 2009, 03:31
  3. 3 phase supply detector challenge
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th May 2009, 07:54
  4. 3 phase PWM with dsPIC30F2020
    By nemmard in forum mel PIC BASIC
    Replies: 1
    Last Post: - 21st January 2009, 14:19
  5. 3 phase sequencing
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2007, 07: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