STM32 PWM problemHow do I select what values to load in CCPR1L register (for generating PWM signal with...

Is opening a file faster than reading variable content?

Ramanujan's radical and how we define an infinite nested radical

Sauna: Wood does not feel so hot

How do I add a strong "onion flavor" to the biryani (in restaurant style)?

How can I portray body horror and still be sensitive to people with disabilities?

Isn't a semicolon (';') needed after a function declaration in C++?

Will linear voltage regulator step up current?

What did Putin say about a US deep state in his state-of-the-nation speech; what has he said in the past?

What happens if you declare more than $10,000 at the US border?

How to scroll to next div using Javascript?

Which was the first story to feature space elevators?

How bad is a Computer Science course that doesn't teach Design Patterns?

Rudeness by being polite

What is formjacking?

Why are `&array` and `array` pointing to the same address?

How do I write a maintainable, fast, compile-time bit-mask in C++?

Can I legally make a website about boycotting a certain company?

What if you do not believe in the project benefits?

Is there a way to pause a running process on Linux systems and resume later?

Why don't reads from /dev/zero count as I/O?

How can changes in personality/values of a person who turned into a vampire be explained?

Are encryption algorithms with fixed-point free permutations inherently flawed?

multiple null checks in Java8

Is Screenshot Time-tracking Common?



STM32 PWM problem


How do I select what values to load in CCPR1L register (for generating PWM signal with PIC)?Shifting between PWM optionsSTM32 Series Microcontroller - Calculations of Timer VariablesAvr multiple ADC and PWM channelsCan't understand a variable in the formula used to determine CDTY to set duty cycle of PWM on cortex M3 (SAM3X8E)Is it possible to achieve 0% to 100% PWM duty cycle with AT90PWM3B?STM32 PWM output frequency is offEverything stops working after I enable PWMNot sure how to go from PID error to PWM dutySTM32 HAL PWM output with DMA misbehavior













4












$begingroup$


Using a STM32F407 board. I want to generate a PWM signal. I have the following function:



/**
* brief Sets the CCR timer register. The register determines the duty cyle.
* param ChannelNumber: channel index from channels configuration array.
* param DutyCycle: value that represents the duty cycle of PWM signal. Can take values between 0x00 and 0x8000.
* return -
*/
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
{
uint32 ul_ARR = Pwm_pt_GroupsConfig[ChannelNumber].pt_Register->ARR;

DutyCycle = ((DutyCycle * ul_ARR) >> 15U) ;

*Pwm_pt_GroupsConfig[ChannelNumber].pt_DutyCycleRegister = DutyCycle;

}


When I call the function with a value between 0x0000 and 0x8000, for example 0x4000, I have 50 % duty cycle:
enter image description here



For 0x8000 I get 100 % duty cycle.
All good.



enter image description here



If I want 0 % duty cycle : 0x0000



enter image description here



When DutyCycleRegister is set to 0x00 seems that the PWM pin is floating or compare unit is inactive, not pulled to ground.
Does anyone know what is going on ?



If I modify the PWM function like this and not allow the DutyCycle to take 0 value.



DutyCycle = ((DutyCycle * ul_ARR) >> 15U) +1;


At 0x0000:
enter image description here
The configuration array:



    /** brief Register configuration array */
static const RegInit_Masked32BitsSingleType Pwm_kat_Registers[PWM_NUMBER_OF_REGISTERS] =
{

/* TIMER 2 CONFIGURATION */

/**
* Configuration of TIM2_CR1 register
* - Set the counting direction as 'upcounter'
* 0: Upcounter
* 1: Downcounter
*
*/

{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_DIR),

(uint32) (0x00)
},

/**
* Configuration of TIM2_EGR register
* - Set update generation to restart the counter after it has reached its peak value.
* 0: No action
* 1: Re-initialize the counter
*
*
*/

{
(volatile uint32*) &TIM2->EGR,

(uint32) ~(TIM_EGR_UG),

(uint32) (TIM_EGR_UG)
},

/**
* Configuration of TIM2_PSC register
* - Set prescaler value to 0.
* Range: 0 to 0xFFFF
* Divided clock frequency: fCK_PSC / (PSC[15:0] + 1).
*
*
*/

{
(volatile uint32*) &TIM2->PSC,

(uint32) ~(TIM_PSC_PSC),

(uint32) (0x00)
},

/**
* Configuration of TIM2_ARR register
* - Set auto-reload value to 0xFA0.
*
*
*/
{
(volatile uint32*) &TIM2->ARR,

(uint32) ~(TIM_ARR_PRELOAD),

(uint32) (TIM_ARR_FREQUENCY)
},

/**
* Configuration of TIM2_CR1 register
* - Set the counter enable register to 1
* 0: Counter disabled
* 1: Counter enabled
*
*/
{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_CEN),

(uint32) (TIM_CR1_CEN)
},

