Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

sine table manipulation

Status
Not open for further replies.

avrsanju

Junior Member level 3
Joined
Jul 16, 2010
Messages
29
Helped
7
Reputation
16
Reaction score
10
Trophy points
1,283
Location
india
Activity points
1,623
hai friends,

i have a ups board using dspic 30f2010, i know that this chip have a mpwm and can be used as complimentary.
such 2 pwm, if we starting with a period of (say 100us), and we start module, we can see the wave foam both are starting together...here i want to start the second ch pwm little time later...then only i can get these type of wave foams i think..indipend ch, i measure 8khz, but in the position of TRANSFORMER (center arm of H, ican measure 16 khz,,,how can it possible?through the time shifted sloat both H arms are conducting twice?...pls clarify me...wave foarm i got her in this attachment,(1H and 2L) only.
 

Attachments

  • MAP007.png
    MAP007.png
    9.4 KB · Views: 79

...such 2 pwm, if we starting with a period of (say 100us), and we start module, we can see the wave foam both are starting together...here i want to start the second ch pwm little time later..

Depending on what IC driver for switch device is employed at circuit, you don´t need take care, due such delay feature is already implemented inside.


+++
 

The waveform seems an inverted "step sine wave".
 

He´s referring to "dead time" feature, required to avoid mutual conduction of both transistors.



+++
 

Hai friends,
i made the software and checked with transformer in bridge arm, sine wave is there, but the waves are not rounded edge,,,,if iam reducing the sec/div of scope, it seems to be as triangular wave..here iam attaching the dspic pwm isr,

Code C - [expand]
1
2
const int sin_table[64]=  {  0,   151,  301,  450,  599,  746,  891, 1034, 1175, 1313, 1447, 1578, 1706, 1829, 1948, 2062, 2171, 2275, 2373, 2466, 2553, 2633, 2707, 2775, 2836, 2891, 2938, 2978, 3011, 3037, 3055, 3066, 3070, 3066, 3055, 3037, 3011, 2978, 2938, 2891, 2836, 2775, 2707, 2633, 2553, 2466, 2373, 2275, 2171, 2062, 1948, 1829, 1706, 1578, 1447, 1313, 1175, 1034,  891,  746, 599,   450,  301, 151};
const int sin_table1[64]= {3070, 3066, 3055, 3037, 3011, 2978, 2938, 2891, 2836, 2775, 2707, 2633, 2553, 2466, 2373, 2275, 2171, 2062, 1948, 1829, 1706, 1578, 1447, 1313, 1175, 1034,  891,  746,  599,  450,  301,  151,   0,   151,  301,  450,  599,  746,  891, 1034, 1175, 1313, 1447, 1578, 1706, 1829, 1948, 2062, 2171, 2275, 2373, 2466, 2553, 2633, 2707, 2775, 2836, 2891, 2938, 2978, 3011, 3037, 3055, 3066};


////PDC1 will count upward and duty cycle will go upto 100%,the same time PDC2 will get counts from second table and it starts decrements its duty cycle ,,,,,here PWM PERIOD IS SET FOR 8khz,,and two times the pair mos-fets will conducts and finally iam geting 16khz at resultant.

here the isr;


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
IFS2bits.PWMIF = 0; // Clear interrupt flag
   TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
        if (TBL_POINTER_NEW < TBL_POINTER_OLD)
         {
         delay_us(5);
         }
        TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
        DUTY_CYCLE = TBL_POINTER_SHIFT;
        PDC1 = sin_table[DUTY_CYCLE];
        PDC2 = sin_table1[DUTY_CYCLE];
        TBL_POINTER_OLD = TBL_POINTER_NEW;
}



/////////////////////////////////////////////////////////////

further discussions welcome regarding the single phase spwm using dspic30fxxx!!!!!!!!!!!!
 
Last edited by a moderator:

hai sir,

i want a 180 degree phase shift in between pwm1 and 2 channels, how can it possible? and i want to load 64 sine table entry's in 10ms , iam having a pwm interrupt of 125us, so iam updating my pdc1 and pdc2(180` phase shift)
duty cycle resistors at 125us interval. but 64X125=8000us, i cannot get an proper divisions for this 10 ms!!!!!!11
how can i handle such a problem?..
 

The above table answer exactly to your original question about shape not complying to sine wave.

Once you are requesting for a table to match for 64 pulses per 180 degrees, and the 'tool' I gave to you provide a way for calculate 32 pulses per 90 degrees, the entire vector can be mirrored due to symetric characteristic of the curve on both ascending and descending direction.

The new question you raised refers now to timing, but it concerns to Crystal and to processor Pre-scaller, and you must calculate it according to formulas given at microcontroller datasheet.





+++
 

sir,
i got an idea to make the sinewave perfectly and i checked it also...4 channels are smooth and nice..but you pls check the attached circuit, iam getting short circuit effect when i put a dead band in DTCON reg!. in my driver section my pic should provide a high impidence mode ! no bit clr or bit set conditions. but during the dead time pic will either in on/or in off position...if on= hi current....off= high current even i dont connect the transformer to the bridge...what to do?..i want a 2 us dead time inside the complimentary sections...pls reply..

- - - Updated - - -

SORRY,

IAM POSTING THE C CODE TOO FOR UR REFFERENCE


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "p30f2010.h" 
#include "libpic30.h"
#include <math.h>
 
_FOSC(CSW_FSCM_OFF & XT_PLL16);
_FWDT(WDT_OFF);
_FBORPOR(PBOR_OFF & PWRT_OFF & MCLR_EN);
 
