Main Page   Hardware Class Hierarchy   Hardware API     Mapping Class Hierarchy  Mapping API 

oPWM Class Reference

A class implementing a pulse width modulator using the Queued output match (QOM) function of the TPU. More...

#include <opwm.h>


Public Member Functions

MICROSECOND get_hightime (void)
 return current high time [DOS only]

MICROSECOND get_lowtime (void)
 return current low time [DOS only]

void WSwrite (void)
 Write object to simulator.

void hightime (MICROSECOND high)
 Hightime set the on time for the pulse measured in micro-seconds.

void nexthigh (MICROSECOND high)
 Used when oPWM is not operating to set new hightime when activated.

void lowtime (MICROSECOND low)
 Lowtime is the off time for the pulse measured in micro-seconds.

void nextlow (MICROSECOND low)
 Used when oPWM is not operating to set new lowtime when activated.

void priority (PRIORITY p)
 Sets the TPU channel execution priority (Ref. TPU Channel Utilization). Default MIDDLE_PRIORITY.

void value (bool onoff) const
 For oDO1_TPU.


Static Public Member Functions

int TCR1 (void)
void TMCR (int iarb)
bool HSQR (int chan, int val)
 Configures the host sequence register.

bool HSRR (int chan, int val)
 Configures the host sequence request register.

bool CPR (int chan, int val)
 Configures the channel priority register (Ref. TPU Channel Utilization).

bool CIER (int chan, int cie)
 Configures the channel interrupt enable register.

int CISR (int chan)
 Returns the channel interrupt status register.

void CISR_clear (int chan)
 Clears the channel interrupt status register for the channel.

bool TICR (int cirl, int cibv)
 Configures the TPU interrupt configuration register.

int tpu_vector (IOLINE channel)
 Given a channel, returns the vector number to use for an interrupt.


Detailed Description

A class implementing a pulse width modulator using the Queued output match (QOM) function of the TPU.

Operation
The oPWM is implemented using the queued output match function (QOM) of the TPU. The 68322 PWM speed is derived from two sources:
Remarks
The oPWM object can generate speeds as low as one micro-second.
Note:
Officially, the MRM periodic interrupt timer can go as low as 250 nano-seconds.
The maximum limit upon the PWM is dependent upon the setting of the TPU TCR1P (clock prescaler). The default setting for the prescaler is 32 (Ref. TPU). This allows a maximum of about 64 milli-seconds at 16 MHz. To generate a pulse beyond that requires setting the TPU TCR1P to 256 which allows a maximum of about 1 second.

It is important to understand the relationship between the number of clocks (TCR1P/PSCK) and the internal system clock to obtain the value for the high and low time; we see from the TPU reference manual 2-2 that the number of clocks required to generate a 1 microsecond pulse is 16 clocks at 16 MHz. Therefore, at 8 MHz, the clock is twice as slow which means it takes twice as many (32) clocks per micro second. Similarly if the prescaler is increased, this decreases the effective clock time on the TPU channel. Thus the higher the TPU effective system clock rate, the more clocks I would need to generate to get my 1 microsecond. Finnally, ignoring the round off of integer division, I thus obtain:

value = time_desired*(clock_frequency/number_clocks) example: scale_factor = (.0015 seconds)*(25000000 /32)

or if you divide everything by 1,000,000 since clock_frequency is in millions (rounded to 8,16, or 25MHz) then we can specify the time in one millionth of a second (microseconds). I have since replaced the simple clock_frequency definitions with more accurate float math versions. I felt the bloat was worth it :)

Sample Code
#include <hardware/opwm.h>
int main()
{
oPWM pwm(14);
// Generate 1.5 milli-second high time with 8 millisecond lowtime (period 9.5 milliseconds).
  pwm.hightime(1500);  
  pwm.lowtime(8000);
  pwm.operate(true);
}


Member Function Documentation

bool CIER int  chan,
int  cie
[static, inherited]
 

Configures the channel interrupt enable register.

Parameters:
int: channel
int: 1 enables; 0 disables

bool CPR int  chan,
int  val
[static, inherited]
 

Configures the channel priority register (Ref. TPU Channel Utilization).

Parameters:
int: channel
int: priority

bool HSQR int  chan,
int  val
[static, inherited]
 

Configures the host sequence register.

Parameters:
int: channel
int dependent upon function (CFSR) selected

bool HSRR int  chan,
int  val
[static, inherited]
 

Configures the host sequence request register.

Parameters:
int: channel
int: dependend upon function

void nexthigh MICROSECOND  high  )  [inherited]
 

Used when oPWM is not operating to set new hightime when activated.

DCmotor (and maybe like objects) needs this, because the only way to stop the PWM (that I know of) is to set hightime to 0--thus loosing the previous value of hightime. thus if you set the hightime while the object is non-operational, you want it to be set to that value the next time the object goes operational (see dcmotor.cpp to know what I'm talking about).

int TCR1 void   )  [static, inherited]
 

misnomer--should be TCR1 divisor--return number of clocks (PSCK,TCR1P modifications) Globally available object. Can be used in combination with TPU_REGISTER definition to say TPU_REGISTER->CFSR.BITS...

void TMCR int  iarb  )  [static, inherited]
 

was tpu_init Configures the channel function select register


The documentation for this class was generated from the following file:
Generated on Mon Oct 8 19:32:45 2007 for OOMRM Hardware API by doxygen1.3