Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

main.c File Reference


Detailed Description

Atmel Corporation

Revision
1.2
Author
jtyssoe
, Atmel Corp.
Date
Thursday, November 10, 2005 10:10:48 UTC

Definition in file main.c.

#include <inavr.h>
#include <ioavr.h>
#include "pid.h"

Include dependency graph for main.c:

Go to the source code of this file.

Data Structures

struct  GLOBAL_FLAGS
 Flags for status information. More...

Functions

int Get_Measurement (void)
 Read system process value.
int Get_Reference (void)
 Read reference value.
void Init (void)
 Init of PID controller demo.
void main (void)
 Demo of PID controller.
void Set_Input (int inputValue)
 Set control input to system.
__interrupt void TIMER0_OVF_ISR (void)
 Timer interrupt to control the sampling interval.

Variables

GLOBAL_FLAGS gFlags
 Flags for status information.
PID_DATA pidData
 Parameters for regulator.


Function Documentation

int Get_Measurement void   ) 
 

Read system process value.

This function must return the measured data

Definition at line 78 of file main.c.

Referenced by main().

00079 {
00080   return 4;
00081 }

int Get_Reference void   ) 
 

Read reference value.

This function must return the reference value. May be constant or varying

Definition at line 69 of file main.c.

Referenced by main().

00070 {
00071   return 8;
00072 }

void Init void   ) 
 

Init of PID controller demo.

Definition at line 54 of file main.c.

References Init_PID(), K_D, K_I, K_P, and SCALING_FACTOR.

Referenced by main().

00055 {
00056   Init_PID(K_P * SCALING_FACTOR, K_I * SCALING_FACTOR , K_D * SCALING_FACTOR , &pidData);
00057 
00058   // Set up timer, enable timer/counte 0 overflow interrupt
00059   TCCR0A = (1<<CS00);
00060   TIMSK0 = (1<<TOIE0);
00061   TCNT0 = 0;
00062 }

Here is the call graph for this function:

void main void   ) 
 

Demo of PID controller.

Definition at line 96 of file main.c.

References FALSE, Get_Measurement(), Get_Reference(), gFlags, Init(), PID(), GLOBAL_FLAGS::pidTimer, and Set_Input().

00097 {
00098   int referenceValue, measurementValue, inputValue;
00099   Init();
00100   __enable_interrupt();
00101 
00102   while(1){
00103 
00104     // Run PID calculations once every PID timer timeout
00105     if(gFlags.pidTimer)
00106     {
00107       referenceValue = Get_Reference();
00108       measurementValue = Get_Measurement();
00109 
00110       inputValue = PID(referenceValue, measurementValue, &pidData);
00111 
00112       Set_Input(inputValue);
00113 
00114       gFlags.pidTimer = FALSE;
00115     }
00116   }
00117 }

Here is the call graph for this function:

void Set_Input int  inputValue  ) 
 

Set control input to system.

Set the output from the controller as input to system.

Definition at line 88 of file main.c.

Referenced by main().

00089 {
00090   ;
00091 }

__interrupt void TIMER0_OVF_ISR void   ) 
 

Timer interrupt to control the sampling interval.

Definition at line 41 of file main.c.

References gFlags, GLOBAL_FLAGS::pidTimer, TIME_INTERVAL, and TRUE.

00042 {
00043   static unsigned int i = 0;
00044   if(i < TIME_INTERVAL)
00045     i++;
00046   else{
00047     gFlags.pidTimer = TRUE;
00048     i = 0;
00049   }
00050 }


Variable Documentation

struct GLOBAL_FLAGS gFlags
 

Flags for status information.

Referenced by main(), and TIMER0_OVF_ISR().

struct PID_DATA pidData
 

Parameters for regulator.

Definition at line 36 of file main.c.


Generated on Thu Nov 10 11:12:11 2005 for AVR221 - PID controller by  doxygen 1.4.4