how to set clock frequency in msp430
Hello!
In your code, you don't have any clock set instruction, so the frequency
will be the default (I don't remember if it's ACK or SMCLK, but anyway it will
the clock will have a default value and it will be generated by the internal
DCO). The default frequency is a few 100 kHz.
Now in your code, you have a while loop. Basically it uses 2 instructions in
machine language:
- Invert bit;
- Jump
Each of these will take a few clocks (you can verify in the documentation
how many clocks for each.
For instance, if both instructions take a total of 5 clocks, then the port will
change its state every 5 clocks. Therefore the period of the port signal will
be 10 clocks.
If the default frequency is, say, 600 kHz, then you will get a frequency of
60 kHz. I think it's roughly what you have, and I am not surprised by this value
for the default setting.
But I don't understand what the 9.7 kHz can be. If you use the same loop,
then it means that the CPU runs at a frequency around 100 kHz, so I cannot
tell you if I don't have the exact processor settings.
Dora
Edit after thinking about it: are you sure it's 9.7 k and not 970 hz?
970 Hz would be easily understandable:
- If you set a frequency with the DCO, it's never accurate, so 16 k may be
14 or even less
- Assuming that the 2 instructions XOR and jump take for instance a total
of 7 or 8 clocks for the whole loop, which would mean 14 ~ 16 clocks for one
P1.0 period. If you start with 16 K, you would get something close to 1000 Hz.
beaver said:
hi guys,
i wrote the following code:
//*************************************
#include <msp430x14x.h>
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0x01;
P1OUT=0;
while (1)
{
P1OUT^=BIT0;
}
return 0;
}
//**************************************
why the frequency of the square wave from P1.0 is 66K? does it operate by aclk which is 32k? when i changed aclk to 16k,however, the frenquency of that wave became 9.7k. can anybody tell me why and how to set that frequency to a desired one? thanks in advance.