Content originally posted in LPCWare by tgalluzzo on Fri Jul 01 15:48:31 MST 2011
I'm having trouble getting the open drain function to work for motor control pwm. I need to drive external transistors with a 5V signal instead of 3V, so my plan was to use the motor control pwm with an external 5V pull up resistor. So far I haven't been able to get it working. Is the open drain available for MCPWM? If so, could you please let me know if there is anything obviously wrong with this code. I'm using the functions provided in lpc17xx_mcpwm.h.
const PINSEL_CFG_Type mcpwm_mco0a_pin[1] = {{1, 19, 1, 2, 1}};
const PINSEL_CFG_Type mcpwm_mco0b_pin[1] = {{1, 22, 1, 2, 1}};
int main(void)
{
/* MCPWM INITIALIZATION *******************************************/
/* Initializes pin corresponding to MCPWM function */
PINSEL_ConfigPin((PINSEL_CFG_Type *)&mcpwm_mco0a_pin[0]);
PINSEL_ConfigPin((PINSEL_CFG_Type *)&mcpwm_mco0b_pin[0]);
uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE_OD0 + 1;
debug_printf("PinConVal: %X\n", *pPinCon);
/* Init MCPWM peripheral */
MCPWM_Init(LPC_MCPWM);
/** @brief MCPWM Channel configuration data */
MCPWM_CHANNEL_CFG_Type channelsetup[3];
/* MCPWM Channel 0 setup */
channelsetup[0].channelType = MCPWM_CHANNEL_EDGE_MODE;
channelsetup[0].channelPolarity = MCPWM_CHANNEL_PASSIVE_LO;
channelsetup[0].channelDeadtimeEnable = DISABLE;
channelsetup[0].channelDeadtimeValue = 0;
channelsetup[0].channelUpdateEnable = ENABLE;
channelsetup[0].channelTimercounterValue = 0;
channelsetup[0].channelPeriodValue = 2000;
channelsetup[0].channelPulsewidthValue = 1800;
/* Apply the setup to the channels */
MCPWM_ConfigChannel(LPC_MCPWM, 0, &channelsetup[0]);
/* Enable the MCPWM DC mode and all output pins */
MCPWM_DCMode(LPC_MCPWM, DISABLE, DISABLE, ( 0 ));
/* Disable LIM0 and MAT0 interrupt flag */
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_LIM0, DISABLE);
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_MAT0, DISABLE);
/* Disable LIM1 and MAT1 interrupt flag */
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_LIM1, DISABLE);
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_MAT1, DISABLE);
/* Disable LIM2 and MAT2 interrupt flag */
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_LIM2, DISABLE);
MCPWM_IntConfig(LPC_MCPWM, MCPWM_INTFLAG_MAT2, DISABLE);
/* Start up the MCPWM */
MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE);
// Main loop
while (1)
{
}
return 1;
}