Main Page | File List | Globals | Related Pages

t2313_softpwm.h File Reference


Detailed Description

Atmel Corporation

Revision
1.2
Date
Tuesday, December 20, 2005 14:11:04 UTC

Definition in file t2313_softpwm.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define CH0_CLEAR   (pinlevelD &= ~(1 << PD2))
#define CH1_CLEAR   (pinlevelD &= ~(1 << PD3))
#define CH2_CLEAR   (pinlevelD &= ~(1 << PD4))
#define CH3_CLEAR   (pinlevelD &= ~(1 << PD5))
#define CH4_CLEAR   (pinlevelD &= ~(1 << PD6))
#define CH5_CLEAR   (pinlevelB &= ~(1 << PB0))
#define CH6_CLEAR   (pinlevelB &= ~(1 << PB1))
#define CH7_CLEAR   (pinlevelB &= ~(1 << PB2))
#define CH8_CLEAR   (pinlevelB &= ~(1 << PB3))
#define CH9_CLEAR   (pinlevelB &= ~(1 << PB4))
#define CHMAX   10
 Pin mappings.
#define DEBUG   0
 Select or deselect ISR Timing Debugging, 0 = disabled, 1 = enabled.
#define DEBUGPIN_OFF   PORTB &= ~(1 << PB7)
#define DEBUGPIN_ON   PORTB |= (1 << PB7)
#define DEBUGSET   DDRB |= (1 << DDB7)
#define PORTB_MASK   (1 << PB0)|(1 << PB1)|(1 << PB2)|(1 << PB3)|(1 << PB4)
 Set bits corresponding to pin usage above.
#define PORTD_MASK   (1 << PD2)|(1 << PD3)|(1 << PD4)|(1 << PD5)|(1 << PD6)
#define PWMDEFAULT   0x80

Functions

void DebugMonitor (void)
unsigned char GetNextChar (void)
unsigned char HexToASCII (unsigned char ch)
void Init (void)
 prototypes
void ManualControl (void)
 Example of PWM control via the serial port. Waits for a synchronization character and acts upon it.
void USART0_Init (unsigned int baudrate)
unsigned char USART0_Receive (void)
void USART0_Transmit (unsigned char data)


Define Documentation

#define CH0_CLEAR   (pinlevelD &= ~(1 << PD2))
 

Definition at line 41 of file t2313_softpwm.h.

#define CH1_CLEAR   (pinlevelD &= ~(1 << PD3))
 

Definition at line 42 of file t2313_softpwm.h.

#define CH2_CLEAR   (pinlevelD &= ~(1 << PD4))
 

Definition at line 43 of file t2313_softpwm.h.

#define CH3_CLEAR   (pinlevelD &= ~(1 << PD5))
 

Definition at line 44 of file t2313_softpwm.h.

#define CH4_CLEAR   (pinlevelD &= ~(1 << PD6))
 

Definition at line 45 of file t2313_softpwm.h.

#define CH5_CLEAR   (pinlevelB &= ~(1 << PB0))
 

Definition at line 47 of file t2313_softpwm.h.

#define CH6_CLEAR   (pinlevelB &= ~(1 << PB1))
 

Definition at line 48 of file t2313_softpwm.h.

#define CH7_CLEAR   (pinlevelB &= ~(1 << PB2))
 

Definition at line 49 of file t2313_softpwm.h.

#define CH8_CLEAR   (pinlevelB &= ~(1 << PB3))
 

Definition at line 50 of file t2313_softpwm.h.

#define CH9_CLEAR   (pinlevelB &= ~(1 << PB4))
 

Definition at line 51 of file t2313_softpwm.h.

#define CHMAX   10
 

Pin mappings.

Definition at line 38 of file t2313_softpwm.h.

Referenced by Init(), and ManualControl().

#define DEBUG   0
 

Select or deselect ISR Timing Debugging, 0 = disabled, 1 = enabled.

Definition at line 23 of file t2313_softpwm.h.

#define DEBUGPIN_OFF   PORTB &= ~(1 << PB7)
 

Definition at line 58 of file t2313_softpwm.h.

#define DEBUGPIN_ON   PORTB |= (1 << PB7)
 

Definition at line 57 of file t2313_softpwm.h.

#define DEBUGSET   DDRB |= (1 << DDB7)
 

Definition at line 59 of file t2313_softpwm.h.

Referenced by Init().

#define PORTB_MASK   (1 << PB0)|(1 << PB1)|(1 << PB2)|(1 << PB3)|(1 << PB4)
 

Set bits corresponding to pin usage above.

Definition at line 54 of file t2313_softpwm.h.

Referenced by Init().

#define PORTD_MASK   (1 << PD2)|(1 << PD3)|(1 << PD4)|(1 << PD5)|(1 << PD6)
 

Definition at line 55 of file t2313_softpwm.h.

Referenced by Init().

#define PWMDEFAULT   0x80
 

