This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CC2430 Timer 3

Hello,

I am using CC2430 TI Chip with Keil compiler.
I am having problem in setting up Timer 3 settings. Going through CC2430.pdf document.
I have below TIMER 3 settings I tried running the code under simulation mode on KEIL compiler.
the program is not breaking for interrupt as counter value is not being incremented. Can anyone look at the settings and let me know where I am going wrong as coounter is not incrementing.

TIMER 3 SETUP :

T3IF = 0
T3IE = 1
T3CTL = 0XFA
T3CC0 = 0XFA
T3CNT = 0X00
T3CCTL0 = 0X4C
T3OVFIF = 0
T3CH0IF = 0
EA = 1

any help would be appreciated....
Thanks in advance...
AD

  • it helps you greatly if you can add comments to your code - in case you want to reuse the code later or to debug it.

    "T3CCTL0 = 0X4C"

    what exactly does that do for you? compare it vs. the datasheet.

  • I deleted comment.... here is the code with comment.... and I had already checked against datasheet.... and aI think I have done correct setting but not sure why its not working... any help on this would be appreciated....

    TIMER 3 SETUP :

    T3IF = 0 //Timer 3 Interrupt Flag (IRCON.T3IF)
    T3IE = 1 // Timer 3 Interrupt Mask ( IEN1.T3IE)
    T3CTL = 0XFA // (i.e DIV = Tick freq/128 , START = 1 , OVFIM = 1, CLR = 0, // MODE = Modulo) - Timer 3 control

    T3CC0 = 0XFA // // Timer 3 Channel 0 Comapre VAlue
    T3CNT = 0X00 // Timer 3 counter
    T3CCTL0 = 0X4C // (i.e IM = 1, CMP = clear output on compare, // MODE = 1 (enable compare mode)) - Timer 3 Channel 0 Compare control

    T3OVFIF = 0 // timer 3 overflow interrupt flag
    T3CH0IF = 0 // Timer 3 channel 0 interrupt flag

    EA = 1 // enable all interrupt

    any help would be appreciated thanks in advance...

  • It also help greatly if you don't use "magic numbers" like 0x4C but, instead, define symbolic names the register bits so that it is obvious what bits you are setting.

    for instance

    #defines OPT_A 0x01  /* Setting bit 0 enables option A */
    #defines OPT_B 0x02  /* Setting bit 1 enables option B */
    #defines OPT_C 0x04  /* Setting bit 2 enables option C */
    #defines OPT_D 0x08  /* Setting bit 3 enables option D */
    #defines OPT_E 0x10  /* Setting bit 4 enables option E */
    #defines OPT_F 0x20  /* Setting bit 5 enables option F */
    #defines OPT_G 0x40  /* Setting bit 6 enables option G */
    #defines OPT_H 0x80  /* Setting bit 7 enables option H */
    
    SOME_SFR = OPT_G | OPT_D | OPT_C;  /* Enable options G, D, and C */
    

    The above is equivalent to writing

    SOME_SFR = 0x4C;
    

    But, hopefully, much clearer?

    Obviously (I hope) you would use more meaningful & descriptive names than OPT_A, etc - they are purely for the sake of a generic example...

  • ... pay attention to instructions: www.danlhenry.com/.../keil_code.png

    "I had already checked against datasheet"

    If your "checking" was as thorough as your attention to those clearly-stated instructions for posting source code, there's a high risk that you missed something important!

  • What I posted is not my original source code. I posted all the Timer/Counter values I read during simulation. Also I did read all the below instruciton reagarding posting the source code.

    Use and for BOLD text.
    Use and for ITALICS text.
    Place source code source code between

     and
    

    .
    Your e-mail address is not published in the forum.

    Also I am following the coding standard as mentioned above. I not using magic numbers in my code.

    I posted this issue here thinking that anyone using Keil compiler and TICC2430 would flash some light on this.
    My problem here is my Counter is not incrementing.
    If anyone could help me on that area it would be greatly appreciated.

    Thanks!!!!

  • I agree with andrew that the use of magic numbers should be avoided, especially when you don't have any comments.

    I usually do this:

    REGISTER_X = (1<<FUNA) |  //enable FUNA
                    (1<<FUNB) |  //enable FUNB
                    (0<<FUNC)    //disable FUNC
                    ;
    

    that way, if I wish to change the settings, I can do so fairly quickly.

    Also, simulation isn't 100% true. so you should always 1) check the compiler / ide manual for limitations of simulation on your particular target; and 2) debug on the real hardware to be sure of a problem.

  • First off, I can really see no single reason why you would erase comments before posting code on this forum.

    Another thing - what was your intention with this comment:

    T3CC0 = 0XFA // // Timer 3 Channel 0 Comapre VAlue
    

    I see 0xFA as timer compare value. But why 0xFA? How did you figure this value should be used? Software comments should focus mostly on "why", while use of well-named constants, function names, variables etc should in most situations be enough to answer "what".

    When playing with timers, it's common to present the evaluation that gives the value that is used - in many cases, this evaluation can even be given directly in the source code, since the compiler can compute constant expressions directly at compile time.

  • Thanks everyone for there suggestion.
    Timer is working fine on Hardware.

    Thanks!
    AD

  • well, lessons learned: simulation isn't always 100% correct.