/**
* Configuration of TIM2_CCMR1 register
* - Set the PWM mode 1
* 110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
* else inactive. In downcounting, channel 1 is inactive (OC1REF=‘0’) as long as
* TIMx_CNT>TIMx_CCR1 else active (OC1REF=’1’).
* 111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1
* else active. In downcounting, channel 1 is active as long as TIMx_CNT>TIMx_CCR1 else
* inactive.
*
*/
{
(volatile uint32*) &TIM2->CCMR1,

(uint32) ~(
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1),

(uint32) (
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1)
},

/**
* Configuration of TIM2_CCER register
* - Set capture/compare enable register. Enable CC2E: Capture/Compare 2 output enable.
*
*/
{
(volatile uint32*) &TIM2->CCER,

(uint32) ~(TIM_CCER_CC2E),

(uint32) (TIM_CCER_CC2E)
},

/**
* Configuration of TIM2_CCR2 register. While initialization the duty cycle is set to 0.
*
*/
{
(volatile uint32*) &TIM2->CCR2,

(uint32) ~(TIM_CCR2_CCR2),

(uint32) (0x00)
},
}


EDIT:
@Alex Lee came with a good observation and I think is right.
The solution, in order to get rid of spikes, at 100 % is to give to dutyCycle this expression:



DutyCycle = ((DutyCycle * (ul_ARR + 1)) >> 15U) ;


(TIMx_ARR + 1) because:
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT < TIMx_CCRx else inactive.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    Have you got a pulldown on that output?
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    No, I don't have. Is it necessary ?
    $endgroup$
    – pantarhei
    5 hours ago










  • $begingroup$
    Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
    $endgroup$
    – John Go-Soco
    5 hours ago






  • 2




    $begingroup$
    @JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
    $endgroup$
    – Lundin
    3 hours ago
















4












$begingroup$


Using a STM32F407 board. I want to generate a PWM signal. I have the following function:



/**
* brief Sets the CCR timer register. The register determines the duty cyle.
* param ChannelNumber: channel index from channels configuration array.
* param DutyCycle: value that represents the duty cycle of PWM signal. Can take values between 0x00 and 0x8000.
* return -
*/
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
{
uint32 ul_ARR = Pwm_pt_GroupsConfig[ChannelNumber].pt_Register->ARR;

DutyCycle = ((DutyCycle * ul_ARR) >> 15U) ;

*Pwm_pt_GroupsConfig[ChannelNumber].pt_DutyCycleRegister = DutyCycle;

}


When I call the function with a value between 0x0000 and 0x8000, for example 0x4000, I have 50 % duty cycle:
enter image description here



For 0x8000 I get 100 % duty cycle.
All good.



enter image description here



If I want 0 % duty cycle : 0x0000



enter image description here



When DutyCycleRegister is set to 0x00 seems that the PWM pin is floating or compare unit is inactive, not pulled to ground.
Does anyone know what is going on ?



If I modify the PWM function like this and not allow the DutyCycle to take 0 value.



DutyCycle = ((DutyCycle * ul_ARR) >> 15U) +1;


At 0x0000:
enter image description here
The configuration array:



    /** brief Register configuration array */
static const RegInit_Masked32BitsSingleType Pwm_kat_Registers[PWM_NUMBER_OF_REGISTERS] =
{

/* TIMER 2 CONFIGURATION */

/**
* Configuration of TIM2_CR1 register
* - Set the counting direction as 'upcounter'
* 0: Upcounter
* 1: Downcounter
*
*/

{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_DIR),

(uint32) (0x00)
},

