Hello I tried to convert a simple example for MikroBasic for 8051 v2.20 to have it working for Silabs C8051F020, actually it works but the problem is the timing the built in delay function below:
Delay_ms(1000) ' 1 second delay
gives me around 12seconds delay instead of 1 second delay.
Actually I already change the type of MCU and the Frequency in the project setting to the appropriate value which is used for my hardware which is C8051F020 and 22.1184MHz.
Please advise how to correct this problem, see my code below:
program LED_Blinking
main:
WDTCN = 0xDE ' Sequence for
WDTCN = 0xAD ' disabling the watchdog timer
P5 = 0x0F
P74OUT = 0x08
OSCXCN = 0xF7
while TRUE
P5 = 0x00 ' Turn ON diodes on PORT1
Delay_ms(1000) ' 1 second delay
P5 = 0xFF ' Turn OFF diodes on PORT1
Delay_ms(1000) ' 1 second delay
wend ' Endless loop
end.
MikroBasic for 8051 v2.20 timing problem using silabs 8051
Hi,
The problem here is that your microcontroller is set to use internal 2MHz oscillator by default, and this hasn't been changed in the course of initialization. If you take a look at c8051F020 datasheet: http://www.keil.com/dd/docs/datashts/si ... 51f02x.pdf in section 14 default on-reset value of OSCICN is 00010100 which implies that internal oscillator is default and set to ON when the chip is reset. This is why your Delay on ~24MHz frequency runs 12 times slower, because the frequency is 12 times lower then one used in delay calculations. So, to use the external oscillator, you must set OSCICN.CLKSL = 1. Also, for greater stability, you should consider the following procedure described in the datasheet:
Delay function calculates the right values according to the frequency you have set in the appropriate IDE oscillator option. So, whatever real frequency is set after changes to OSCXCN and OSCICN, you should set that frequency as the reference for compiler.
Best regards,
Aleksandar
The problem here is that your microcontroller is set to use internal 2MHz oscillator by default, and this hasn't been changed in the course of initialization. If you take a look at c8051F020 datasheet: http://www.keil.com/dd/docs/datashts/si ... 51f02x.pdf in section 14 default on-reset value of OSCICN is 00010100 which implies that internal oscillator is default and set to ON when the chip is reset. This is why your Delay on ~24MHz frequency runs 12 times slower, because the frequency is 12 times lower then one used in delay calculations. So, to use the external oscillator, you must set OSCICN.CLKSL = 1. Also, for greater stability, you should consider the following procedure described in the datasheet:
Code: Select all
Step 1. Enable the external oscillator.
Step 2. Wait at least 1 ms.
Step 3. Poll for XTLVLD => ‘1’.
Step 4. Switch the system clock to the external oscillator.
Best regards,
Aleksandar
Web Department Manager