def run(): roboveroConfig() MCPWM_Init(LPC_MCPWM) channelsetup = MCPWM_CHANNEL_CFG_Type() channelsetup.channelType = MCPWM_CHANNEL_EDGE_MODE channelsetup.channelPolarity = MCPWM_CHANNEL_PASSIVE_HI channelsetup.channelDeadtimeEnable = DISABLE channelsetup.channelDeadtimeValue = 0 channelsetup.channelUpdateEnable = ENABLE channelsetup.channelTimercounterValue = 0 channelsetup.channelPeriodValue = periodValue channelsetup.channelPulsewidthValue = 0 MCPWM_ConfigChannel(LPC_MCPWM, 0, channelsetup.ptr) # Disable DC Mode MCPWM_DCMode(LPC_MCPWM, DISABLE, ENABLE, (0)) # Disable AC Mode MCPWM_ACMode(LPC_MCPWM, DISABLE) MCPWM_Start(LPC_MCPWM, ENABLE, DISABLE, DISABLE) try: while True: channelsetup.channelPulsewidthValue = getMotorSpeed() MCPWM_WriteToShadow(LPC_MCPWM, 0, channelsetup.ptr) except: MCPWM_Stop(LPC_MCPWM, ENABLE, DISABLE, DISABLE) print "you broke it"
return match_value roboveroConfig() MCPWM_Init(LPC_MCPWM) channelsetup = MCPWM_CHANNEL_CFG_Type() channelsetup.channelType = MCPWM_CHANNEL_EDGE_MODE channelsetup.channelPolarity = MCPWM_CHANNEL_PASSIVE_HI channelsetup.channelDeadtimeEnable = DISABLE channelsetup.channelDeadtimeValue = 0 channelsetup.channelUpdateEnable = ENABLE channelsetup.channelTimercounterValue = 0 channelsetup.channelPeriodValue = periodValue channelsetup.channelPulsewidthValue = 0 # Disable DC Mode MCPWM_DCMode(LPC_MCPWM, DISABLE, DISABLE, (0)) # Disable AC Mode MCPWM_ACMode(LPC_MCPWM, DISABLE) for i in xrange(0,6): MCPWM_ConfigChannel(LPC_MCPWM, i, channelsetup.ptr) MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE) try: while True: chan = int(raw_input("Pick a channel: "))
roboveroConfig() MCPWM_Init(LPC_MCPWM) channelsetup = MCPWM_CHANNEL_CFG_Type() channelsetup.channelType = MCPWM_CHANNEL_EDGE_MODE channelsetup.channelPolarity = MCPWM_CHANNEL_PASSIVE_HI channelsetup.channelDeadtimeEnable = DISABLE channelsetup.channelDeadtimeValue = 0 channelsetup.channelUpdateEnable = ENABLE channelsetup.channelTimercounterValue = 0 channelsetup.channelPeriodValue = periodValue channelsetup.channelPulsewidthValue = 0 MCPWM_ConfigChannel(LPC_MCPWM, 0, channelsetup.ptr) # Disable DC Mode MCPWM_DCMode(LPC_MCPWM, DISABLE, ENABLE, (0)) # Disable AC Mode MCPWM_ACMode(LPC_MCPWM, DISABLE) MCPWM_Start(LPC_MCPWM, ENABLE, DISABLE, DISABLE) try: while True: channelsetup.channelPulsewidthValue = getMotorSpeed() MCPWM_WriteToShadow(LPC_MCPWM, 0, channelsetup.ptr)
#Channel setup is needed for the proper setup of MCPWM periodValue = 600000 ENABLE = FunctionalState.ENABLE DISABLE = FunctionalState.DISABLE channelsetup = MCPWM_CHANNEL_CFG_Type() channelsetup.channelType = MCPWM_CHANNEL_EDGE_MODE channelsetup.channelPolarity = MCPWM_CHANNEL_PASSIVE_HI channelsetup.channelDeadtimeEnable = DISABLE channelsetup.channelDeadtimeValue = 0 channelsetup.channelUpdateEnable = ENABLE channelsetup.channelTimercounterValue = 0 channelsetup.channelPeriodValue = periodValue channelsetup.channelPulsewidthValue = 0 def initPulse(channel, pulse_width): initMatch(channel, pulse_width) def initPeriod(period): initMatch(0, period) def initPWM(): #Initializes both the MCPWM and the regular PWM MCPWM_DCMode(LPC_MCPWM, DISABLE, DISABLE, (0)) MCPWM_ACMode(LPC_MCPWM, DISABLE) MCPWM_Start(LPC_MCPWM, ENABLE, ENABLE, ENABLE) #Start all three channels, even if we're not using them I guess initPeriod(20000) PWM_ResetCounter(LPC_PWM1) PWM_CounterCmd(LPC_PWM1, ENABLE)