This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Delay Calculation For 5 secs

Other Parts Discussed in Thread: MSP430F2274

Hi ,

      I  want to generate a hardware delay using Timer , I want to know the calculation for loading the Value into  TACCRO register

      it also good if any body can help me by telling the Software delay calculation  please help me

     I know for Software calculation it is (# of Delays ) * ( CPU speed) but this didnt work out for me ,  I feel some more modifications need to be done

   ( is 62.5 ns / Instruction Cycle  correct for MSP430F2274 )  any body  who made a suCcess in this please post an example with a small explanation

    Thanks in Advance.

  • (Time elaps) = (# of cycles) / (frequency)

    For example: You have ACLK=32768Hz and use ACLK/8=4096Hz to clock TimerA. You can set CCR0 to 5*4096-1=20479 and use count up mode. It will overflow in 20480 cycles which takes 5sec.

    Another example is for CPU.  Instructions like NOP take 1 cycle to execute, thus it takes 62.5ns if MCLK is at 16MHz. There are other instructions that takes more cycles, and MCLK is not always 16MHz.

    "Instructions" in c take anywhere from 0 to infinite # of cycles (of MCLK) to execute.

  • Hi SHRIK,

    there is an instrinsic C function which calls __delay_cycles.

    The __delay_cycles inserts code to consume precisely the number of specified clock cycles with not side effects. The number of clock cycles delayed must be a compile-time constant, so you will use this instrinsic like:

    __delay_cycles (1000); // delay program execution for 1000 cycles 

    For your example it would look like: __delay_cycles(80000000);

    Well, maybe it is better to use OCY's approach and do it with a timer (if you have one for spare).
    Rgds
    aBUGSworstnightmare 

  • ThanQ  Old Cow Yellow,

                                                 I will check your solution and the Above calculations are for Hardware delay right ?

  • Hi  aBugs,

                        the Approach suggested by u is already used by me but   how much value to be used in that function like say 1000 ,2000, or 80000 and it also depends on clock im using so If u can detail me with small example it would be really gr8 thanx in advance

  • Hi SRIHK,

    the instrinsic function speeks for itself. I consumes exactely the ammount of MCU clock cyles (MCLK) you specify in parentheses

    So, the delay time for the instrinsic calculates as follows:  required delay / instruction cyle time = value (in parentheses).

    I.e.

    MCU clock MCLK = 16MHz --> instruction cycle time = 62.5ns (= 1/MCLK)
    Required delay = 5s

    --> 5s/62.5ns = 80000000

    Rgds
    aBUGSworstnightmare 

     

  • Dear all ,

    I want to generate a interrupt after two hours

    Is this possible using MSP 430 ?

     

    bcoz from the above conversation , I understand it as  value to be put in for loop or delay function is the number of cycles CPU takes .

    So for 2 hours the value comes as 72 000 000 00 ,  using a 1MHz  SMCLK . Can I use this method ?

     

    Thanks a lot in advance

     

     

  • The timer is 16 bits long, so the maximum value for the CCR is 65535.

    If the value is greater you have to made a software management.

     

     

     

  • Hi volatile_solid,

    for such a long delay I would recommend using a RTC (real time clock). TI has an application note here (http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=slaa290) which can be used with all MSP430 derivative.

    Another possible solution could be unsig the WDT in interval mode (because you lnow how long it takes untill you get an interrupt) and increment (or cecrement) a static variabel to the value equivalent for around 2 hours.

    If the part you're using has a RTC module I would recommend using this (instead of the library mentioned above).

    Rgds
    aBUGSworstnightmare

  • Hi aBUGSworstnightmare ,

    Thanks a lot for ur reply .

    I am using eZ430-RF2500 evaluation kit and it has msp430-F2274 in it . How do i know whether it has RTC module or not ??

     

    I am using CCE v3 for compiling ,and I   tried to include rtc.h as header file , but as we guessed it doesnt have that header file  so i downloaded the header files and included them into CCE and now it says header file is included .

     

    But I didnt understand how this works , So you are suggesting me to set up this clock and compare the clock value continously so as to read a period of 2 hours ??

     

    can you please elaborate ,how can I set use this ? I have to send 3 interrupts ,each of diff time periods around 4 hours ,6 hours , 8 hours  periods . If i get to know any one of them at least , I guess i can manipulate the same for others .

     

    thanks in advance

     

  • Hi,

    the MSP430F2274 doesn't has a RTC peripheral (pls refer to the device user manual and data sheet for details: http://focus.ti.com/docs/prod/folders/print/msp430f2274.html).

    The dcumentation of the library has all information you need to setup and use it. You can find it under http://focus.ti.com/general/docs/litabsmultiplefilelist.tsp?literatureNumber=slaa290).

    Yeap! You can use it as your alarm clock in the morning! Initialize time and the compare the actual value with a preset value (your 2 hours later, 6hours later or whatever). When both values match you can do what you want (ring the alarm).

    Kind regards
    aBUGSworstnightmare

  •  

    ya  I got it know

     

    But , as u mentioned MSP 430-F2274 doesnt have a RTC peripheral ,Will I still be able to use RTC.h header file and measure the times in software so that  once the timer values match ,Can I generate an interrupt on any other GPIO pin ??

    Thanks a ton

  • Hi,

    the INTENTION of this library is that you can have a real time clock on devices WITHOUT a RTC peripheral! So, you can for shure use this lib and generate an interrupt once time matches with your predefined value.

    Rgds
    aBUGSworstnightmare

  • The whole calculation depends on your setup.

    62.5ns/instruction cycle is only correct if your 2274 runs at 16Mhz. But if you use TACCR0, this is independent from instruction cycles (at least mostly). It all depends on how you set up your system clock module.

    e.g. if you use a 16MHz crystal and set MCLK=XT1, you can set up SMCLK to XT1/16 resulting in a 1MHz clock source for the timer. Set the timer to SMCLK source and it will count 1 per µs. Then the timer will overflow each 65.536 ms, issuing an interrupt.

    The setup I usually use is to set up TimerA as above and configure TACCR1 to TAR+1000. This means, that a CCRA1 interrupt is issued every ms. In the ISR I increase a millisecond timer counter and add 1000 to the content of TACCR1, which will raise another IRQ 1ms after the last (no matter how many clock cycles have passed since the last, as long as it ia below 1ms).

    This way, I can do a software wait for up to 65 seconds (I use a 16 bit ms counter).

    It is also possible to preload a delay variable with the number of milliseconds to wait and then go into LPM. The TACCR1 ISR will decrement this variable and when it reaches 0, it will exit LPM and the program continues.

    There are many variants possible with this setup. Having a timer running at 1MHz allows from exact delays of few microseconds (e.g. by setting TACCR2 to TAR+X) up to over a minute.

  • okie sir

    thanks for help .

     

    So  the info I understood till now is :

    1) I can include RTC library to my MSP430-F2274 file setup under include section in CCE and start the real-time clock on system to make use of  variables  like TI_hour to  send  out an interrupt on a GPIO 

    2) The problem is :

             I downloaded  slaa290.zip and slaa290.pdf given in the RTC link provided above and included  RTC.h from CCE headers  folder into CCE ,and tried to use the variables as mentioned above in my own code .But ,I am getting linking error .

    This is all I have done till now ,So some one please help me out in setting up RTC on my MSP430-F2274  .

     

     

     

     

    Thanks in advance

     

  • Including a .h file into a project just tells the compiler that somewhere is something of this and that name and type.

    It does NOT add these somethings to the project. The compiler just knows what kind of reference to generate when you refer to them, but it does not generate them, as there is no code for doing so. And when the linker tries to resolve these references later, it won't find the tagets.

    You can compare it with the 'sender' field in an email you got. It tells your email program where to send your reply to, but that doesn't mean that this address really exists.

    You'll need to add the library code itself to the project too, so it is either freshly compiled (if .c files are available) or just linked in (from a library file that comes with the header files). In any case you'll need to tell the linker that there is more than just your own code belonging to the project.

  • Hi Jens-Michael ,

    Thanks a lot for ur reply

    Lots of doubts has been clarified by your previous reply ,

    But can you please suggest me which is the library code for CCEv3 in that slaa290.zip ,that is available on TI website for downloads as RTC library associated files .

    Please let me know about the process because, I am very new to this software !! or in fact this type of work

  • The ZIp file contains a folder source_CCE. There are the actual code files for the RTC 'library'. Whil it is a real library in IAR, CCE requires that you include these files into your project. Don't ask me how, as I'm neither using IAR nor CCE (I'm mspgcc user). Somewhere in the project settings or so you'll have to add the files as additional (assembly) source files.

    However, the documentation http://focus.ti.com/lit/an/slaa290/slaa290.pdf tells on page 5 which of the files you'll need for a certain functionality.

  • ya Thanks a lott

     

    actually i was seearching for library files similar to that of IAR , but now it is fine .

     

    I got it ...

    Thanks a ton for ur help and patience !!!

     

     

**Attention** This is a public forum