khansaab21
Advanced Member level 4
Device: PIC16F628A
Compiler: MikroC
Program Description: This is a simple test program in which timer1 is configured for counter operation. Counter has to be read every 10 sec and the maximum number of counts are 233 in that interval. Hence, only TMR1L is more than enough to be read.
Problem: Every external pulse on the counter pin increases '3' in the register rather than increasing '1'. Can anybody please hepl me with that.
Schematic:
Code:
void main() {
CMCON |= 7; // Disable Comparators
TRISA = 0; // Setting in output mode
TRISB.B6 = 1; // Making it input for counter inputs
T1CON = 6; // Initializing Timer1 for asynchronous counter operation
TMR1H = 0; // Clearing upper byte
for (;
{
// Resetting variables and registers
TMR1L = 0;
T1CON.B0 = 1; // Enable Timer 1
Delay_ms(5000); // Wait for 10 sec
T1CON.B0 = 0; // Disable Timer 1
PORTA = TMR1L;
}
}
Note:
Input has to be through opto coupler.
Compiler: MikroC
Program Description: This is a simple test program in which timer1 is configured for counter operation. Counter has to be read every 10 sec and the maximum number of counts are 233 in that interval. Hence, only TMR1L is more than enough to be read.
Problem: Every external pulse on the counter pin increases '3' in the register rather than increasing '1'. Can anybody please hepl me with that.
Schematic:
Code:
void main() {
CMCON |= 7; // Disable Comparators
TRISA = 0; // Setting in output mode
TRISB.B6 = 1; // Making it input for counter inputs
T1CON = 6; // Initializing Timer1 for asynchronous counter operation
TMR1H = 0; // Clearing upper byte
for (;
{
// Resetting variables and registers
TMR1L = 0;
T1CON.B0 = 1; // Enable Timer 1
Delay_ms(5000); // Wait for 10 sec
T1CON.B0 = 0; // Disable Timer 1
PORTA = TMR1L;
}
}
Note:
Input has to be through opto coupler.