Open ghost opened 1 year ago
Correct time_meas.h
as below.
/* time_meas.h */
#ifndef IMC_ANALYSIS_TIME_MEAS_H_
#define IMC_ANALYSIS_TIME_MEAS_H_
#include <stdint.h>
#define TA2_CLOCKDIV TIMER_A_CLOCKSOURCE_DIVIDER_64
//! TIMER_A_CLOCKSOURCE_DIVIDER_1
//! TIMER_A_CLOCKSOURCE_DIVIDER_10
//! TIMER_A_CLOCKSOURCE_DIVIDER_64
void timer_init();
void timer_start_count(uint16_t *timer_counter_start);
void timer_end_count(uint16_t *timer_counter_finish);
uint32_t timer_get_cycles(uint16_t cstart, uint16_t cfinish);
#endif /* IMC_ANALYSIS_TIME_MEAS_H_ */
这里的时钟参数设置是不是有问题?
#if WORKING_FREQUENCY_IN_MHZ == 1
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_0); // DCO in 1MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // MCLK = DCO = 1MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // SMCLK = DCO = 1MHz
#elif WORKING_FREQUENCY_IN_MHZ == 2
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3); // DCO in 4MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); // MCLK = DCO/2 = 2MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); // SMCLK = DCO/2 = 2MHz
#elif WORKING_FREQUENCY_IN_MHZ == 4
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3); // DCO in 4MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // MCLK = DCO = 4MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // SMCLK = DCO = 4MHz
#elif WORKING_FREQUENCY_IN_MHZ == 8
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6); // DCO in 8MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // MCLK = DCO = 8MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // SMCLK = DCO = 8MHz
#else
#error "WORKING FREQUENCY ILLEGAL!"
#endif
与下面的设置不一致
void clock_sys_init()
{
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_6); // DCO in 8MHz
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1); // MCLK = DCO = 8MHz
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8); // SMCLK = DCO/8 = 1MHz, x8 divided DCO
CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1);
CS_turnOffLFXT();
}
Boards
The project supports three boards, MSP430FR5994, MSP430FR5969 and MSP430FR2433. Switch to your board from
CCS.Properties_for_project.General.Project.Device.Variant
.Clock
The function
clock_sys_init()
in$/driver/target.c
is used to do initialization for main clock MCLK, second main clock SMCLK and auxiliary clock ACLK. By default, MCLK and SMCLK is driven by internal DCO with variable frequencies and ACLK is driven by internal REFO with frequency 32768Hz.Usually, setting DCO as 1, 2, 4, 8 MHz is preferred. Do not adjust other parameters of the clock unless you fully understand what you are doing. See the following code.
UART
The UART is used for data transmission (interaction) between the MSP430 development board and the host (Windows).
The UART is usually driven with MCLK (don't modify it), so the settings for the UART are relative to the current MCLK frequency. Change code in
$/driver/uart2target.h
to match the configuration of the UART to the MCLK frequency. See code below.Download a serial debugging assistant (see [HERE](https://blog.csdn.net/m0_46563076/article/details/105318326)), set the baud rate to 115200, and keep other configurations as default. Connect the MSP430 development board to the host, and select the corresponding channel (serial port number).
Do not edit
fputc()
andfputs()
functions in$/dirver/uart2target.c
unless you fully understand what you are doing. With these two functions, you can simply callprintf()
to send the required data from the MSP430 development board to the host, and see the data in the serial debugging assistant.TimerA
and time measurementAdd these two files to
$dirver/
.and
Here is a simple usage example.
The TA2 timer is driven by SMCLK.
TA2_CLOCKDIV
determines when the clock passes through how many cycles, the value of the counter of the TA2 timer will increase by 1 (i.e. frequency division).The frequency division reflects the trade-off between timing accuracy and maximum timing. It should be noted that the timer of TA2 is only 16 bits long, that is, the maximum tick can be 65536.
Run function
timer_get_cycles()
to get the actual period elapsed by the clock (32 bits long).