- This topic has 1 reply, 2 voices, and was last updated 13 years, 7 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › Timer 2 in compare mode
Hi,
I’m using an nRF24LE1 based on the 8051 architecture, so it is quite similiar.
What I am trying to do is set up Timer 2 with interrupts each ~15ms, using the compare interrupt feature.
my init routine is as such:
void timer2_init()
{
uint16_t test_ms = 0x2710; // 15ms, 10000
T2CON |= (1 << 7); // prescaler = Fcpu/24, one tick equals 1.5µs
T2CON |= (1 << 2); // Compare mode, Mode 1 (16 bits timer)
T2CON |= (1 << 0); // Start timer 2 with f/12 of f/24
CCEN = (1 << 1); // Compare with CRC
IEN0 |= (0x01 << 5); // Enable Timer2 interrupt
CRCH = (test_ms << ;
CRCL = test_ms & 0xFF;
}
Never the less, the interrupt only occurs each 100ms, and I just can’t understand why. In the interrupt, I make sure to clear the TF2 bit.
Any help on this issue is really much appreciated, since I have an assignement controlling a helicopter due in one week!
What I am trying to do is set up Timer 2 with interrupts each ~15ms, using the compare interrupt feature.
—I dont quite understand your problem… pls more info..
and about the TF2 bit. I dont think you need to clear the TF2..
Timer 2 Overflow (TF2.). This bit is set when T2 overflows. When T2 interrupt is enabled, this bit will cause the interrupt to be triggered. This bit will not be set if either TCLK or RCLK bits are set.