Instructions

366Libraries
© 2013 Conrad Electronic
while(PM_Value==0); // Measure Pulse Width or Period
Msg_WriteHex(PM_Value); // Output Measuring Value
}
For reason of better survey only a simplified version is shown here. Because of a collision on
Pin B.4 Timer_0 is used for pulse generation with Mega128. The entire program can be found in dir-
ectory PW_Measurement.
5.26.1.6 Timer Functions
In C-Control Pro Mega 32 there are two, in Mega128 three independent Timer available. These are
Timer_0 with 8 bit and Timer_1 with 16 bit (Timer_3 with 16 bit for Mega128 only). The timer have a
programmable prescaler (see Table ). After the defined period the timer will trigger an interrupt. An in-
terrupt routine can then be used to execute specific actions.
Timer_T0Time (8 Bit)
Example: Timer0: Switch output on with a delay of 6,94 ms (100x 69,44 µs, see Table)
void Timer0_ISR(void)
{
int irqcnt;
Port_WriteBit(0,1);
Timer_T0Stop() ; // stop Timer0
irqcnt=Irq_GetCount(INT_TIM0COMP);
}
void main(void)
{
Port_DataDirBit(0,0); // PortA.0 Output
Port_WriteBit(0,0); // PortA.0 Output=0
Irq_SetVect(INT_TIM0COMP,Timer0_ISR);// define Interrupt Service Routine
Timer_T0Time(100,PS0_1024); // set time and start Timer0
// other program code....
}
5.26.1.7 Timer_Disable
Timer Functions
Syntax
void Timer_Disable(byte timer);
Sub Timer_Disable(timer As Byte)