/**
* Configuration of TIM2_EGR register
* - Set update generation to restart the counter after it has reached its peak value.
* 0: No action
* 1: Re-initialize the counter
*
*
*/

{
(volatile uint32*) &TIM2->EGR,

(uint32) ~(TIM_EGR_UG),

(uint32) (TIM_EGR_UG)
},

/**
* Configuration of TIM2_PSC register
* - Set prescaler value to 0.
* Range: 0 to 0xFFFF
* Divided clock frequency: fCK_PSC / (PSC[15:0] + 1).
*
*
*/

{
(volatile uint32*) &TIM2->PSC,

(uint32) ~(TIM_PSC_PSC),

(uint32) (0x00)
},

/**
* Configuration of TIM2_ARR register
* - Set auto-reload value to 0xFA0.
*
*
*/
{
(volatile uint32*) &TIM2->ARR,

(uint32) ~(TIM_ARR_PRELOAD),

(uint32) (TIM_ARR_FREQUENCY)
},

/**
* Configuration of TIM2_CR1 register
* - Set the counter enable register to 1
* 0: Counter disabled
* 1: Counter enabled
*
*/
{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_CEN),

(uint32) (TIM_CR1_CEN)
},

/**
* Configuration of TIM2_CCMR1 register
* - Set the PWM mode 1
* 110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
* else inactive. In downcounting, channel 1 is inactive (OC1REF=‘0’) as long as
* TIMx_CNT>TIMx_CCR1 else active (OC1REF=’1’).
* 111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1
* else active. In downcounting, channel 1 is active as long as TIMx_CNT>TIMx_CCR1 else
* inactive.
*
*/
{
(volatile uint32*) &TIM2->CCMR1,

(uint32) ~(
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1),

(uint32) (
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1)
},

/**
* Configuration of TIM2_CCER register
* - Set capture/compare enable register. Enable CC2E: Capture/Compare 2 output enable.
*
*/
{
(volatile uint32*) &TIM2->CCER,

(uint32) ~(TIM_CCER_CC2E),

(uint32) (TIM_CCER_CC2E)
},

/**
* Configuration of TIM2_CCR2 register. While initialization the duty cycle is set to 0.
*
*/
{
(volatile uint32*) &TIM2->CCR2,

(uint32) ~(TIM_CCR2_CCR2),

(uint32) (0x00)
},
}


EDIT:
@Alex Lee came with a good observation and I think is right.
The solution, in order to get rid of spikes, at 100 % is to give to dutyCycle this expression:



DutyCycle = ((DutyCycle * (ul_ARR + 1)) >> 15U) ;


(TIMx_ARR + 1) because:
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT < TIMx_CCRx else inactive.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    Have you got a pulldown on that output?
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    No, I don't have. Is it necessary ?
    $endgroup$
    – pantarhei
    5 hours ago










  • $begingroup$
    Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
    $endgroup$
    – John Go-Soco
    5 hours ago






  • 2




    $begingroup$
    @JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
    $endgroup$
    – Lundin
    3 hours ago














4












4








4





$begingroup$


Using a STM32F407 board. I want to generate a PWM signal. I have the following function:



/**
* brief Sets the CCR timer register. The register determines the duty cyle.
* param ChannelNumber: channel index from channels configuration array.
* param DutyCycle: value that represents the duty cycle of PWM signal. Can take values between 0x00 and 0x8000.
* return -
*/
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
{
uint32 ul_ARR = Pwm_pt_GroupsConfig[ChannelNumber].pt_Register->ARR;

DutyCycle = ((DutyCycle * ul_ARR) >> 15U) ;

*Pwm_pt_GroupsConfig[ChannelNumber].pt_DutyCycleRegister = DutyCycle;

}


When I call the function with a value between 0x0000 and 0x8000, for example 0x4000, I have 50 % duty cycle:
enter image description here



For 0x8000 I get 100 % duty cycle.
All good.



enter image description here



If I want 0 % duty cycle : 0x0000



enter image description here



When DutyCycleRegister is set to 0x00 seems that the PWM pin is floating or compare unit is inactive, not pulled to ground.
Does anyone know what is going on ?



If I modify the PWM function like this and not allow the DutyCycle to take 0 value.



