We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I cannot get PWM signal in P7.1..pls help me MY Program is .. #include <stdio.h> /* standard I/O .h-file */ #include <reg167.h> /* special function register 80C167 */ #include <math.h> a int i; double La[200],Lb[200]; unsigned int sdata deltaKLa[400]; unsigned int sdata deltaKLb[400]; int sdata period_reg; int sdata PECC7_init; int sdata PECC6_init; void PWM (void); void pulse (void); void delay (int); void CC_PEC_init(void); void PWM_PEC_init(void); void PWM_Init(void); /****************/ /* main program */ /****************/ void main (void) { /* execution starts here */ /* initialize the serial interface */ #ifndef MCB167 /* do not initialize if you use Monitor-166 */ P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */ DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */ DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */ S0TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ S0RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ S0BG = 0x40; /* SET BAUDRATE TO 9600 BAUD */ S0CON = 0x8011; /* SET SERIAL MODE */ IEN = 1; /*Globally enable interrut request */ #endif while (1) { /* An embedded program does not stop and */ /* never returns. We've used an endless */ PWM(); pulse(); } /* loop. You may wish to put in your own */ } /* code were we've printed the dots (...). */ /*==================================================================*/ /* PWM GENERATOR /*==================================================================*/ void PWM (void) { double pi=3.1416,rad2count; float m; int p,k; int f; p=400; f=50; m=0.9; //printf ("Masukan Modulation Index P\n"); //scanf("%d",&p); //printf ("Masukan Nisbah Pemodulatan m\n"); //scanf("%f",&m); PECC7_init=0x0400+(p/2); PECC6_init=0x0400+(p/2); period_reg=(500000/(f*p*0.05)); rad2count=(pi*f)/10000000; for (k=1;k<=p/2;k++){ deltaKLa[k] = period_reg-((pi/(2*p))+(m*pi/(2*p))*sin((pi*2*k)/p))/rad2count; deltaKLb[k] = period_reg-((pi/(2*p))+(m*pi/(2*p))*sin((pi*2*k)/p))/rad2count; //deltaKLa[k]=period_reg/2; //deltaKLb[k]=period_reg/2; //deltaKLa[k] = (pi/(2*p))+(m*pi/(2*p))*sin((pi*2*k)/p); //deltaKLb[k] = (pi/(2*p))-(m*pi/(2*p))*sin((pi*2*k)/p); //deltaKLa[k] = deltaKLa[k]/0.000016; //deltaKLb[k] = deltaKLb[k]/0.000016; if(deltaKLa[k]>=period_reg-100){ deltaKLa[k]=period_reg+1; } if(deltaKLb[k]>=period_reg-100){ deltaKLb[k]=period_reg+1; } printf("%d ",k); printf("La=%d ,Lb=%d \n",deltaKLa[k],deltaKLb[k] ); } PWM_Init(); PWM_PEC_init(); CC_PEC_init(); PWMCON0=PWMCON0+0x000F; /* PTR0=1;PTR1=1;PTR2=1,PTR3=1 RUN PWM CHANNEL 0,1 */ DP2=DP2+0x00007; /* Set P2.0,P2.1 as Output */ P2=P2+0x00007; /* P2.0,P2.1-->high, Enable Driver output */ while(1){ } } /***********************************/ /* Init Capture/Compare for PEC service */ /***********************************/ void CC_PEC_init(void){ CCM2=0x0020; /* ACC9=1; CCMOD9=0x2 ---> negetive edge; */ DP2=0x0000; /* SEt P2 as input */ EXICON=0x0002; /* Fast External Interrupt Enable */ CC9IC=0x007E; /* Capture ch9 for PEC priority level 15,group 2 */ } /************************************/ /* Init PWM module for PEC service */ /************************************/ void PWM_PEC_init(void) { PWMIC= 0x007F; /*Set PWM Interrupt priority level 15,groupt 3 */ PECC7=PECC7_init; /*Initialize PECC7 for PWM module */ SRCP7=(int)&deltaKLa[1]; DSTP7=(int)&PW0; PECC6=PECC6_init; SRCP6=(int)&deltaKLb[1]; DSTP6=(int)&PW1; } /***********************/ /* PWM Init / /***********************/ void PWM_Init(void){ PWMCON0=0x0100; /* PTx = CLK cpu ,ENABLE CHANNEL 0 INTERRUPT,*/ PWMCON1=0x003F; /* PWM CHANNEL 1,2 ENABLE IN MODE 1 */ DP7=0x000F; /* SET P7.0,P7.1,P7.2 as OUTPUT */ P7=0x0008; /* Inverted PWM. */ PT2=PT1=PT0=0x0000; PP1=PP0=period_reg; /* Pulse witdh period */ PP2=PP3=2*period_reg+1; PW0=deltaKLa[1]; PW1=deltaKLb[1]; PW2=PW3=period_reg; //PW2=period_reg/2; //PP2=period_reg; } /*==================================================================*/ /* PWM Interrupt /*==================================================================*/ void PWM_0 (void) interrupt 0x3F using S_RBANK { //PIR0=0; /* Clear Interrut request flag PWM channel 0 */ //PWMIR=0; PECC7=PECC7_init; SRCP7=(unsigned short)&deltaKLa[1]; //SRCP6=(unsigned short)&deltaKLb[1]; //PECC6=PECC6_init; } /*==================================================================*/ /*==================================================================*/ /*===================================================================*/ /* PULSE GENERATOR /*===================================================================*/ void pulse (void) { DP2=0xFFFF; ODP2=0x00FF; while(1){ P7= 0xFF; delay (20000); P7=0x00; delay (20000); } } /*===================================================================*/ /* Funtion delay /*===================================================================*/ void delay (int i) { while(i>0) { i=i-1; } } /*--------------------------------------------------------------------*/