mircea2012
Newbie level 4
- Joined
- Jan 2, 2013
- Messages
- 5
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,321
Hy everybody.
I want to make a programm who accomplish the next tasks : generate a
delay of 3 seconds.
The RD7 pin must stay ON 3 seconds, then must stay OFF 3 seonds, and so
on.
freq. out = freq. clk / (Prescaler*(256 - TMR0)*count)
In my program I work with internal clk (T0CS=0) so the freq. clk is
4Mhz/4 = 1Mhz. ( Period = 1 / freq; internal instruction cycle is 1
microsec).
freq. out = 1 / T = 1 / 3 sec = 0.33Hz and replacing 0.33Hz = 1MHz / (256 * (256 - 0) * count)
count = 1MHz / 65536 * 0.33Hz
count = 46.
#include<pic.h>
unsigned char counter;
void interrupt Timer0_ISR(void)
{
if ( T0IE && T0IF ) // are TMR0 interrupts enabled and//is the TMR0 interrupt flag set?
{
T0IF = 0; // TMR0 interrupt flag must be cleared in software
++counter; // increment the counter variable by 1
if(counter == 46)
PORTDbits.RD7 ^= 1; // toggle the RD7 pin
}
}
Init(void)
{
TMR0 = 0; // clear the TMR0 register
OPTION_REG = 0B00000111; // Use the internal instruction clock, choosing to work with a Prescaler (1 : 256)
INTCONbits.T0IE = 1; // enable TMR0 overflow
INTCONbits.GIE = 1; // enable Global
interrupts
}
main(void)
{
TRISD = 0B01111111;
PORTDbits.RD7 = 0;
Init();
while(1)
{
}
}
I simulate this program with MPLAB SIM but timer0 dont want to
increment.
Please help me.
I dont know if my computations is good.
All the best.
I want to make a programm who accomplish the next tasks : generate a
delay of 3 seconds.
The RD7 pin must stay ON 3 seconds, then must stay OFF 3 seonds, and so
on.
freq. out = freq. clk / (Prescaler*(256 - TMR0)*count)
In my program I work with internal clk (T0CS=0) so the freq. clk is
4Mhz/4 = 1Mhz. ( Period = 1 / freq; internal instruction cycle is 1
microsec).
freq. out = 1 / T = 1 / 3 sec = 0.33Hz and replacing 0.33Hz = 1MHz / (256 * (256 - 0) * count)
count = 1MHz / 65536 * 0.33Hz
count = 46.
#include<pic.h>
unsigned char counter;
void interrupt Timer0_ISR(void)
{
if ( T0IE && T0IF ) // are TMR0 interrupts enabled and//is the TMR0 interrupt flag set?
{
T0IF = 0; // TMR0 interrupt flag must be cleared in software
++counter; // increment the counter variable by 1
if(counter == 46)
PORTDbits.RD7 ^= 1; // toggle the RD7 pin
}
}
Init(void)
{
TMR0 = 0; // clear the TMR0 register
OPTION_REG = 0B00000111; // Use the internal instruction clock, choosing to work with a Prescaler (1 : 256)
INTCONbits.T0IE = 1; // enable TMR0 overflow
INTCONbits.GIE = 1; // enable Global
interrupts
}
main(void)
{
TRISD = 0B01111111;
PORTDbits.RD7 = 0;
Init();
while(1)
{
}
}
I simulate this program with MPLAB SIM but timer0 dont want to
increment.
Please help me.
I dont know if my computations is good.
All the best.