DutyCycle = ((DutyCycle * ul_ARR) >> 15U) +1;


At 0x0000:
enter image description here
The configuration array:



    /** brief Register configuration array */
static const RegInit_Masked32BitsSingleType Pwm_kat_Registers[PWM_NUMBER_OF_REGISTERS] =
{

/* TIMER 2 CONFIGURATION */

/**
* Configuration of TIM2_CR1 register
* - Set the counting direction as 'upcounter'
* 0: Upcounter
* 1: Downcounter
*
*/

{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_DIR),

(uint32) (0x00)
},

/**
* Configuration of TIM2_EGR register
* - Set update generation to restart the counter after it has reached its peak value.
* 0: No action
* 1: Re-initialize the counter
*
*
*/

{
(volatile uint32*) &TIM2->EGR,

(uint32) ~(TIM_EGR_UG),

(uint32) (TIM_EGR_UG)
},

/**
* Configuration of TIM2_PSC register
* - Set prescaler value to 0.
* Range: 0 to 0xFFFF
* Divided clock frequency: fCK_PSC / (PSC[15:0] + 1).
*
*
*/

{
(volatile uint32*) &TIM2->PSC,

(uint32) ~(TIM_PSC_PSC),

(uint32) (0x00)
},

/**
* Configuration of TIM2_ARR register
* - Set auto-reload value to 0xFA0.
*
*
*/
{
(volatile uint32*) &TIM2->ARR,

(uint32) ~(TIM_ARR_PRELOAD),

(uint32) (TIM_ARR_FREQUENCY)
},

/**
* Configuration of TIM2_CR1 register
* - Set the counter enable register to 1
* 0: Counter disabled
* 1: Counter enabled
*
*/
{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_CEN),

(uint32) (TIM_CR1_CEN)
},

/**
* Configuration of TIM2_CCMR1 register
* - Set the PWM mode 1
* 110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
* else inactive. In downcounting, channel 1 is inactive (OC1REF=‘0’) as long as
* TIMx_CNT>TIMx_CCR1 else active (OC1REF=’1’).
* 111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1
* else active. In downcounting, channel 1 is active as long as TIMx_CNT>TIMx_CCR1 else
* inactive.
*
*/
{
(volatile uint32*) &TIM2->CCMR1,

(uint32) ~(
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1),

(uint32) (
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1)
},

/**
* Configuration of TIM2_CCER register
* - Set capture/compare enable register. Enable CC2E: Capture/Compare 2 output enable.
*
*/
{
(volatile uint32*) &TIM2->CCER,

(uint32) ~(TIM_CCER_CC2E),

(uint32) (TIM_CCER_CC2E)
},

/**
* Configuration of TIM2_CCR2 register. While initialization the duty cycle is set to 0.
*
*/
{
(volatile uint32*) &TIM2->CCR2,

(uint32) ~(TIM_CCR2_CCR2),

(uint32) (0x00)
},
}


EDIT:
@Alex Lee came with a good observation and I think is right.
The solution, in order to get rid of spikes, at 100 % is to give to dutyCycle this expression:



DutyCycle = ((DutyCycle * (ul_ARR + 1)) >> 15U) ;


(TIMx_ARR + 1) because:
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT < TIMx_CCRx else inactive.










share|improve this question











$endgroup$




Using a STM32F407 board. I want to generate a PWM signal. I have the following function:



/**
* brief Sets the CCR timer register. The register determines the duty cyle.
* param ChannelNumber: channel index from channels configuration array.
* param DutyCycle: value that represents the duty cycle of PWM signal. Can take values between 0x00 and 0x8000.
* return -
*/
void Pwm_SetDutyCycle(Pwm_ChannelType ChannelNumber, uint16 DutyCycle)
{
uint32 ul_ARR = Pwm_pt_GroupsConfig[ChannelNumber].pt_Register->ARR;

DutyCycle = ((DutyCycle * ul_ARR) >> 15U) ;

*Pwm_pt_GroupsConfig[ChannelNumber].pt_DutyCycleRegister = DutyCycle;

}


When I call the function with a value between 0x0000 and 0x8000, for example 0x4000, I have 50 % duty cycle:
enter image description here



