Main Page | File List | Globals

icp.c File Reference


Detailed Description

Atmel Corporation

Originally authored by Bruce McKenny

Revision
1.5
Date
Wednesday, November 02, 2005 13:20:02 UTC

Definition in file icp.c.

#include <stdio.h>
#include <inavr.h>
#include <iom64.h>
#include "icp.h"

Include dependency graph for icp.c:

Go to the source code of this file.

Defines

#define ENABLE_BIT_DEFINITIONS
#define ICP_BIT   PD4
#define ICP_CTL   TCCR1B
#define ICP_CTL_A   TCCR1A
#define ICP_DDR   DDRD
#define ICP_IE   TICIE1
#define ICP_IF   ICF1
#define ICP_OC_IE   OCIE1A
#define ICP_OC_IF   OCF1A
#define ICP_OCR   OCR1A
#define ICP_PIN   PIND
#define ICP_PORT   PORTD
#define ICP_PRESCALE   ((0 << CS12) | (0 << CS11) | (1 << CS10))
#define ICP_SENSE   ICES1
#define ICP_START_SENSE   (1 << ICP_SENSE)

Typedefs

typedef unsigned int icp_timer_t

Functions

void icp_init (void)
icp_sample_t icp_rx (void)
__interrupt void TIMER1_CAPT (void)
__interrupt void TIMER1_COMPA (void)

Variables

icp_timer_t icp_period
icp_sample_t icp_rx_q [ICP_RX_QSIZE]
unsigned char icp_rx_tail
icp_timer_t icp_start_time
icp_timer_t icp_stop_time
icp_total_t icp_total


Define Documentation

#define ENABLE_BIT_DEFINITIONS
 

Definition at line 29 of file icp.c.

#define ICP_BIT   PD4
 

Definition at line 40 of file icp.c.

Referenced by TIMER1_CAPT().

#define ICP_CTL   TCCR1B
 

Definition at line 51 of file icp.c.

Referenced by icp_init(), TIMER1_CAPT(), and TIMER1_COMPA().

#define ICP_CTL_A   TCCR1A
 

Definition at line 50 of file icp.c.

Referenced by icp_init().

#define ICP_DDR   DDRD
 

Definition at line 39 of file icp.c.

#define ICP_IE   TICIE1
 

Definition at line 48 of file icp.c.

Referenced by icp_init().

#define ICP_IF   ICF1
 

Definition at line 49 of file icp.c.

Referenced by TIMER1_CAPT().

#define ICP_OC_IE   OCIE1A
 

Definition at line 46 of file icp.c.

Referenced by icp_init().

#define ICP_OC_IF   OCF1A
 

Definition at line 47 of file icp.c.

Referenced by TIMER1_CAPT().

#define ICP_OCR   OCR1A
 

Definition at line 45 of file icp.c.

Referenced by icp_init(), TIMER1_CAPT(), and TIMER1_COMPA().

#define ICP_PIN   PIND
 

Definition at line 37 of file icp.c.

Referenced by TIMER1_CAPT().

#define ICP_PORT   PORTD
 

Definition at line 38 of file icp.c.

#define ICP_PRESCALE   ((0 << CS12) | (0 << CS11) | (1 << CS10))
 

Definition at line 53 of file icp.c.

Referenced by icp_init().

#define ICP_SENSE   ICES1
 

Definition at line 52 of file icp.c.

Referenced by TIMER1_CAPT(), and TIMER1_COMPA().

#define ICP_START_SENSE   (1 << ICP_SENSE)
 

Definition at line 55 of file icp.c.

Referenced by icp_init(), TIMER1_CAPT(), and TIMER1_COMPA().


Typedef Documentation

typedef unsigned int icp_timer_t
 

icp_start_time, icp_stop_time, icp_period

State variables for the Demodulator.

start_time, stop_time and period all have the same type as the respective TCNT register.

Definition at line 65 of file icp.c.


Function Documentation

void icp_init void   ) 
 

icp_init()

Set up the ICP timer.

Definition at line 328 of file icp.c.

References ICP_CTL, ICP_CTL_A, ICP_IE, ICP_OC_IE, ICP_OCR, ICP_PRESCALE, and ICP_START_SENSE.

Referenced by main().

icp_sample_t icp_rx void   ) 
 

icp_rx()

Fetch a sample from the queue. For analog mode, this is a moving average of the last QSIZE readings. For digital, it is the oldest reading.

Definition at line 298 of file icp.c.

References ICP_RX_QSIZE, icp_rx_tail, and icp_total.

Referenced by main().

__interrupt void TIMER1_CAPT void   ) 
 

TIMER1_CAPT()

ICP capture interrupt.

Definition at line 206 of file icp.c.

References ICP_BIT, ICP_CTL, ICP_IF, ICP_OC_IF, ICP_OCR, icp_period, ICP_PIN, ICP_SENSE, ICP_START_SENSE, icp_start_time, and icp_stop_time.

__interrupt void TIMER1_COMPA void   ) 
 

TIMER1_COMPA()

ICP timer Output Compare ISR.

The OC interrupt indicates that some edge didn't arrive as expected. This happens when the duty cycle is either 0% (no pulse at all) or 100% (pulse encompasses the entire period).

Definition at line 182 of file icp.c.

References ICP_CTL, ICP_OCR, icp_period, ICP_SCALE, ICP_SENSE, and ICP_START_SENSE.


Variable Documentation

icp_timer_t icp_period
 

Definition at line 67 of file icp.c.

Referenced by TIMER1_CAPT(), and TIMER1_COMPA().

icp_sample_t icp_rx_q[ICP_RX_QSIZE]
 

icp_rx_q[]

Stores demodulated samples.

The rx_q elements have the same type as the duty-cycle result.

Definition at line 76 of file icp.c.

unsigned char icp_rx_tail
 

icp_rx_tail, icp_rx_head

Queue state variables for icp_rx_q.

The rx_head and rx_tail indices need to be wide enough to accomodate [0:ICP_RX_QSIZE). Since QSIZE should generally not be very large, these are hard-coded as single bytes, which gets around certain atomicity concerns.

Definition at line 88 of file icp.c.

Referenced by icp_rx().

icp_timer_t icp_start_time
 

Definition at line 66 of file icp.c.

Referenced by TIMER1_CAPT().

icp_timer_t icp_stop_time
 

Definition at line 66 of file icp.c.

Referenced by TIMER1_CAPT().

icp_total_t icp_total
 

icp_total

Used in computing a moving average for ICP_ANALOG samples.

icp_total needs to be wide enough to acommodate the sum of RX_QSIZE icp_sample_t's.

Definition at line 102 of file icp.c.

Referenced by icp_rx().


Generated on Wed Nov 2 14:20:47 2005 for AVR135: Using Timer Capture to Measure PWM Duty Cycle by  doxygen 1.4.4