Timers and Interrupts silicon lab c8051f

Discussion in 'Embedded Systems and Microcontrollers' started by antiantianti, May 22, 2017.

  1. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    Hi
    I have a problem understanding what this actually means

    Code (C):
    1.   TMOD = 0x20;              
    2.     CKCON = 0x02;                //System Clock divided by 48   what does this mean
    3.     TH1 = 0x01;                //Auto reload every 0,254 ms
    4.     TL1 = 0x01;                
    every 5ms must a computation get done . how does the timer does this when it is equal to 1
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    3,323
    1,667
    How about giving us the COMPLETE part number of the chip? Silicon labs has dozens of C8051F variants. I looked at a couple of them and your code does not make any sense for those parts.

    For example, TMOD=20h sets timer 1 to 8 bits auto reload so I don't know why you would write it as if it were 16 bits. The bits you are changing in CKCON are marked 'reserved' in the datasheet I looked at.
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,388
    692
    1. Mode 2 of Timer 1 is selected.
    2. Don't know.
    3. Timer 1 High 4 bits contain 0001.
    4. Timer 1 Low 4 bits contain 0001
     
  4. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    SORRY C8051F340
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    3,323
    1,667
    OK, Timer 1 is running in the 8 bit auto-reload mode i.e. TL1 counts up until it rolls over then it automatically reloads to the value in TH1. The init/reload value is 0x1 so it counts 255 timer input clocks between rollovers. The value of CKCON applies a 48x prescaler to the timer input. Assuming this is a USB setup (implied by the /48 and the comments), the oscillator looks like it is 48MHz. After the prescalar /48 that gives 1MHz = 1usec timer count period. Presetting/reloading the timer to 1 counts 255 until rollover for a timer period of 255usec (I don't think 254us is correct but it has been awhile since I messed with 8051).

    All of this implies that the code is using the timer as a system tik. It is not shown but it probably interrupts the processor every 255us and does some function from there.

    That's about all I can get from 4 instructions.
     
Loading...