For 0x8000 I get 100 % duty cycle.
All good.



enter image description here



If I want 0 % duty cycle : 0x0000



enter image description here



When DutyCycleRegister is set to 0x00 seems that the PWM pin is floating or compare unit is inactive, not pulled to ground.
Does anyone know what is going on ?



If I modify the PWM function like this and not allow the DutyCycle to take 0 value.



DutyCycle = ((DutyCycle * ul_ARR) >> 15U) +1;


At 0x0000:
enter image description here
The configuration array:



    /** brief Register configuration array */
static const RegInit_Masked32BitsSingleType Pwm_kat_Registers[PWM_NUMBER_OF_REGISTERS] =
{

/* TIMER 2 CONFIGURATION */

/**
* Configuration of TIM2_CR1 register
* - Set the counting direction as 'upcounter'
* 0: Upcounter
* 1: Downcounter
*
*/

{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_DIR),

(uint32) (0x00)
},

/**
* Configuration of TIM2_EGR register
* - Set update generation to restart the counter after it has reached its peak value.
* 0: No action
* 1: Re-initialize the counter
*
*
*/

{
(volatile uint32*) &TIM2->EGR,

(uint32) ~(TIM_EGR_UG),

(uint32) (TIM_EGR_UG)
},

/**
* Configuration of TIM2_PSC register
* - Set prescaler value to 0.
* Range: 0 to 0xFFFF
* Divided clock frequency: fCK_PSC / (PSC[15:0] + 1).
*
*
*/

{
(volatile uint32*) &TIM2->PSC,

(uint32) ~(TIM_PSC_PSC),

(uint32) (0x00)
},

/**
* Configuration of TIM2_ARR register
* - Set auto-reload value to 0xFA0.
*
*
*/
{
(volatile uint32*) &TIM2->ARR,

(uint32) ~(TIM_ARR_PRELOAD),

(uint32) (TIM_ARR_FREQUENCY)
},

/**
* Configuration of TIM2_CR1 register
* - Set the counter enable register to 1
* 0: Counter disabled
* 1: Counter enabled
*
*/
{
(volatile uint32*) &TIM2->CR1,

(uint32) ~(TIM_CR1_CEN),

(uint32) (TIM_CR1_CEN)
},

/**
* Configuration of TIM2_CCMR1 register
* - Set the PWM mode 1
* 110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT<TIMx_CCR1
* else inactive. In downcounting, channel 1 is inactive (OC1REF=‘0’) as long as
* TIMx_CNT>TIMx_CCR1 else active (OC1REF=’1’).
* 111: PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT<TIMx_CCR1
* else active. In downcounting, channel 1 is active as long as TIMx_CNT>TIMx_CCR1 else
* inactive.
*
*/
{
(volatile uint32*) &TIM2->CCMR1,

(uint32) ~(
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1),

(uint32) (
TIM_CCMR1_OC2PE |
TIM_CCMR1_OC2M_2 |
TIM_CCMR1_OC2M_1)
},

/**
* Configuration of TIM2_CCER register
* - Set capture/compare enable register. Enable CC2E: Capture/Compare 2 output enable.
*
*/
{
(volatile uint32*) &TIM2->CCER,

(uint32) ~(TIM_CCER_CC2E),

(uint32) (TIM_CCER_CC2E)
},

/**
* Configuration of TIM2_CCR2 register. While initialization the duty cycle is set to 0.
*
*/
{
(volatile uint32*) &TIM2->CCR2,

(uint32) ~(TIM_CCR2_CCR2),

(uint32) (0x00)
},
}


EDIT:
@Alex Lee came with a good observation and I think is right.
The solution, in order to get rid of spikes, at 100 % is to give to dutyCycle this expression:



DutyCycle = ((DutyCycle * (ul_ARR + 1)) >> 15U) ;


(TIMx_ARR + 1) because:
110: PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT < TIMx_CCRx else inactive.







microcontroller pwm stm32 stm32f4 duty-cycle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago







pantarhei

















asked 5 hours ago









pantarheipantarhei

45212




