On 28.08.2016 12:11, Maarten Brock wrote: >> On 28.08.2016 10:48, Philipp Klaus Krause wrote: >>> I have some trouble understanding the C8051 clock and timers. >>> In the tutorial code at >>> http://www.colecovision.eu/mcs51/C8051F340%20380%20LED.shtml I get a >>> timer interrupt at 1000 Hz. But I got the values for configuring the >>> timer experimentally, and can't seem to get them from the datasheet. >>> >>> According to the datsheet, at startup the internal oscillator is running >>> at 24.5 Mhz (OSCICL reset value), then gets divided by 128 (OSCICN reset >>> value) and then used for SYSCLK (CLKSEL rest value). >>> >>> Thus SYSCLK is 24.5 Mhz / 128 about 0.1914 Mhz. >>> >>> In the timer, this then gets divided by 12 (CKCON reset value) adn then >>> sued as the frequency for incrementing the timer (TMOD value as in the >>> tutorial code). >>> >>> Thus the timer increment frequency is 24.5 Mhz / 128 / 12 about 0.0159 >>> Mhz. >>> >>> The tutorial code ssets the timer register to (65536 - 125) in the >>> interrupt handler. >>> >>> Thus the timer interrupt frequency is 24.5 Mhz / 128 / 12 / 125 about >>> 127 Hz. >>> >>> So from the datasheet I get 127 Hz. But on the hardware I see 1000 Hz. >>> >>> Philipp >> >> P.S.: I have verified that the OSCICN, CLKSEL and CKCON reset values are >> as in the datasheet. Initializing these registers explicitly to their >> reset value does not change anything. > > First of all which MCU are you using exactly? The C8051F340 as in the URL > name does not run the internal RC oscillator at 24.5MHz but runs at 12MHz. > And the default OSCICN value makes SYSCLK=HFRCO/8. Next there is a 4x > clock multiplier which if off after reset (CLKMUL). And CLKSEL can choose > this multiplied clock /2 or /1. > > Maarten
For some reason, I was looking at the C8051F410 data sheet instead of the C8051F340. Sorry for the noise. Philipp
signature.asc
Description: OpenPGP digital signature
------------------------------------------------------------------------------
_______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user