PWMMC problem on 8-bits MC68HC908MR16

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWMMC problem on 8-bits MC68HC908MR16

Jump to solution
518 Views
Cruvix
Contributor I

Hello community,

I encounter a problem with the PWMMC peripheral on the 8-bits microcontroler MC68HC908MR16 from freescale. Let me present you the problem.

I. Configuration

  • Microcontroler : MC68HC908MR16
  • IDE : CodeWarrior

II. Project presentation

I'm working on an old software that control a three-phase motor with a scalar control approach (open loop), based on the application note AN1857 (attachments). The principle is to loop through a sine wave (with its third harmonic) look up table each 0.4ms (2.5kHz) and output PWM signal describing this sine wave with the good duty cycle. I would like to generate a 220Hz sine wave with 2.5kHz carrier frequency => 11 points for the whole signal.

III. Problem description

When I see the 6 PWM generated on a scope, I notice an inconsistent duty cycle. So, I try a simple approach to test PWMMC's configuration with only 2 duty cycle values (250 and 500 corresponding to 25% and 50% duty cycle respectively).

 

 

 

 

//The table wih the dummy duty cycle values
const unsigned long aul_pval[2] = {
   250,
   500
};

 

 

 

In the PWM interrupt, I cycle between these two values and load them into the PVAL1, PVAL3 and PVAL5 registers :

 

 

 

unsigned int uiPhase = 0;

void vPWMcalc (void){	
   COPCTL=0x00;	
   PCTL1.R &= 0xE3; /* clear PWMF bit */	  	  

   PVAL1 = aul_pval[uiPhase];
   PVAL3 = aul_pval[uiPhase];
   PVAL5 = aul_pval[uiPhase];

   if (uiPhase >= 1) {
      uiPhase = 0;
   }
   else {
      uiPhase++;
   }	

   PCTL1.R |= 0x02; /* set LDOK bit */					
}

 

 

 

However, when I ran this code, the PWM output does not work as I expected :

  • I have 2 times the same duty cycle for consecutives pulses (I expect an alternating between the 2 values)
  • An inconsistent duty cycle is present and not in the simple dummy table

On the next figures, the yellow signal is the High PWM and purple signal the Low PWM. The blue one is just a port that I toggle in the PWM interrupt to show the center aligned mode.

Cruvix_0-1729514381802.png

Figure 1  : Duty cycle of 50% OK, but the next pulse is 50% too

Cruvix_1-1729514414888.png

Figure 2 : Duty cycle of 25% OK, but the next pulse is 25% too

Cruvix_3-1729514715022.png

Figure 3 : unknown PWM duty cycle (35% in principle)

Its look likes there is a reload every 2 cycles, whereas I configure the PWMMC peripheral with a reload every cycle, but is does not explain the unknown duty cycle on figure 3. Moreover, it look likes the bufferisation of PVAL1, PVAL3 and PVAL5 are not applied every cycle.

III. PWMMC peripheral configuration

Here the configuration of the PWMMC peripheral in the project :

  • CONFIG.R =  0x09;
  • PMOD =  0x03E8;
  • DEADTM.R =  12;
  • DISMAP.R = 0xFF;
  • PCTL2.R = 0x01;
  • PWMOUT.R = 0x00;
  • PCTL1.R  |= 0x02;

I attach too the code and PWMMC configuration of Freescale Application Note 1857 to see differences.

IV. What I try to solve the problem (but does not work)

  • Use volatile variables outside ISR to avoid CPU caching
  • Use the first interrupt request when enabling the PWMMC to load values in PVAL1, PVAL3 and PVAL5 in advance (As I understand modified registers are buffered).

After many searches on the web and in the documentation, I don't understand the problem

 

Thank you in advance for your answers !

Regards.

Cruvix.

0 Kudos
Reply
1 Solution
430 Views
Cruvix
Contributor I

OK,


Problem solved, the PWMMC device did not start correctly. Instead of enabling the PWMMC with the PWMEN bit only, we enabled it with other bits. In addition, we wrote (with an ‘=’) instead of reading and writing (with ‘|=’) to the PCTL1 register. As the documentation says, the PWMMC device buffers the registers and requires the register to be read before writing.

View solution in original post

0 Kudos
Reply
1 Reply
431 Views
Cruvix
Contributor I

OK,


Problem solved, the PWMMC device did not start correctly. Instead of enabling the PWMMC with the PWMEN bit only, we enabled it with other bits. In addition, we wrote (with an ‘=’) instead of reading and writing (with ‘|=’) to the PCTL1 register. As the documentation says, the PWMMC device buffers the registers and requires the register to be read before writing.

0 Kudos
Reply