45212








  • 1




    $begingroup$
    Have you got a pulldown on that output?
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    No, I don't have. Is it necessary ?
    $endgroup$
    – pantarhei
    5 hours ago










  • $begingroup$
    Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
    $endgroup$
    – John Go-Soco
    5 hours ago






  • 2




    $begingroup$
    @JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
    $endgroup$
    – Lundin
    3 hours ago














  • 1




    $begingroup$
    Have you got a pulldown on that output?
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    No, I don't have. Is it necessary ?
    $endgroup$
    – pantarhei
    5 hours ago










  • $begingroup$
    Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
    $endgroup$
    – John Go-Soco
    5 hours ago






  • 2




    $begingroup$
    @JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
    $endgroup$
    – Lundin
    3 hours ago








1




1




$begingroup$
Have you got a pulldown on that output?
$endgroup$
– John Go-Soco
5 hours ago




$begingroup$
Have you got a pulldown on that output?
$endgroup$
– John Go-Soco
5 hours ago












$begingroup$
No, I don't have. Is it necessary ?
$endgroup$
– pantarhei
5 hours ago




$begingroup$
No, I don't have. Is it necessary ?
$endgroup$
– pantarhei
5 hours ago












$begingroup$
Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
$endgroup$
– John Go-Soco
5 hours ago




$begingroup$
Only if you want to prevent a floating signal, which seems to me is what you want. AFAIK there's a way to configure an internal pulldown as well, I think?
$endgroup$
– John Go-Soco
5 hours ago




2




2




$begingroup$
@JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
$endgroup$
– Lundin
3 hours ago




$begingroup$
@JohnGo-Soco If it's a proper PWM it should actively drive the pin low. There should never be a need for external pulldown. This is likely some quirk of the specific PWM peripherals. Nothing else to do but to read everything in the PWM chapter of the manual.
$endgroup$
– Lundin
3 hours ago










1 Answer
1






active

oldest

votes


















13












$begingroup$

The vertical scale on your first two oscilloscope traces (50% and 100% duty cycle) is roughly 0-3 V



The vertical scale on your third oscilloscope trace (0% duty cycle) is around 0-30 mV



The amplitude of the noise is thus probably the same in all the traces, but it is only obvious when magnified in the third image which is "zoomed in" by a factor of 100!






share|improve this answer









$endgroup$













  • $begingroup$
    Good observation.
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    Ok then. Buy why is not a clean 0 and the pin has some noise ?
    $endgroup$
    – pantarhei
    4 hours ago






  • 2




    $begingroup$
    @pantarhei What does your 3.3V supply plane look like, with the same scope settings?
    $endgroup$
    – Lundin
    3 hours ago






  • 1




    $begingroup$
    Has the same amount of noise if I zoom in.
    $endgroup$
    – pantarhei
    3 hours ago






  • 2




    $begingroup$
    @pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
    $endgroup$
    – brhans
    1 hour ago











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
return StackExchange.using("schematics", function () {
StackExchange.schematics.init();
});
}, "cicuitlab");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "135"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f423547%2fstm32-pwm-problem%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









13












$begingroup$

The vertical scale on your first two oscilloscope traces (50% and 100% duty cycle) is roughly 0-3 V



The vertical scale on your third oscilloscope trace (0% duty cycle) is around 0-30 mV



The amplitude of the noise is thus probably the same in all the traces, but it is only obvious when magnified in the third image which is "zoomed in" by a factor of 100!






share|improve this answer









$endgroup$













  • $begingroup$
    Good observation.
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    Ok then. Buy why is not a clean 0 and the pin has some noise ?
    $endgroup$
    – pantarhei
    4 hours ago






  • 2




    $begingroup$
    @pantarhei What does your 3.3V supply plane look like, with the same scope settings?
    $endgroup$
    – Lundin
    3 hours ago






  • 1




    $begingroup$
    Has the same amount of noise if I zoom in.
    $endgroup$
    – pantarhei
    3 hours ago






  • 2




    $begingroup$
    @pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
    $endgroup$
    – brhans
    1 hour ago
















13












$begingroup$

The vertical scale on your first two oscilloscope traces (50% and 100% duty cycle) is roughly 0-3 V



The vertical scale on your third oscilloscope trace (0% duty cycle) is around 0-30 mV



The amplitude of the noise is thus probably the same in all the traces, but it is only obvious when magnified in the third image which is "zoomed in" by a factor of 100!






