4
\$\begingroup\$

I have a MSP430G2231. My ultimate goal is to communicate with a device that wants 1 bit of data each microsecond. I believe this is too fast for timers, meaning I need to handwrite assembly code that uses correct amount of cycles for timing.

ti.com says the CPU's frequency is 16MHz. The manual says that "call" takes 5 cycles. Does this mean it takes 5/16000000seconds?

To verify this, I tried to make a simple program that's supposed to toggle the LED every second by counting down from 65536 61 times. This should use ~65536*61*4 (about 16 000 000) cycles. Assuming the previous paragraph is correct, that should take 1second, but it takes 12-13 seconds.

hello:
    mov.w #62, r15
    clr.w r14
hello_next:
    dec.w r14      ; 1 cycle
    subc.w #0, r15 ; 1 cycle
    jnz hello_next ; 2 cycle

    xor.b #LED1PIN, &P1OUT
    jmp hello
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

The Family Reference Manual has timing info for various instruction starting on page 63. The number of cycles is not fixed for a certain instruction, it appears to be dependent on the mode used. Here is one of the tables from the manual, you can see most instructions take more than 1 cycle:

MSP430 Instruction timing

I haven't used an MSP4340, but I imagine there should be a tool available in the IDE to time your code and tell you how many cycles it takes to run. I'd try and find/use this first - if you can't, use the info in the manual and calculate manually.

If you tell us more about the device that needs the data (part number, format, etc) then we may be able to suggest alternatives (e.g SPI peripheral?). It sounds like a tall order to achieve this speed using this method, and not particularly efficient if a peripheral/PLD can do it for you.
With the price/capability of uCs nowadays, needing to resort to stuff like this is usually a sign for me that I need to consider moving to a more capable uC (unless the quantities are such that it makes enough of a difference)

\$\endgroup\$
1
  • \$\begingroup\$ Thank you! The problem was that 16MHz is the maximum frequency. The device starts in ~1MHz (I think). When I wrote some magic values to magic registers it worked. The device is a GameCube controller. The communication looks like this picture: int03.co.uk/crema/hardware/gamecube/images/timing.gif With device set to 16MHz I was able to query it. \$\endgroup\$
    – wildnu
    Commented Jul 1, 2013 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.