Hi.
I am a beginner with the 8051 controllers, and are trying to run a servo. I need 20ms period and 1-2ms pulses, as Im sure a lot of you guys know.
I was trying this :
void main() { uint16_t value = 0; P0DIR = 0x00; P0 = 0x00; TCON |= (1 << 6); // Start timer 1 TMOD |= (2 << 4); // mode 2 - auto reloads while(1) { if(TF1 == 1) { value++; } if(value >= 26500) { P00 ^= (1 << 0); value = 0; } } }
calculating that my 16MHz clock is divided by 12 for the timer; 16MHz/12 = 1.3 MHz => T = 1/1.3MHz = 7.5*10^-7 per count.
Then I need 20ms/7.5*10^-7 = 26666 overflows to get my 20ms output. The problem is that this is not quite accurate, it gives about 35ms. Is my calculations wrong?
Also, I should not be toggling, but that is ust for testing purposes. Using nRF24LE1.
Thank you all in advance!