/**
 * \brief ILI9488 Hardware Initialization for SPI/SMC LCD.
 */
static void _ILI9488_Spi_HW_Initialize(void)
{
	/* Pin configurations */
	PIO_Configure(&lcd_spi_reset_pin, 1);
	PIO_Configure(&lcd_spi_cds_pin, 1);
	PIO_Configure(lcd_pins, PIO_LISTSIZE(lcd_pins));
	PIO_Configure(&lcd_spi_pwm_pin, 1);

	/* Enable PWM peripheral clock */
	PMC_EnablePeripheral(ID_PWM0);
	PMC_EnablePeripheral(ID_SPI0);
	/* Set clock A and clock B */
	// set for 14.11 KHz for CABC control
	//mode = PWM_CLK_PREB(0x0A) | (PWM_CLK_DIVB(110)) |
	//PWM_CLK_PREA(0x0A) | (PWM_CLK_DIVA(110));
	PWMC_ConfigureClocks(PWM0, 14200, 0,  BOARD_MCK);

	/* Configure PWM channel 1 for LED0  */
	PWMC_DisableChannel(PWM0, CHANNEL_PWM_LCD);

	PWMC_ConfigureChannel(PWM0, CHANNEL_PWM_LCD, PWM_CMR_CPRE_CLKA, 0,
						  PWM_CMR_CPOL);
	PWMC_SetPeriod(PWM0, CHANNEL_PWM_LCD, 16);
	PWMC_SetDutyCycle(PWM0, CHANNEL_PWM_LCD, 8);
	PWMC_EnableChannel(PWM0, CHANNEL_PWM_LCD);

	SPI_Configure(ILI9488_SPI, ID_SPI0, (SPI_MR_MSTR | SPI_MR_MODFDIS
										 | SPI_PCS(SMC_EBI_LCD_CS)));
	SPI_ConfigureNPCS(ILI9488_SPI,
					  SMC_EBI_LCD_CS,
					  SPI_CSR_CPOL | SPI_CSR_BITS_8_BIT | SPI_DLYBS(6, BOARD_MCK)
					  | SPI_DLYBCT(100, BOARD_MCK) | SPI_SCBR(20000000, BOARD_MCK));
	SPI_Enable(ILI9488_SPI);
}
Exemple #2
0
static void ILI9488_InitInterface(void)
{

    PIO_Configure(ILI9488_Reset, PIO_LISTSIZE(ILI9488_Reset));    
    PIO_Configure(spi_pins, PIO_LISTSIZE(spi_pins));


    PIO_Configure(ILI9488_Pwm, PIO_LISTSIZE(ILI9488_Pwm));
    /* Enable PWM peripheral clock */
    PMC_EnablePeripheral(ID_PWM0);

    /* Set clock A and clock B */
    // set for 14.11 KHz for CABC control
    //    mode = PWM_CLK_PREB(0x0A) | (PWM_CLK_DIVB(110)) | 
    //           PWM_CLK_PREA(0x0A) | (PWM_CLK_DIVA(110));
    PWMC_ConfigureClocks(PWM0, 14200, 0,  BOARD_MCK);

    /* Configure PWM channel 1 for LED0  */
    PWMC_DisableChannel(PWM0, CHANNEL_PWM_LCD);

    PWMC_ConfigureChannel(PWM0, CHANNEL_PWM_LCD, PWM_CMR_CPRE_CLKA,0,PWM_CMR_CPOL);
    PWMC_SetPeriod(PWM0, CHANNEL_PWM_LCD, 16);
    PWMC_SetDutyCycle(PWM0, CHANNEL_PWM_LCD, 8);
    PWMC_EnableChannel(PWM0, CHANNEL_PWM_LCD);

    SPI_Configure(ILI9488, ILI9488_ID, (SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS( ILI9488_cs )));
    SPI_ConfigureNPCS( ILI9488, ILI9488_cs, 
            SPI_CSR_CPOL | SPI_CSR_BITS_9_BIT | 
            SPI_DLYBS(100, BOARD_MCK) | SPI_DLYBCT(100, BOARD_MCK) |
            SPI_SCBR( 35000000, BOARD_MCK) ) ;  

    SPI_Enable(ILI9488);

}
Exemple #3
0
void dc_update_pwm_frequency(void) {
	// Calculate best possible frequency
	uint8_t cmr_cpre;
	for(cmr_cpre = 0; cmr_cpre < DC_NUM_PWM_FREQUENCIES; cmr_cpre++) {
		uint32_t frequency = (BOARD_MCK/(1 << cmr_cpre));

		if(dc_pwm_frequency > frequency/0xFFFF) {
			dc_pwm_scale_value = frequency/dc_pwm_frequency;
			break;
		}
	}

	// Set PWM frequency according to PWM mode (drive/brake vs drive/coast)
	if(dc_mode == DC_MODE_DRIVE_BRAKE) {
		PWMC_DisableChannel(PWM, INPUT1_CHANNEL);
		PWMC_DisableChannel(PWM, INPUT2_CHANNEL);

		PWMC_ConfigureChannel(PWM, INPUT1_CHANNEL, cmr_cpre, 0, 0);
		PWMC_SetPeriod(PWM, INPUT1_CHANNEL, dc_pwm_scale_value);

		PWMC_ConfigureChannel(PWM, INPUT2_CHANNEL, cmr_cpre, 0, 0);
		PWMC_SetPeriod(PWM, INPUT2_CHANNEL, dc_pwm_scale_value);

		PWMC_EnableChannel(PWM, INPUT1_CHANNEL);
		PWMC_EnableChannel(PWM, INPUT2_CHANNEL);

		dc_velocity_to_pwm();
	} else {
		PWMC_DisableChannel(PWM, DISABLE1_CHANNEL);
		PWMC_ConfigureChannel(PWM, DISABLE1_CHANNEL, cmr_cpre, 0, 0);
		PWMC_SetPeriod(PWM, DISABLE1_CHANNEL, dc_pwm_scale_value);

		PWMC_EnableChannel(PWM, DISABLE1_CHANNEL);
		dc_velocity_to_pwm();
	}
}
/*------------------------------------------------------------------------------
Name:           configurePWMC
parameters:     -
description:    initializes the PWM controller
------------------------------------------------------------------------------*/
void BldcControl::configurePWMC(void)
{
    uint32_t clka = 0; /* clock A not used */
    uint32_t clkb = 0; /* clock B not used */
    uint32_t mck = MCK_CLOCK_42MHZ;
    uint16_t duty = 0;
    uint16_t deadTime;
    
    pwmPeriod = MCK_CLOCK_42MHZ / this->periphery->Pwm.pwmSwFrq;
    
    deadTime = (uint16_t)(pwmPeriod * (DEAD_TIME * this->periphery->Pwm.pwmSwFrq * 2));

    /* disable all 3 channels */
    PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChU);
    PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChV);
    PWMC_DisableChannel(PWM, this->periphery->Pwm.pwmChW);

    PWMC_ConfigureClocks(clka, clkb, mck);

    /* initialize all 3 channels */
    PWMC_ConfigureChannelExt(PWM,
                          this->periphery->Pwm.pwmChU, /* channel ID */
                          PWM_CMR_CPRE_MCK, /* use main clock */
                          PWM_CMR_CALG, /* center alligned */
                          0, /* polarity low level */
                          0, /* event counter = 0 */
                          PWM_CMR_DTE, /* enable dead time */
                          0,  /* no inversion of dead time H */
                          0); /* no inversion of dead time L */
    PWMC_ConfigureChannelExt(PWM,
                          this->periphery->Pwm.pwmChV, /* channel ID */
                          PWM_CMR_CPRE_MCK,
                          PWM_CMR_CALG, /* center alligned */
                          0, /* polarity low level */
                          0, /* event counter = 0 */
                          PWM_CMR_DTE, /* enable dead time */
                          0,  /* no inversion of dead time H */
                          0); /* no inversion of dead time L */
    PWMC_ConfigureChannelExt(PWM,
                          this->periphery->Pwm.pwmChW, /* channel ID */
                          PWM_CMR_CPRE_MCK,
                          PWM_CMR_CALG, /* center alligned */
                          0, /* polarity low level */
                          0, /* event counter = 0 */
                          PWM_CMR_DTE, /* enable dead time */
                          0,  /* no inversion of dead time H */
                          0); /* no inversion of dead time L */
                             
    PWMC_ConfigureSyncChannel(PWM,
                              PWM_SCM_SYNC0|PWM_SCM_SYNC1|PWM_SCM_SYNC2,
                              PWM_SCM_UPDM_MODE0,
                              PWM_SCM_PTRM,
                              PWM_SCM_PTRCS(0)) ;

    /* set periods */
    PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChU, pwmPeriod);
    PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChV, pwmPeriod);
    PWMC_SetPeriod(PWM, this->periphery->Pwm.pwmChW, pwmPeriod);

    /* set duty cycles */
    PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChU, duty);
    PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChV, duty);
    PWMC_SetDutyCycle(PWM, this->periphery->Pwm.pwmChW, duty);

    /* set dead times */
    PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChU, deadTime, deadTime);
    PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChV, deadTime, deadTime);
    PWMC_SetDeadTime(PWM, this->periphery->Pwm.pwmChW, deadTime, deadTime);

    /* set overwrites to 0 */
    PWMC_SetOverrideValue(PWM, 0);

    /* set event for ADC trigger */
    PWM->PWM_CMP[this->periphery->Pwm.pwmChU].PWM_CMPM |= PWM_CMPM_CEN | /* enable */
                                           PWM_CMPM_CTR(0) | /* each period */
                                           PWM_CMPM_CPR(0);
    PWM->PWM_CMP[this->periphery->Pwm.pwmChU].PWM_CMPV = pwmPeriod/2; /* set trigger */
    PWM->PWM_ELMR[0] |= PWM_ELMR_CSEL0; /* enable event line 0 */

}