Definition at line 39 of file t2313_softpwm.h.

Referenced by Init().


Function Documentation

void DebugMonitor void   ) 
 

Referenced by main().

unsigned char GetNextChar void   ) 
 

Referenced by ManualControl().

unsigned char HexToASCII unsigned char  ch  ) 
 

void Init void   ) 
 

prototypes

Definition at line 184 of file t2313_softpwm.c.

References CHMAX, compare, compbuff, DEBUGSET, PORTB_MASK, PORTD_MASK, and PWMDEFAULT.

Referenced by main().

00185 {
00186   unsigned char i, pwm;
00187 
00188   CLKPR = (1 << CLKPCE);        // enable clock prescaler update
00189   CLKPR = 0;                    // set clock to maximum (= crystal)
00190 
00191   __watchdog_reset();           // reset watchdog timer
00192   MCUSR &= ~(1 << WDRF);        // clear the watchdog reset flag
00193   WDTCSR |= (1<<WDCE)|(1<<WDE); // start timed sequence
00194   WDTCSR = 0x00;                // disable watchdog timer
00195 
00196   DDRD = PORTD_MASK;            // set port pins to output
00197   DDRB = PORTB_MASK;            // set port pins to output
00198 
00199 #if DEBUG
00200   DEBUGSET;                     // make debug pin output (header file macro)
00201   pwm = 0;                      // worst-case default PWM level
00202 #else
00203   pwm = PWMDEFAULT;
00204 #endif
00205 
00206   for(i=0 ; i<CHMAX ; i++)      // initialise all channels
00207   {
00208     compare[i] = pwm;           // set default PWM values
00209     compbuff[i] = pwm;          // set default PWM values
00210   }
00211 
00212 #if DEBUG
00213   compare[0] = 0x01;            // make one channel active
00214   compbuff[0] = 0x01;
00215 #endif
00216 
00217   TIFR = (1 << TOV0);           // clear interrupt flag
00218   TIMSK = (1 << TOIE0);         // enable overflow interrupt
00219   TCCR0B = (1 << CS00);         // start timer, no prescale
00220 
00221   __enable_interrupt();         // enable interrupts
00222 }

void ManualControl void   ) 
 

Example of PWM control via the serial port. Waits for a synchronization character and acts upon it.

Definition at line 113 of file t2313_softpwm.c.

References CHMAX, compbuff, GetNextChar(), USART0_Receive(), and USART0_Transmit().

Referenced by main().

00114 {
00115   unsigned char rxdata, channel, temp, error;
00116 
00117     error = 0;                          // clear error flag
00118     while(USART0_Receive() != '#');     // wait for sync character
00119     USART0_Transmit('#');               // echo sync character
00120     channel = USART0_Receive() - 0x30;  // receive channel number
00121     if(channel >= CHMAX) error = 1;     // error if invalid channel
00122     USART0_Transmit(channel + 0x30);    // echo received character
00123 
00124     temp = GetNextChar();         // fetch upper nibble
00125     USART0_Transmit(temp);        // echo received character
00126     if (isxdigit(temp))           // check for a hex character
00127     {
00128       if ( temp > '9') temp -= 7; // subtract offset for A-F
00129       temp -= 0x30;               // subtract ASCII offset
00130     }
00131     else error = 1;               // error if not hex
00132     rxdata = temp << 4;           // store received upper nibble
00133 
00134     temp = GetNextChar();         // fetch lower nibble
00135     USART0_Transmit(temp);        // echo received character
00136     if (isxdigit(temp))           // check for a hex character
00137     {
00138       if ( temp > '9') temp -= 7; // subtract offset for A-F
00139       temp -= 0x30;               // subtract ASCII offset
00140     }
00141     else error = 1;               // error if not hex
00142     rxdata += temp;               // add lower nibble to upper nibble
00143 
00144     if(!error)                    // if data is good
00145     {
00146       compbuff[channel] = rxdata; // update compare buffer
00147 
00148       USART0_Transmit(':');       // send OK message
00149       USART0_Transmit('O');
00150       USART0_Transmit('K');
00151       USART0_Transmit('\r');
00152       USART0_Transmit('\n');
00153     }
00154     else                          // if data is not good
00155     {
00156       USART0_Transmit(':');       // send ERRor message
00157       USART0_Transmit('E');
00158       USART0_Transmit('R');
00159       USART0_Transmit('R');
00160       USART0_Transmit('\r');
00161       USART0_Transmit('\n');
00162     }
00163 }

Here is the call graph for this function:

void USART0_Init unsigned int  baudrate  ) 
 

Referenced by main().

unsigned char USART0_Receive void   ) 
 

Referenced by ManualControl().

void USART0_Transmit unsigned char  data  ) 
 

Referenced by ManualControl().


Generated on Tue Dec 20 15:11:31 2005 for AVR136: Low-Jitter Multi-Channel Software PWM by  doxygen 1.4.4