Instructions
365 C-Control Pro IDE
© 2013 Conrad Electronic
Timer_T1PWMX(255,128,128,PS_8);
Timer_T1PWA(128);
Timer_T1PWB(128);
AbsDelay(1000);
// set OC1B off
Timer_Disable(1);
Timer_T1PWM(255,128,PS_8);
Port_DataDirBit(14,1);
Port_WriteBit(14,0);
}
5.26.1.5 Pulse & Period Measurement
By use of Timer_1 or Timer_3 (only Mega128) pulse widths and signal periods can be measured.
Here by use of the Input Capture Function (specific register of the Controller) the time between two
signal slopes is measured. This function utilizes the Capture-Interrupt (INT_TIM1CAPT). A pulse is
measured between a rising and the next falling signal edge. A period is measured between two rising
signal edges. Because of the Input Capture Function program delay times will not as an inaccuracy
be entered into the measuring result. With a programmable prescaler the resolution of Timer_1 can
be set. Prescaler see Table.
Example: Activate Pulse Width Measurement (Project PMeasurement) 434 µs (100 x 4,34 µs, see
Table)
word PM_Value;
void Timer1_ISR(void)
{
int irqcnt;
PM_Value=Timer_T1GetPM();
irqcnt=Irq_GetCount(INT_TIM1CAPT);
}
void main(void)
{
byte n;
// Define Interrupt Service Routine
Irq_SetVect(INT_TIM1CAPT,Timer1_ISR);
Timer_T0PWM(100,PS0_64); // Start Pulse Generator Timer 0
// Measurement starts here
// Output Timer0 OC0(PortB.3) connect to ICP(input capture pin, PortD.6)
PM_Value=0;
// Set mode to Pulse Width Measurement and determine prescaler
Timer_T1PM(0,PS_64);