Skip to main content
deleted 54 characters in body
Source Link
Majenko
  • 56.4k
  • 9
  • 106
  • 190

Ok... first offUnless you have made any changes to the internal oscillator is 8MHz, not 1MHz. So \$F_{CY}\$settings with the OSCCON register it will be \$\frac{8}{4}=2MHz\$. So I havedefault to assume that you have set the oscillator'sa prescaler toof /8 to give 1MHz. If that is true, then the \$F_{CY}\$ will be 256000Hz.

Your prescaler is set to 256, so the clock tick will be at \$\frac{256000}{256}=1000Hz\$

You think you're setting the overflow value to 65535, but you're not. You're actually setting the current timer's high byte to 0xFFFF (which, since it's an 8 bit register is actually 0xFF), and the timer's low byte to 0x00, so the current timer count is 0xFF00 in total. It ticks up, and when it loops from 0xFFFF to 0x0000 it triggers an interrupt. That's 256 ticks away.

So at 1000Hz divided by 256 ticks, that's \$\frac{1000}{256}=3.90625Hz.\$

Which is almost 4 times per second.

So to get exactly one second, with a 1000Hz tick, you need 1000 ticks. So you would set your timer values to 65536 minus 1000, or 64536, which is 0xFC18, so your TIMERH would be 0xFC and your TIMERL would be 0x18.

Ok... first off the internal oscillator is 8MHz, not 1MHz. So \$F_{CY}\$ will be \$\frac{8}{4}=2MHz\$. So I have to assume that you have set the oscillator's prescaler to /8 to give 1MHz. If that is true, then the \$F_{CY}\$ will be 256000Hz.

Your prescaler is set to 256, so the clock tick will be at \$\frac{256000}{256}=1000Hz\$

You think you're setting the overflow value to 65535, but you're not. You're actually setting the current timer's high byte to 0xFFFF (which, since it's an 8 bit register is actually 0xFF), and the timer's low byte to 0x00, so the current timer count is 0xFF00 in total. It ticks up, and when it loops from 0xFFFF to 0x0000 it triggers an interrupt. That's 256 ticks away.

So at 1000Hz divided by 256 ticks, that's \$\frac{1000}{256}=3.90625Hz.\$

Which is almost 4 times per second.

So to get exactly one second, with a 1000Hz tick, you need 1000 ticks. So you would set your timer values to 65536 minus 1000, or 64536, which is 0xFC18, so your TIMERH would be 0xFC and your TIMERL would be 0x18.

Unless you have made any changes to the oscillator settings with the OSCCON register it will default to a prescaler of /8 to give 1MHz. If that is true, then the \$F_{CY}\$ will be 256000Hz.

Your prescaler is set to 256, so the clock tick will be at \$\frac{256000}{256}=1000Hz\$

You think you're setting the overflow value to 65535, but you're not. You're actually setting the current timer's high byte to 0xFFFF (which, since it's an 8 bit register is actually 0xFF), and the timer's low byte to 0x00, so the current timer count is 0xFF00 in total. It ticks up, and when it loops from 0xFFFF to 0x0000 it triggers an interrupt. That's 256 ticks away.

So at 1000Hz divided by 256 ticks, that's \$\frac{1000}{256}=3.90625Hz.\$

Which is almost 4 times per second.

So to get exactly one second, with a 1000Hz tick, you need 1000 ticks. So you would set your timer values to 65536 minus 1000, or 64536, which is 0xFC18, so your TIMERH would be 0xFC and your TIMERL would be 0x18.

Source Link
Majenko
  • 56.4k
  • 9
  • 106
  • 190

Ok... first off the internal oscillator is 8MHz, not 1MHz. So \$F_{CY}\$ will be \$\frac{8}{4}=2MHz\$. So I have to assume that you have set the oscillator's prescaler to /8 to give 1MHz. If that is true, then the \$F_{CY}\$ will be 256000Hz.

Your prescaler is set to 256, so the clock tick will be at \$\frac{256000}{256}=1000Hz\$

You think you're setting the overflow value to 65535, but you're not. You're actually setting the current timer's high byte to 0xFFFF (which, since it's an 8 bit register is actually 0xFF), and the timer's low byte to 0x00, so the current timer count is 0xFF00 in total. It ticks up, and when it loops from 0xFFFF to 0x0000 it triggers an interrupt. That's 256 ticks away.

So at 1000Hz divided by 256 ticks, that's \$\frac{1000}{256}=3.90625Hz.\$

Which is almost 4 times per second.

So to get exactly one second, with a 1000Hz tick, you need 1000 ticks. So you would set your timer values to 65536 minus 1000, or 64536, which is 0xFC18, so your TIMERH would be 0xFC and your TIMERL would be 0x18.