I have a somewhat silly question… I have read through the manuals and user guides but I have failed to come up with any answers.
How fast can I switch the output ports? My MSP is running with a 8 MHz crystal. I know that it will depend on the load of the ports etc, but I have not found any documentation that will tell how fast I can eg toggle P1.0.
I want to control a multiplexer and I need to toggle the control pins of multiplexer.
I’m using IAR Embedded Workbench and writing in C.
First, you have to set up that Port pin as an output pin. For example, to set up Port-x, Pin-y, you do:
bis.b #BITy, &PxDIR
Next, if you are going to use CPU to set/reset that pin directly, you need to make sure that this pin is not used by a peripheral. You can do this with:
bic.b #BITy,&PxSEL
After that, you can set/reset that pin as fast as the CPU can execute the code. For example the loop below can toggle that pin every 6 or 7 cycles or MCLK (i.e., every 6/8 or 7/8 microseconds if you use 8MHz).
Loop:
xor.b #BITy,&PxOUT
jmp Loop
This is because the xor.b instruction takes either 4 cycles (if y=0,1,2 or 3) or 5 cycles (if y=4,5,6 or 7) while the jmp instruction takes 2 cycles.
Instead of using the CPU, some of the I/O pins can also be controlled by Timer or other peripherals. For example, Timer could toggle some of the pins every cycle (i.e., every 1/8 microseconds if you use 8MHz) or generate PWM waveform. I2C and SPI could set/reset some other pins for multiplexing data direction automatically.