/****************************************************************************                                                                        ***  FILE        :  pwm.c                                                  ***                                                                        ***  DESCRIPTION :  Routines for controlling PWM	input to DC Drive motor	  ***                 controller							                  ***                                                                        ***  COPYRIGHT   :  2000 Monterey Bay Aquarium Research Institute          ***                                                                        ***	REVISION HISTORY:													  ***		1.0.0	Initial release (prm)									  ***************************************************************************/#ifndef PRECOMPHDRS#include	<TT8.h>			/* Tattletale Model 8 Definitions */#include	<tat332.h>		/* 68332 Tattletale (7,8) Hardware Definitions */#include	<tpu332.h>		/* 68332 Time Processing Unit Definitions */#include	<tt8lib.h>		/* definitions and prototypes for Model 8 library */#endif#include	<pwm.h>#include	<instrument.h>/*********************************************************************************	TPUSetupPWM			Setup TPU channel for Pulse-Width Modulation**	**	Notes:**		pwmper = period in tcr1 cycles [call TPUGetTCR1() for current cycles/sec]**		with default TPU setup and TT8 clock at 16 MHz, one tcr1 cycle is 250 ns**		pwmhi = time high in tcr1 cycles**		priority = LowPrior, MiddlePrior, or HighPrior [defined in tpu.h]**		read about value limitations in the TPU Reference Manual*******************************************************************************/void TPUSetupPWM(short chan, short pwmhi, short pwmper, short priority)	{		CHANPRIOR(chan, Disabled);			/* stop what it's doing */	if (priority == Disabled)			/* just shutting it down */		return;	*CIER &= ~(1 << chan);				/* don't want interrupts enabled */	FUNSEL(chan, PWM);					/* channel function select */	PRAM[chan][0] = OutputChan | NoChangePAC | (pwmhi ? ForceHigh : ForceLow);	PRAM[chan][2] = pwmhi;				/* time hi */	PRAM[chan][3] = pwmper;				/* period */	HOSTSERVREQ(chan, 2);				/* issue request */	CHANPRIOR(chan, priority);			/* set channel priority */	while (HOSTSERVSTAT(chan) & 3)		/* await reply */		;		} /* TPUSetupPWM() *//*********************************************************************************	TPUChangePWM			Change PWM values for inited TPU channel**	**	Notes:**		pwmper = period in tcr1 cycles [call TPUGetTCR1() for current value]**		pwmhi = time high in tcr1 cycles*******************************************************************************/void TPUChangePWM(short chan, short pwmhi, short pwmper)	{/***	NEED TO DO THIS WRITE COHERENTLY (AS DOUBLE WRITE)*/	* (ulong *) &PRAM[chan][2] = ((ulong) pwmhi << 16L) | (ulong) pwmper;	HOSTSERVREQ(chan, 1);				/* issue request */	while (HOSTSERVSTAT(chan) & 3)		/* await reply */		;	} /* TPUChangePWM() */