5282 GPT / PWM

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

5282 GPT / PWM

1,834 Views
FXMarquand
Contributor I
Hello,
 
I'm using a Coldfire 5282 in a complex real time system. My problem is around GPTB and PWM.
 
I have to generate on demand a specific signal to command an EValve on GPTB3. This signal is:
   ________                                          ________
_|                |||||||||||||||||||||||||||||||||||                ||||||||||||||||||||||||||||....
        (1)                          (2)                        (1)                     (2)
 
(1): 100ms on boost
(2): 900ms of 24KHz signal, duty cycle 40%
 
I understood that:
To generate a PWM signal, we need to use 2 GPTB channels: GPTB3 and the GPT channel associated to the output pin (channel 0 to output on pin GPTB0).
 
My problem is:
I want a 24KHz signal duty 40% (2) on pin GPTB3 but this channel is allready used to generate a similar signal on GPTB0.
So, how to "copy" the signal on GPTB0 to GPTB3? if it's not possible, how to generate my signal on the pin GPTB3?
 
I allready tried an interrupt based solution, but it seems to interfer with the system (48KHz interrupt uses too much ressources).
 
I thank you in advance for any help or idea. :smileyhappy:
Labels (1)
0 Kudos
5 Replies

746 Views
SimonMarsden_de
Contributor II
Hi

I think it could be done by using a single GPT channel together with two interrupts per second generated by a PIT timer...

First of all you configure the GPT channel as a GPIO output, and set the PIT timer to interrupt after 100ms.

In the interrupt service routine, you reconfigure the GPT to generate the 24kHz signal, and reconfigure the PIT to interrupt again after 900ms.

Finally in the second PIT interrupt routine you switch back to the first configuration.

Just a suggestion - I hope it helps.


Simon
0 Kudos

746 Views
FXMarquand
Contributor I
Yes, this is what i wanted to do, but there is still a problem.
 
That's the point: the channel 3 which controls pin 3 is allready used, in collaboration with channel0, to generate a pwm signal on pin 0(the same signal i want to generate on pin 3 btw). so i cant generate my signal on pin 3.
 
Maybe im wrong but i think i cant use pin3 because ch3 is used kinda like a "master" channel.
 
here is the actual code that i want to modify:
.
.
.
StartPWM( 3, 24000, 40 );
.
.
.
 
VOID StartPWM( uint8 bNumPWM, FLOAT fFreq, uint8 bAlpha )
{
 FLOAT fTmpFreq, fTmpAlpha;
 
 fTmpFreq  =  ( (FLOAT)SYSTEM_FREQ /(FLOAT)2.0) / fFreq;
 fTmpAlpha  =  (FLOAT)bAlpha / (FLOAT)100.0 * fTmpFreq;
  
 if ( bNumPWM >= 0 & bNumPWM <= 2 )
 {
  MCF5282_GPTA_GPTIOS  = (BYTE)(MCF5282_GPTA_GPTIOS | (1<<bNumPWM) | 0x08);
  MCF5282_GPTA_GPTOC3M = (BYTE)(MCF5282_GPTA_GPTOC3M | (1<<bNumPWM));
  MCF5282_GPTA_GPTOC3D = (BYTE)(MCF5282_GPTA_GPTOC3D | (1<<bNumPWM));
  MCF5282_GPTA_GPTSCR1 = MCF5282_GPT_GPTSCR1_GPTEN;     // GPT enable  
  MCF5282_GPTA_GPTTOV  = (BYTE)(MCF5282_GPTA_GPTTOV | (1<<bNumPWM) | 0x08); // toggle on OverFlow  
  MCF5282_GPTA_GPTCTL1 = (BYTE)(MCF5282_GPTA_GPTCTL1 | (1<<2*bNumPWM));
  MCF5282_GPTA_GPTSCR2  = MCF5282_GPT_GPTSCR2_TCRE;     // toggle on PWM3 overflow
  if ( bNumPWM == 0 )
   MCF5282_GPTA_GPTC0 = (uint16) (fTmpAlpha);
  else if ( bNumPWM == 1 )
   MCF5282_GPTA_GPTC1 = (uint16) (fTmpAlpha);
  else if ( bNumPWM == 2 )
   MCF5282_GPTA_GPTC2 = (uint16) (fTmpAlpha);
  MCF5282_GPTA_GPTC3 = (uint16) (fTmpFreq);
 }
 else if ( bNumPWM >= 4 & bNumPWM <= 6 ) 
 {
  bNumPWM -= 4;
  
  MCF5282_GPTB_GPTIOS  = (BYTE)(MCF5282_GPTB_GPTIOS | (1<<bNumPWM) | 0x08);
  MCF5282_GPTB_GPTOC3M = (BYTE)(MCF5282_GPTB_GPTOC3M | (1<<bNumPWM));
  MCF5282_GPTB_GPTOC3D = (BYTE)(MCF5282_GPTB_GPTOC3D | (1<<bNumPWM));
  MCF5282_GPTB_GPTSCR1 = MCF5282_GPT_GPTSCR1_GPTEN;     // GPT enable  
   MCF5282_GPTB_GPTTOV  = (BYTE)(MCF5282_GPTB_GPTTOV | (1<<bNumPWM) | 0x08); // toggle on OverFlow  
  MCF5282_GPTB_GPTCTL1 = (BYTE)(MCF5282_GPTB_GPTCTL1 | (1<<2*bNumPWM));
  MCF5282_GPTB_GPTSCR2  = MCF5282_GPT_GPTSCR2_TCRE;          // toggle on PWM3 overflow
  if ( bNumPWM == 0 )
   MCF5282_GPTB_GPTC0 = (uint16) (fTmpAlpha);
  else if ( bNumPWM == 1 )
   MCF5282_GPTB_GPTC1 = (uint16) (fTmpAlpha);
  else if ( bNumPWM == 2 )
   MCF5282_GPTB_GPTC2 = (uint16) (fTmpAlpha);
  MCF5282_GPTB_GPTC3 = (uint16) (fTmpFreq);
  
 }
}
0 Kudos

746 Views
SimonMarsden_de
Contributor II
My proposed solution only needs a single GPT channel for each PWM signal, and they are independent. Thus you can use Channel 0 for Pin 0 and Channel 3 for Pin 3.

You're right that Channel 3 has some special properties, but I'm suggesting that you don't use them.

Instead of your method of using channel 3 to shape the output of the other channel, I'm suggesting that you ONLY use the other channel, together with a Programmable Interrupt Timer (PIT) to reconfigure the GPT channel when the output waveform needs to change - i.e you don't need Channel 3 for the signal on Pin 0 and so you're free to re-use it for the second PWM signal.

Sorry if I'm missing something.


0 Kudos

746 Views
SimonMarsden_de
Contributor II
Sorry, reading the code sample again I realise that you're using Channel 3 to achieve the 40% duty cycle. I had thought that it was to achieve the 100ms / 900ms timing.
 
Sorry for the confusion.
0 Kudos

746 Views
FXMarquand
Contributor I
Yes Simon, you got it... now you understand my problem :smileytongue:
 
how to create my signal on pin 3 when ch3 is used?
0 Kudos