share|improve this answer









$endgroup$













  • $begingroup$
    Good observation.
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    Ok then. Buy why is not a clean 0 and the pin has some noise ?
    $endgroup$
    – pantarhei
    4 hours ago






  • 2




    $begingroup$
    @pantarhei What does your 3.3V supply plane look like, with the same scope settings?
    $endgroup$
    – Lundin
    3 hours ago






  • 1




    $begingroup$
    Has the same amount of noise if I zoom in.
    $endgroup$
    – pantarhei
    3 hours ago






  • 2




    $begingroup$
    @pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
    $endgroup$
    – brhans
    1 hour ago














13












13








13





$begingroup$

The vertical scale on your first two oscilloscope traces (50% and 100% duty cycle) is roughly 0-3 V



The vertical scale on your third oscilloscope trace (0% duty cycle) is around 0-30 mV



The amplitude of the noise is thus probably the same in all the traces, but it is only obvious when magnified in the third image which is "zoomed in" by a factor of 100!






share|improve this answer









$endgroup$



The vertical scale on your first two oscilloscope traces (50% and 100% duty cycle) is roughly 0-3 V



The vertical scale on your third oscilloscope trace (0% duty cycle) is around 0-30 mV



The amplitude of the noise is thus probably the same in all the traces, but it is only obvious when magnified in the third image which is "zoomed in" by a factor of 100!







share|improve this answer












share|improve this answer



share|improve this answer










answered 5 hours ago









Alex LeeAlex Lee

15613




15613












  • $begingroup$
    Good observation.
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    Ok then. Buy why is not a clean 0 and the pin has some noise ?
    $endgroup$
    – pantarhei
    4 hours ago






  • 2




    $begingroup$
    @pantarhei What does your 3.3V supply plane look like, with the same scope settings?
    $endgroup$
    – Lundin
    3 hours ago






  • 1




    $begingroup$
    Has the same amount of noise if I zoom in.
    $endgroup$
    – pantarhei
    3 hours ago






  • 2




    $begingroup$
    @pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
    $endgroup$
    – brhans
    1 hour ago


















  • $begingroup$
    Good observation.
    $endgroup$
    – John Go-Soco
    5 hours ago










  • $begingroup$
    Ok then. Buy why is not a clean 0 and the pin has some noise ?
    $endgroup$
    – pantarhei
    4 hours ago






  • 2




    $begingroup$
    @pantarhei What does your 3.3V supply plane look like, with the same scope settings?
    $endgroup$
    – Lundin
    3 hours ago






  • 1




    $begingroup$
    Has the same amount of noise if I zoom in.
    $endgroup$
    – pantarhei
    3 hours ago






  • 2




    $begingroup$
    @pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
    $endgroup$
    – brhans
    1 hour ago
















$begingroup$
Good observation.
$endgroup$
– John Go-Soco
5 hours ago




$begingroup$
Good observation.
$endgroup$
– John Go-Soco
5 hours ago












$begingroup$
Ok then. Buy why is not a clean 0 and the pin has some noise ?
$endgroup$
– pantarhei
4 hours ago




$begingroup$
Ok then. Buy why is not a clean 0 and the pin has some noise ?
$endgroup$
– pantarhei
4 hours ago




2




2




$begingroup$
@pantarhei What does your 3.3V supply plane look like, with the same scope settings?
$endgroup$
– Lundin
3 hours ago




$begingroup$
@pantarhei What does your 3.3V supply plane look like, with the same scope settings?
$endgroup$
– Lundin
3 hours ago




1




1




$begingroup$
Has the same amount of noise if I zoom in.
$endgroup$
– pantarhei
3 hours ago




$begingroup$
Has the same amount of noise if I zoom in.
$endgroup$
– pantarhei
3 hours ago




2




2




$begingroup$
@pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
$endgroup$
– brhans
1 hour ago




$begingroup$
@pantarhei - well there you go - you're seeing the power supply noise that's everywhere in your circuit. It's not reasonable to expect your micro's PWM output to be somehow 'cleaner' than the supply you give it.
$endgroup$
– brhans
1 hour ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Electrical Engineering Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f423547%2fstm32-pwm-problem%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...