Перейти к содержанию
    

rt595 fusionF1 - не могу запустить ШИМ на МК этом.

Есть отладочная плата RT595, на ней кросс-МК. В части Fusion DSP- F1, не могу запустить ШИМ, чтобы LED светился с частотой заполнения. Вроде уже все переделал и перечитал.

#ifndef CTIMER_MAT_PWM_PERIOD_CHANNEL
#define CTIMER_MAT_PWM_PERIOD_CHANNEL kCTIMER_Match_2
#endif
#define CTIMER_MAT_OUT  kCTIMER_Match_0 /* Match output 0 */


#define IOPCTL_PIO_ANAMUX_DI 0x00u        /*!<@brief Analog mux is disabled */
#define IOPCTL_PIO_FULLDRIVE_DI 0x00u     /*!<@brief Normal drive */
#define IOPCTL_PIO_FUNC1 0x01u            /*!<@brief Selects pin function 1 */
#define IOPCTL_PIO_FUNC4 0x04u            /*!<@brief Selects pin function 4 */
#define IOPCTL_PIO_INBUF_DI 0x00u         /*!<@brief Disable input buffer function */
#define IOPCTL_PIO_INBUF_EN 0x40u         /*!<@brief Enables input buffer function */
#define IOPCTL_PIO_INV_DI 0x00u           /*!<@brief Input function is not inverted */
#define IOPCTL_PIO_PSEDRAIN_DI 0x00u      /*!<@brief Pseudo Output Drain is disabled */
#define IOPCTL_PIO_PULLDOWN_EN 0x00u      /*!<@brief Enable pull-down function */
#define IOPCTL_PIO_PUPD_DI 0x00u          /*!<@brief Disable pull-up / pull-down function */
#define IOPCTL_PIO_SLEW_RATE_NORMAL 0x00u /*!<@brief Normal mode */


// Match Configuration for Channel 0
static ctimer_match_config_t matchConfig0;

static uint8_t dutyCycle        = 60;
volatile uint32_t g_pwmPeriod   = 0U;
volatile uint32_t g_pulsePeriod = 0U;


void BOARD_InitPins(void)
{
    const uint32_t port0_pin14_config = (/* Pin is configured as CTIMER2_MAT0 */
                                         IOPCTL_PIO_FUNC4 |
                                         /* Disable pull-up / pull-down function */
                                         IOPCTL_PIO_PUPD_DI |
                                         /* Enable pull-down function */
                                         IOPCTL_PIO_PULLDOWN_EN |
                                         /* Disable input buffer function */
                                         IOPCTL_PIO_INBUF_DI |
                                         /* Normal mode */
                                         IOPCTL_PIO_SLEW_RATE_NORMAL |
                                         /* Normal drive */
                                         IOPCTL_PIO_FULLDRIVE_DI |
                                         /* Analog mux is disabled */
                                         IOPCTL_PIO_ANAMUX_DI |
                                         /* Pseudo Output Drain is disabled */
                                         IOPCTL_PIO_PSEDRAIN_DI |
                                         /* Input function is not inverted */
                                         IOPCTL_PIO_INV_DI);
    /* PORT0 PIN14 (coords: B12) is configured as CTIMER2_MAT0 */
    IOPCTL_PinMuxSet(IOPCTL, 0U, 14U, port0_pin14_config);
}

status_t CTIMER_GetPwmPeriodValue(uint32_t pwmFreqHz, uint8_t dutyCyclePercent, uint32_t timerClock_Hz)
{
    /* Calculate PWM period match value */
    g_pwmPeriod = (timerClock_Hz / pwmFreqHz) - 1U;

    /* Calculate pulse width match value */
    g_pulsePeriod = (g_pwmPeriod + 1U) * (100 - dutyCyclePercent) / 100;

    return kStatus_Success;
}
status_t CTIMER_UpdatePwmPulsePeriodValue(uint8_t dutyCyclePercent)
{
    /* Calculate pulse width match value */
    g_pulsePeriod = (g_pwmPeriod + 1U) * (100 - dutyCyclePercent) / 100;

    return kStatus_Success;
}

static void timer2_interrupt_handler(void *arg)
{
	//CTIMER_ClearStatusFlags(CTIMER3, kCTIMER_Match3Flag);
	static int tst_cnt = 0;
	tst_cnt++;
	if ((tst_cnt % 1000000) == 0)
		Logger::instance().log("timer3_interrupt_handler %d \r\n", tst_cnt);
}

void Start::init()
{
	// configure CTIMER2
	ctimer_config_t config;

    uint32_t srcClock_Hz; // --
    uint32_t timerClock; // --

    BOARD_InitPins();
    CLOCK_EnableClock(kCLOCK_HsGpio0);

	InterruptManager::instance().enableInterrupt(6, timer2_interrupt_handler);
	INPUTMUX_AttachSignal(INPUTMUX, 1, kINPUTMUX_Ctimer2ToDspInterrupt);

	CLOCK_AttachClk(kMAIN_CLK_to_CTIMER2); // ---
	srcClock_Hz = CLOCK_GetCtimerClkFreq(2);// ----    /* CTimer0 counter uses the AHB clock, some CTimer1 modules use the Aysnc clock */

	CTIMER_GetDefaultConfig(&config);
	timerClock = srcClock_Hz / (config.prescale + 1); // --------
	CTIMER_Init(CTIMER2, &config);

//	matchConfig0.enableCounterReset = true;
//	matchConfig0.enableCounterStop  = false;
//	matchConfig0.matchValue         = CLOCK_GetCtimerClkFreq(3) / 2;
//	matchConfig0.outControl         = kCTIMER_Output_Toggle;
//	matchConfig0.outPinInitState    = false;
//	matchConfig0.enableInterrupt    = true;
//
//	CTIMER_SetupMatch(CTIMER3, kCTIMER_Match_3, &matchConfig0);

    /* Get the PWM period match value and pulse width match value of 2Khz PWM signal */
    CTIMER_GetPwmPeriodValue(2000, dutyCycle, timerClock);
    CTIMER_SetupPwmPeriod(CTIMER2, CTIMER_MAT_PWM_PERIOD_CHANNEL, CTIMER_MAT_OUT, g_pwmPeriod, g_pulsePeriod, true);


	CTIMER_StartTimer(CTIMER2);
}

 

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...