#define FCY  24576000UL               // xtal = 6.144Mhz; PLLx16 -> 24.57 MIPS
#define FPWM 16000                    // 16 kHz, so that no audible noise is present.
#define SINE_TABLE_SIZE 128
 
#define buzzer    LATCbits.LATC14
#define change    LATCbits.LATC13
#define fan       LATDbits.LATD1
 
#define pwma      LATEbits.LATE0
#define pwmb      LATEbits.LATE1
#define pwmc      LATEbits.LATE2
#define pwmd      LATEbits.LATE3
 
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned int DUTY_CYCLE;
#define PI 3.1415926536
 
int n = 0;
double dc_min=0.1, dc_max=0.90;
int rt,sflag,sampleCount,millysec;
unsigned int val1,val2;
const char  title[17];
int counter,tick,counter1;
char *ptr,sync;
char lcdtmp, Direction ;
 
///////////////////////////////////////////////////////////
void __attribute__((interrupt, no_auto_psv)) _PWMInterrupt (void)
{
 
  double dc, sine_term;
    IFS2bits.PWMIF = 0; // Clear interrupt flag
 
    // Vary PWM duty cycle sinusoidally (in 100 steps)
    n = n + 1;
    if (n == 100)
      {
       n = 0;
        }
 
    // Calculate duty cycle
    sine_term = (1 + sin(2 * PI * n / 100.0)); 
    dc = sine_term * dc_min + (2 - sine_term) * dc_max; 
 
    PDC2 = dc * PTPER;
    PDC1 = (2*PTPER )- PDC2;  //phase shift 180`
 
}
//////////////////////////////////////////////////////////////////////////////
// Timer 1 interrupt service routine (runs automatically every 200us)
void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void)
{
    double dc, sine_term;
     _T1IF = 0;
 
  
 
}  
 
///////////////////////////////////////////////////////////////////////////////
void init_PWM()
{
  
    PTCONbits.PTSIDL = 0;
    PTCONbits.PTOPS = 0;
    PTCONbits.PTCKPS = 0;
    PTCONbits.PTMOD = 0b11;
     PTMR = 0x0000;
  PTPER = 1390;
      SEVTCMP = 0x0000;
    PWMCON1 = 0x0033;
    PWMCON2 = 0x0000;
PWMCON2bits.OSYNC = 1;     //Output overrides via the OVDCON register are synchronized to the PWM time base//
      DTCON1bits.DTA = 0b000000; //Unsigned 6-bit Dead Time Value bits for Dead Time Unit A//
      DTCON1bits.DTAPS = 0b00;    // Clock period for Dead Time Unit A is TCY//
      FLTACON = 0x0000;
 
      /**
     * Override Control Register
     *
     * POVDxH-POVxL     =   1 = Output PWMxH/PWMxL pin is controlled by PWM generator, 0 = Output PWMxH/PWMxL pin is controlled by value of POUTxH/POUTxL
     * POUTxH-POUTxL    =   1 = PWMxH/PWMxL pin is driven ACTIVE when POVDxH/POVDXL is cleared, 0 PWMxH/PWMxL pin is driven INACTIVE when POVDxH/POVDxL is cleared
     *
     * OVDCON   = POVD4H | POVD4L | POVD3H | POVD3L | POVD2H | POVD2L | POVD1H | POVD1L | POUT4H | POUT4L | POUT3H | POUT3L | POUT2H | POUT2L | POUT1H | POUT1L
     * 0x0000   =    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0   |    0
     */
    OVDCON = 0x0F0f;
 
 
 
    PDC1=PDC2=PTPER;
  
     /* start PWM */
    PTCONbits.PTEN = 1;
    IFS2bits.PWMIF = 0;         // Clear interrupt flag
     TRISE=0X0000;              // change to output mode from input Z mode
 
    IEC2bits.PWMIE = 1;         // disable PWM interrupts 
 
  // T1CON = 0;            // Clear the Timer 1 configuration
  //  TMR1 = 0;             // Reset Timer 1 counter
 //   PR1 = 3000;           // Set the Timer 1 period (max 65535)
 //   T1CONbits.TCS = 0;    // Select internal clock (Fosc/4)
 //   T1CONbits.TCKPS = 0;  // Prescaler (0=1:1, 1=1:8, 2=1:64, 3=1:256)
 //   _T1IP = 1;            // Set the Timer 1 interrupt priority
 //   _T1IF = 0;            // Clear the Timer 1 interrupt flag
  //  _T1IE = 1;            // Enable Timer 1 interrupt
 //   T1CONbits.TON = 1;    // Turn on Timer 1
    }
 
/////////////////////////////////////////////////
void InitTMR1(void)
{
 
}
////////////////////////////////////////////////////////
void InitTMR3(void)
{
 
}
/*                             MAIN ROUTINE                                  */
/*****************************************************************************/
int main()
{
TRISF=0X0000;
TRISE=0X000F;////Z MODE TO AVOID SHORT CIRCUIT
TRISD=0X0000;
TRISC=0X0000;
PTCON=0X0000;
OVDCON=0X0000;
 
 
delay_ms(15); 
lcd_init();
delay_ms(5);
buzzer=1;
delay_ms(2500);
buzzer=0;
 
init_PWM();
while(1)
{
 
   }
}

 

Attachments

  • SCHEMATIC1 _ PAGE1.pdf
    58.6 KB · Views: 108
hai everybody...
i solved todays problem..._FBORPOR(PBOR_OFF & PWRT_OFF & MCLR_EN);

here i didnot mensioned the pwm pulse start polarity..now i reversed it ...& working ok..frequency is 55.8 hz!...and peak-peak is 144 v!..how can i solve?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top