View Single Post
Old 22-04-2014, 10:42 AM   #1
thienduyen3
Nhập môn đệ tử
 
Tham gia ngày: Sep 2013
Bài gửi: 2
:
các bác giúp dùm em đoạn code cho dspic33fj12mc202 này với

Em đã thử đoạn code này vô mplab và cũng đã cài c30 nhưng không xuất ra file .hex được không biết là bị gì nũa, em đang lam đè tài về nghịch lưu 1pha bác nào có code điều chế xung PWm thì cho em xin với, em xin cảm ơn

code
#include "p33FJ12MC202.h"
#define T 499
_FOSCSEL(FNOSC_PRIPLL&IESO_OFF);
_FOSC(FCKSM_CSDCMD&OSCIOFNC_OFF&POSCMD_XT);
_FWDT(FWDTEN_OFF);
_FPOR(PWMPIN_ON&HPOL_ON&LPOL_ON);
int a=0,b=0;
int const SinValue[200] = {515, 530, 546, 562, 577, 592, 608, 623, 638,
653, 668, 683, 697, 711, 725, 739, 753, 766, 779, 792, 805, 817, 829,
840, 852, 863, 873, 883, 893, 903, 912, 920, 928, 936, 943, 950, 957,
963, 968, 973, 978, 982, 986, 989, 992, 994, 996, 997, 998, 998, 998,
997, 996, 994, 992, 989, 986, 982, 978, 974, 969, 963, 957, 951, 944,
937, 929, 921, 912, 903, 894, 884, 874, 863, 852, 841, 829, 818, 805,
793, 780, 767, 754, 740, 726, 712, 698, 683, 669, 654, 639, 624, 609,
593, 578, 562, 547, 531, 515, 500, 484, 468, 453, 437, 422, 406, 391,
376, 361, 346, 331, 316, 302, 287, 273, 259, 246, 232, 219, 206, 194,
182, 170, 158, 147, 136, 125, 115, 105, 96, 87, 78, 70, 62, 55, 48, 41,
35, 30, 25, 20, 16, 12, 9, 6, 4, 2, 1, 0, 0, 0, 1, 2, 4, 6, 9, 12, 15,
19, 24, 29, 35, 41, 47, 54, 61, 69, 77, 86, 95, 104, 114, 124, 134, 145,
156, 168, 180, 1 92, 205, 217, 230, 244, 257, 271, 285, 299, 314, 329,
343, 358, 373, 389, 404, 419, 435, 450, 466, 482, 497};
int main(void)
{
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD = 38; //M=40
CLKDIVbits.PLLPOST=0; //N1=2
CLKDIVbits.PLLPRE=0; //N2=2
//FOSC = FIN*(M/(N1*N2)) = 80MHz FCY = FOSC/2 = 40MHz
// Initiate Clock Switch to FRC oscillator with PLL (NOSC=0b001)
// Wait for Clock switch to occur
while (OSCCONbits.COSC != 0b011);
while (_LOCK !=1);//cho PLL bat dau khoa pha
TRISB=0X0000;
LATB=0X0000;
//Continuous up/down cout mode
P1TCONbits.PTMOD = 0b10;
//PWM time base input clock period is 4 TCY(1:4 prescale)
P1TCONbits.PTCKPS = 0b01;
//PWM Time Base Output Postscale 1:1
P1TCONbits.PTOPS = 0b0000;
//F1TPER = Fcy/(Fpwm * P1TMRPrescaler * 2) - 1
//499 = 40M/(Fpwm * 4 * 2) - 1
//Fpwm = 10khz
P1TPER = T;
//Complementary PWM Output Mode
PWM1CON1bits.PMOD1=0;
PWM1CON1bits.PMOD2=0;
//Enable for PWM output
PWM1CON1bits.PEN2H=1; PWM1CON1bits.PEN1H=1;
PWM1CON1bits.PEN2L=1; PWM1CON1bits.PEN1L=1;
// Immediate update of PWM enabled
PWM1CON2bits.IUE=0;
//Update from duty cycle and period buffer registers are enabled
PWM2CON2bits.UDIS=0;
//Dead Time Unit A Prescale 1:1
P1DTCON1bits.DTAPS=0b00;
//Deadtime = 1us
P1DTCON1bits.DTA = 40;
P1DTCON2bits.DTS2A=0; P1DTCON2bits.DTS1A=0;
P1DTCON2bits.DTS1I=1; P1DTCON2bits.DTS2I=1;
P1OVDCONbits.POVD2H=1; P1OVDCONbits.POVD1H=1;
P1OVDCONbits.POVD2L=1; P1OVDCONbits.POVD1L=1;
// Initialize duty cycle values for PWM1 and PWM2 signals
P1DC1=0;
P1DC2=0;
// Clear PWM Interrupt Flag
_PWM1IF=0;
//Enable the PWM1 interrupt
_PWM1IE=1;
//Enabling PWM Pulse Generation
P1TCONbits.PTEN=1;
while(1);
}
void __attribute__((interrupt,auto_psv)) _MPWM1Interrupt(void)
{// Clear PWM Interrupt Flag
_PWM1IF=0; a++;
if(a==200) {a=0;}
P1DC1= (SinValue[a])*0.95;
b=a+100;
if(b>199) {b=(b-200);}
P1DC2 = (SinValue[b])*0.95;
}
thienduyen3 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn