cancel
Showing results for 
Search instead for 
Did you mean: 

Floating outputs when not connected to PWM Timer 8

Tobe
Senior III

Hi, 

i found out, that the output is floating, when it is not activated to output the PWM signal of timer 8.

 

// **************** PWM *********************
	// PC6-8 (High side)
	// PC10-12 (Low side)
	my_GPIO_InitStruct.Pin = 	GPIO_PIN_6 |
								GPIO_PIN_7 |
								GPIO_PIN_8 |
								GPIO_PIN_9 |	// TODO: debug pin mod: PC9: remove test for tim 8 CCR4 (see other, and change back to EEPROM)
								GPIO_PIN_10 |
								GPIO_PIN_11 |
								GPIO_PIN_12;

	my_GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
	my_GPIO_InitStruct.Pull = GPIO_PULLDOWN;	// Pulldown, to never create an opportunity of shootthrough. Actually not used by timer, directly, but may be used by software (intentionally or accidently).
	my_GPIO_InitStruct.Speed = GPIO_SPEED_LOW; // Low = 270V/us / fast = 570V/us
	HAL_GPIO_Init(GPIOC, &my_GPIO_InitStruct);

	// Alternative function HIGH register
	GPIOC->AFR[0] |= (	GPIO_AFRL_AFSEL6_2 |  	// AF4 (all)
						GPIO_AFRL_AFSEL7_2);
	// Alternative function LOW register
	GPIOC->AFR[1] |= (	GPIO_AFRH_AFSEL8_2 |	// AF4 (all)
						GPIO_AFRH_AFSEL9_2 | 	// TODO: debug pin mod: PC9: remove test for tim 8 CCR4 (see other, and change back to EEPROM)
						GPIO_AFRH_AFSEL10_2 |
						GPIO_AFRH_AFSEL11_2 |
						GPIO_AFRH_AFSEL12_2);

 

 

 

This is the deactivation:

 

CLEAR_BIT(TIM8->CCER, TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E);

 

 

 

Timer init:

 

void initTimer8PWM(){	// BOOKMARK |  initTimer8PWM
	__HAL_RCC_TIM8_CLK_ENABLE();		// Enable clock

	CLEAR_REG(TIM8->AF1);				// Disable BKIN input
	CLEAR_REG(TIM8->AF2);

	SET_BIT(TIM8->CR1, 	TIM_CR1_ARPE | 	// ARR register is bufferd
						TIM_CR1_CMS_1 	// center aligned up/down (Center-aligned mode 2). (interrupt on counting up only - for ADC trigger only?)
						);

	//TODO: check entries again for pwm
	SET_BIT(TIM8->CR2, 	TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0);// tim_oc4refc rising edges generate pulses on tim_trgo2 for ADC trigger
	SET_BIT(TIM8->CR2, 	TIM_CR2_CCUS);			// Update on COM or trigger in

	//TIMx_ARR -1 ist max counter (Counter is counted up and down, so PWM has half the tics)
	WRITE_REG(TIM8->ARR, PWM_HALF_CYCLE_TICS); 	// Counter TOP
	WRITE_REG(TIM8->CCR4, ADC_TRIG_PRE_COUNT);	// compare value 4 (ADC trigger)


	TIM8->PSC = TIM_8_PSC - 1;

//	WRITE_REG(TIM8->CCR1, DUTY_TO_TICS(10));	// compare value 1
//	WRITE_REG(TIM8->CCR2, DUTY_TO_TICS(10));	// compare value 2
//	WRITE_REG(TIM8->CCR3, DUTY_TO_TICS(10));	// compare value 3


	// ***************************************************************
	// ****** ATTENTION! TIM CH 1 is PH 3 and CH 3 is PH 1 !!!  ******
	// ***************************************************************

	SET_BIT(TIM8->CCMR1, 	TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1	| // pwm output compare polarity channel 1 and 2 (pwm mode 1)
							TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 |
							TIM_CCMR1_OC1PE  | TIM_CCMR1_OC2PE); 	// preload enable ccr 1 + 2
	// Default is OUTPUT !!!
	// CC1S = 0 > channel output (CC1 as OUTPUT)

	SET_BIT(TIM8->CCMR2, 	TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1	| // pwm output compare polarity channel 3 and 4 (pwm mode 1)
							TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 |
							TIM_CCMR2_OC3PE  | TIM_CCMR2_OC4PE); 	// preload enable ccr 3 + 4



	// Timer 1 trigger out comes in on itr0 (Only trgo is possible!)
	//TIM8->SMCR itr0 is default 0!


	//TODO: debug remove ?? Really? its current calculation?
	SET_BIT(TIM8->CCER, TIM_CCER_CC4E);		// Enable output

	TIM8->DIER |= TIM_DIER_CC4IE;			// Enable interrupts (from ADC trigger) for kind of sine wave generation
	//TIM8->CR1 |= TIM_CR1_URS;	does it work with update from timer 1?// Only update interrupt on overflow and DMA TODO: does it work with interrupt


	SET_BIT(TIM8->BDTR, TIM_BDTR_OSSR); // inactive state high or low
	CLEAR_BIT(TIM8->CCER, TIM_CCER_CC1P);// oc1 polarity active high
	CLEAR_BIT(TIM8->CCER, TIM_CCER_CC2P);// oc2 polarity active high
	CLEAR_BIT(TIM8->CCER, TIM_CCER_CC3P);// oc3 polarity active high
	// Polarity ONLY for pins, has no effect on trigger lines!!!
}

void startTimer8(){
	__disable_irq();

	SET_BIT(TIM8->EGR , 1);				// Send event, to load all register via Update event (UG)

	SET_BIT(TIM8->CR1, TIM_CR1_CEN); 	// Counter enable
	switchToSectorOFF();				// Dont drive any outputs yet!
	SET_BIT(TIM8->BDTR, TIM_BDTR_MOE); 	// Connect signals to outputs (When CCxE and CCxNE are set - see also OSSR and OSSI)
	WRITE_REG(TIM8->SR, 0); 			// Clear any int flags
	__enable_irq();
}

 

 

I believe this was causing me the headache i had when blowing mosfets and having to change chips.

 

Is there a way to have the output not floating?

0 REPLIES 0