| rxpu99 
 
 
 Joined: 23 Jun 2014
 Posts: 10
 
 
 
			    
 
 | 
			
				| dspic30-33  Power supply PWM  phase setting |  
				|  Posted: Mon Jun 23, 2014 12:56 am |   |  
				| 
 |  
				| I am evaluating the ccs compiler , I investigated the compiler command reference, but i can not find how to setup the phase shift between 2 PWMs. 
 Following is the code how I setup the phase shift of power supply pwm with mplabx built in compiler:
 
 
  	  | Code: |  	  | #include<30F2020.h>
 
 #FUSES NOWDT                    //No Watch Dog Timer
 #FUSES NOWRTB                   //Boot block not write protected
 #FUSES NOPROTECT                //Code not protected from reading
 #FUSES NOWRT                    //Program memory not write protected
 #FUSES FRC_PLL                  //Internal Fast RC oscillator with PLL
 #FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
 #FUSES FRANGE_HIGH              //Frequency Range for FRC 14.55MHz
 #FUSES NOOSCIO                  //OSC2 is clock output
 #FUSES NOPR                     //Primary oscillaotr disabled
 #FUSES NOWINDIS                 //Watch Dog Timer in Window mode
 #FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
 #FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
 #FUSES PUT128                   //Power On Reset Timer value 128ms
 #FUSES NODEBUG                  //No Debug mode for ICD
 #FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
 #use delay(clock=58200000)      // =14.55MHZ *4 (interne rc oscillator)
 
 #word PTCON = getenv("SFR:PTCON")
 #word PTPER = getenv("SFR:PTPER")
 #word MDC = getenv("SFR:MDC")
 #word IOCON1 = getenv("SFR:IOCON1")
 #word IOCON2 = getenv("SFR:IOCON2")
 #word DTR1 = getenv("SFR:DTR1")
 #word DTR2 = getenv("SFR:DTR2")
 #word PWMCON1 = getenv("SFR:PWMCON1")
 #word PWMCON2 = getenv("SFR:PWMCON2")
 #word PDC1 = getenv("SFR:PDC1")
 #word PDC2 = getenv("SFR:PDC2")
 #word ALTDTR1 = getenv("SFR:ALTDTR1")
 #word ALTDTR2 = getenv("SFR:ALTDTR2")
 #word Phase1 = getenv("SFR:PHASE1")
 #word Phase2 = getenv("SFR:PHASE2")
 #bit PTEN = getenv("BIT:PTEN")
 
 void main()
 {
 
 PTCON = 0x0400;      // Enable immideate period updates
 PTPER = 0x8894;      // Period timed (Desired period / 1.05ns)
 MDC = 0x444B;        // Master duty cycle (50%) in this case
 Phase1 = 0x2225;     // Phase shift pwm channel 1
 Phase2 = 0x2225;     // Phase shift pwm channel 2
 PWMCON1 = 0x0180;    // Use Master duty cycle, Enable phase1 function
 PWMCON2 = 0x0180;    // Use Master duty cycle, Enable phase1 function
 IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
 IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
 DTR1 = 0x0040;       // Set dead time to 4*64*1.05ns ??
 DTR2 = 0x0040;       // Set dead time to 4*64*1.05ns ??
 //ALTDTR1 = 0x0040;
 //ALTDTR2 = 0x0040;
 PTEN = 1;            // Enable PWM module
 
 while (true)
 {
 
 }
 
 }
 
 | 
 
 
 I think ccs compiler is easier to use and has better and basic grouped fixed fuctions. I found everything except the phase shift function. I can not setup Phase1 and Phase2 as shown in code in the ccs compiler.
 
 thank you for your input.
 |  |