??? 01/25/10 16:29 Read: times |
#172710 - execution speed and crystal frequency |
Hi, I just started out with microcontrolers and have a question about the execution speed in combination with the crystal used as clock.
I made a test program which simply decrements P0 in a loop (with some delay). It all works fine, I've got 8 LED's connected to P0 so I have a simple binairy counter. Now for my question: I have two different crystal oscillators, one with a frequency of 11.059 MHz and on of 32.768 MHz. I read the 8051 tutorial from the site and I understand that with the 32 MHz one my program should run almost 3x as fast as the 11 Mhz one, right? Except it doesn't... When I change the crystal the LED's blink just as fast. I timed it with the stopwatch on my phone and it takes (independent of the crystal) about 6 seconds to count from 0 all the way to 255 where it wraps back to 0. The microcontroler I use is an AT89S51RC. As far as I can tell from the data-sheet it has no internal timer and can be used with a crystal between 0 and 33MHz. I connected the crystal between pins XTAL1 and XTAL2 and connected connected both pins to the ground using 30pF capacitors as instructed in the data-sheet. The program I run is: ORG 0h START: MOV P0, #255 LOOP: CALL DELAY DEC P0 SJMP LOOP DELAY: MOV R1, #100 DELAY1: MOV R2, #100 DELAY2: DJNZ R2, DELAY2 DJNZ R1, DELAY1 RET END I'm probably missing something really obvious here, but can't figure out what. Can anyone explain why my program runs at the same speed with a different crystal. Thanks, Hans |