Bluestar88
Member level 3
- Joined
- Oct 17, 2014
- Messages
- 59
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 447
I am doing Counter0 (T0Ck1) of PIC18f97j60 and I want to read the number of pulses which inters to it.
For this purpose, I Initialized the timer0 in counter mode and I produced PWM1 (from pin ECCP1) in Mikroc Program and I connected ECCPI to T0CK1 with a wire. But when I reade TMR0L is it 130 all of the times and It doesn't change. My code is here. I expect the TMR0L increments with rising time not fixed in 130. Please Help me. I am really confused.
For this purpose, I Initialized the timer0 in counter mode and I produced PWM1 (from pin ECCP1) in Mikroc Program and I connected ECCPI to T0CK1 with a wire. But when I reade TMR0L is it 130 all of the times and It doesn't change. My code is here. I expect the TMR0L increments with rising time not fixed in 130. Please Help me. I am really confused.
Code:
unsigned short current_duty=128;
char receive;
char buffer[16];
volatile char count=0;
void main() {
ADCON1 = 0x0B ; // ADC convertors will be used with AN2 and AN3
CMCON = 0x07 ; // turn off comparators
PORTA = 0 ;
TRISA = 0xfc ; // set PORTA as input for ADC
// except RA0 and RA1 which will be used as
// ethernet's LEDA and LEDB
TRISA.RA4 = 1; //make RA4/TOCKI an input
// T0CON = 0X28; //Counter 0, 16-bit mode, no prescaler
TMR0H = 0;
TMR0L = 0; //set count to 0
// PORTB = 0 ;
TRISB = 0xff ; // set PORTB as input for buttons
// PORTC = 0; // set PORTC to 0
// TRISC = 0; // designate PORTC pins as output
PORTD = 0 ;
TRISD = 0 ; // set PORTD as output
UART1_Init(9600);
Delay_ms(100); // Wait for UART module to stabilize
PWM1_Init(500); // Initialize PWM1 module at 5KHz
while(1)
{
PORTD.RD4=1;
PORTD.RD5=1;
PWM1_Start(); // start PWM1
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
T0CON.TMR0ON = 1; //turn on T0
T0CON.T08BIT= 1; //8bit
T0CON.T0CS=1; // Timer0 Clock Source Select bit
T0CON.T0SE=1; //Timer0 Source Edge Select bit
T0CON.PSA=1; // Timer0 Prescaler Assignment bit
UART1_Write(TMR0L);
}
}
}
}