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

    Last project I used the CLEAR statement, but not in this one.. Would it be necessary since I've set all the variables at the top of the program?
    Sylvio,

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    Last project I used the CLEAR statement, but not in this one.. Would it be necessary since I've set all the variables at the top of the program?
    Maybe ... I'm not really sure.
    The last problem with DT_INTS-18 was because of that.

    DT_INTS-14 is at .93 now because I've never really been confident enough to call it "DONE". And I don't give it as much attention as the 18F version. My Avatar could be a clue.

    Give it a try, couldn't hurt.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    One week later, I'm back.. but no luck yet..

    I've tried to add the CLEAR statement but nothing happened... it still remains like it was...

    Is there another tip??????

    Thanks!
    Sylvio,

  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 sirvo View Post
    Is there another tip??????
    You could post the rest of the program.

    Like I said <a href=#post59895>before</a>, I've run what you posted here (on a diff chip) and everything was fine.

    There may be something in the portion of the program that wasn't included.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Ok...

    Code:
    
    INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
    
    '@ DEVICE pic16F777, HS_OSC ; System Clock Options
    '@ DEVICE pic16F777, WDT_OFF ; Watchdog Timer
    '@ DEVICE pic16F777, PWRT_ON ; Power-On Timer
    '@ DEVICE pic16F777, MCLR_OFF ; Brown-Out Detect
    '@ DEVICE pic16F777, PROTECT_OFF
    @  __CONFIG    _CONFIG1, _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
    
    
    define  OSC 20
    
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 10  ' 115200 Baud @ 20MHz, -1,36%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    clear
    MODO    VAR BYTE[3]
    DIST    VAR BYTE
    SAG     VAR BYTE[3]
    SAG[0] = 0
    SAG[1] = 0
    SAG[2] = 0
    SWELL   VAR BYTE
    SWELL = 0
    
    CTRL    VAR BYTE
    LOAD    VAR WORD
    RA      VAR BYTE
    RB      VAR BYTE
    RC      VAR BYTE
    RD      VAR BYTE
    RA = 0
    RB = 1
    RC = 0
    RD = 0
    V       VAR BYTE
    VA      VAR BYTE
    VB      VAR BYTE
    VC      VAR BYTE
    CONTA    VAR BYTE
    CONTB    VAR BYTE
    CONTC    VAR BYTE
    CONT    VAR BYTE
    INDEX   VAR BYTE
    FLAG    VAR BYTE
    X       VAR BYTE
    
    FLAG = 0
    CONTA = 0
    CONTB = 23
    CONTC = 47
    modo[0] = 1
    modo[1] = 1
    modo[2] = 1
    ' Set CCPx pins to outputs
    TRISC.2 = 0 ' CCP1 output
    TRISC.1 = 0 ' CCP2 output (could also be assigned to RB3)
    TRISB.5 = 0 ' CCP3 output
    TRISC.7 = 1
    TRISC.6 = 0
    TRISD.0 = 0
    ' Set CCP modules to PWM mode
    CCP1CON = %00001100 ' Mode select = PWM
    CCP2CON = %00001100 ' Mode select = PWM
    CCP3CON = %00001100 ' Mode select = PWM
    
    INTCON = %11000000
    LOAD = 65250' 4320Hz
    'LOAD = 0
    TMR1H = LOAD.HIGHBYTE
    TMR1L = LOAD.LOWBYTE
    T1CON = %00000001
    PIE1.0 = 1
    PR2 = 200
    'PR2 = 62
    PORTD.0 = 0
    ' Set TMR2 up for 1:1 prescale & turn it on
    T2CON = %00000100 ' TMR2 ON 1:1 prescale
    'T2CON = %00011100 ' TMR2 ON 1:1 prescale
    
    
    ASM
    INT_LIST macro ;IntSource, Label,    Type, ResetFlag?
        INT_Handler TMR1_INT, _Timer1,   PBP, yes 
        INT_Handler RX_INT,   _GetChar,  PBP, yes 
        INT_Handler TX_INT,   _SendChar, PBP, yes 
        endm
        INT_CREATE ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE  TMR1_INT   ; Habilita interrupção do TMR1 
    @    INT_ENABLE  RX_INT     ;- enable the interrupt
    @    INT_ENABLE  TX_INT     ;- enable the interrupt
    
    
    MAIN: 
        IF FLAG = 1 THEN 
            PORTD.0 = 1 
            flag = 0 
            CONTA = CONTA + 1
            CONTB = CONTB + 1
            CONTC = CONTC + 1
            if contA = 71 then contA = 0
            if contB = 71 then contB = 0
            if contC = 71 then contC = 0
                
            index  = conta
            if RA.0 = 1 then 
                DIST = RB
                SAG[0] = RC
                MODO[0] = DIST
            ELSE
                DIST = MODO[0]
            ENDIF
            GOSUB tabela
            va = (v*(100-sag[0]))/100
            
            index  = contB
            if RA.1 = 1 then 
                DIST = RB
                SAG[1] = RC
                MODO[1] = DIST
            ELSE
                DIST = MODO[1]
            ENDIF
            GOSUB tabela
            vb = (v*(100-SAG[1]))/100
            
            index  = contC
            if RA.2 = 1 then 
                DIST = RB
                SAG[2] = RC
                MODO[2] = DIST
            ELSE
                DIST = MODO[2]
            ENDIF
            GOSUB tabela
            vc = (v*(100-SAG[2]))/100
    
            RA = 0
            GOSUB SAIDA
            PORTD.0 = 0 
        endif      
        GOTO MAIN
    
        
    TABELA:
        SELECT CASE DIST
        CASE 1: ' Fundamental
               LOOKUP INDEX, [100,109,118,126,135,143,151,158,165,171,177,183,187,191,195,197,199,200,200,199,198,196,193,189,185,180,175,168,162,154,147,139,130,122,113,104,96,87,78,70,61,53,46,38,32,25,20,15,11,7,4,2,1,0,0,1,3,5,9,13,17,23,29,35,42,49,57,65,74,82,91], V 
        CASE 2: ' 3 com 20%
               LOOKUP INDEX, [100,114,127,140,152,162,170,177,182,185,187,187,187,185,184,182,181,180,180,180,181,182,184,185,187,187,187,185,182,177,170,162,152,140,127,114,100,86,73,60,48,38,30,23,18,15,13,13,13,15,16,18,19,20,20,20,19,18,16,15,13,13,13,15,18,23,30,38,48,60,73,86], v
        CASE 3: ' 3 com 20% + 5 com 10%
               LOOKUP INDEX, [100,118,135,150,161,170,175,178,178,178,177,177,178,180,182,185,188,189,190,189,188,185,182,180,178,177,177,178,178,178,175,170,161,150,135,118,100,82,65,50,39,30,25,22,22,22,23,23,22,20,18,15,12,11,10,11,12,15,18,20,22,23,23,22,22,22,25,30,39,50,65,82], V
        CASE 4: ' 3 com 20% + 5 com 10% + 7 com 10%
               LOOKUP INDEX, [100,124,144,159,168,171,170,168,168,171,175,181,187,190,190,188,184,181,180,181,184,188,190,190,187,181,175,171,168,168,170,171,168,159,144,124,100,76,56,41,32,29,30,32,32,29,25,19,13,10,10,12,16,19,20,19,16,12,10,10,13,19,25,29,32,32,30,29,32,41,56,76], V
        CASE 5: ' 5 com 10% + 7 com 20%
               lookup index, [100,122,139,149,151,147,141,136,137,145,157,172,186,194,197,194,188,183,181,183,188,194,197,194,186,172,157,145,137,136,141,147,151,149,139,122,100,78,61,51,49,53,60,64,63,55,43,28,14,6,3,6,12,17,19,17,12,6,3,6,14,28,43,55,63,64,59,53,49,51,61,78], v
        CASE 6:
               return
        CASE 7:
               return 
        end select
    return
    
    SAIDA:
            CCP1CON.4 = VA.0
            CCP1CON.5 = VA.1
            CCPR1L = VA >> 2
            CCP2CON.4 = VB.0
            CCP2CON.5 = VB.1
            CCPR2L = VB >> 2
            CCP3CON.4 = VC.0
            CCP3CON.5 = VC.1            
            CCPR3L = VC >> 2
    RETURN
      
    Timer1:
        TMR1H = load.highbyte 
        TMR1L = load.lowbyte              
        FLAG = 1 
    @ INT_RETURN  
    
    GetChar:
          HSERIN [dec RA] 
          HSERIN [dec RB]  
          HSERIN [dec RC]  
          HSERIN [dec RD]
    
    @   INT_ENABLE  TX_INT     ;- enable the interrupt
    @   INT_RETURN 
    
    SendChar:
          'hserout [dec cod[0], "-", dec cod[1], "-", dec cod[2], "-", dec cod[3]]
    @   INT_DISABLE  TX_INT    ;- disable the interrupt
    @   INT_RETURN 
    
    END
    Sylvio,

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


    Did you find this post helpful? Yes | No

    Default

    Ah ha, there's the missing info.

    With the lines ...
    Code:
    va = (v*(100-sag[0]))/100
    I'm measuring each one at about 125us. There's 3 of them, so that's 375us, plus the 70us I measured for the main loop last time, for a total of around 450us.

    Timer1 is overflowing every ~230us, so it's definately missing the Flag's.
    <br>
    DT

  7. #7
    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,

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