pulses jitter

I am trying to eliminate pulses jitter by noInterrupts() function, according to post

https://forum.arduino.cc/index.php?topic=549016.0

this function should do that but is not, what I'm doing wrong ?

HardwareTimer pwmtimer1(1);
HardwareTimer pwmtimer4(4);
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
int i;
int ovfi;

void setup() {
  pinMode(PA8, PWM); //Rx
  pinMode(PB7, PWM); //Tx
  pinMode(PB6, INPUT_PULLDOWN);
  pinMode(PB9, INPUT_PULLDOWN);
  lcd.begin(16, 2);
   Serial.begin(9600);

  // noInterrupts() ;  
}

void loop() 
{
  ovfi = 10000 - i;
   noInterrupts() ;  
/////////////////////////////////////////////
  pwmtimer1.pause();
  pwmtimer1.setPrescaleFactor(1);
  pwmtimer1.setOverflow(5760 - 1);
  pwmtimer1.setCompare(TIMER_CH1, 2880);
  pwmtimer1.refresh();
  pwmtimer1.resume();

delayMicroseconds(i);

  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(1);
  pwmtimer4.setOverflow(5760 - 1);
  pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();
///////////////////////////////////////////////////
 }



  if (digitalRead(PB9) == HIGH)
  {
    if (i < 6000)
      // if (i < 25)
    {
      i++;//if pin PB3 is pressed and the duty ratio value is less than 255
      analogWrite(PB0, i);  // analogWrite values from 0 to 255
    
      delay(100);
    }
       
  }
  if (digitalRead(PB6) == HIGH)
  {
    if (i > 0)
    
    {
      i--;// if pin PB5 is pressed and the duty ratio value is greater than 0
      analogWrite(PB0, i);  // analogWrite values from 0 to 255
      
      delay(100);
    }
   
  }
  lcd.setCursor(0, 1);
  lcd.println(i);

}

Thanks for response
It is stm32f103, Arduino IDE.
This is a program for phase shifter of two generators 12kHz, I am opsering shaking pulses on oscilloscope.
Without <delay(100);> the shifting is very fast so it is hard to get required shift.

I disabled both delays - no difference

That bracket < } > is a left over from my attempts, after removing it should compile

HardwareTimer pwmtimer1(1);
HardwareTimer pwmtimer4(4);
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
int i;
int ovfi;

void setup() {
  pinMode(PA8, PWM); //Rx
  pinMode(PB7, PWM); //Tx
  pinMode(PB6, INPUT_PULLDOWN);
  pinMode(PB9, INPUT_PULLDOWN);
  lcd.begin(16, 2);
   Serial.begin(9600);

  // noInterrupts() ;  
}

void loop() 
{
  ovfi = 10000 - i;
   noInterrupts() ;  
/////////////////////////////////////////////
  pwmtimer1.pause();
  pwmtimer1.setPrescaleFactor(1);
  pwmtimer1.setOverflow(5760 - 1);
  pwmtimer1.setCompare(TIMER_CH1, 2880);
  pwmtimer1.refresh();
  pwmtimer1.resume();

delayMicroseconds(i);

  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(1);
  pwmtimer4.setOverflow(5760 - 1);
  pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();
///////////////////////////////////////////////////




  if (digitalRead(PB9) == HIGH)
  {
    if (i < 6000)
      // if (i < 25)
    {
      i++;//if pin PB3 is pressed and the duty ratio value is less than 255
      analogWrite(PB0, i);  // analogWrite values from 0 to 255
    
      //delay(100);
    }
       
  }
  if (digitalRead(PB6) == HIGH)
  {
    if (i > 0)
    
    {
      i--;// if pin PB5 is pressed and the duty ratio value is greater than 0
      analogWrite(PB0, i);  // analogWrite values from 0 to 255
      
      //delay(100);
    }
   
  }
  lcd.setCursor(0, 1);
  lcd.println(i);

}

scope.jpg

The little spikes = shaking double vertical lines

Vik321:
The little spikes = shaking double vertical lines

The double vertical lines are capacitive coupling from one signal to the other. Better lead dress is the answer. OR shielded leads.

Paul

Here you can see better, when I move both generators to set up the image is clear on both channels, so is not coupling problem

s2.jpg

It is hard to see on picture but on scope it is obvious shaking, the probes are directly on the pins of stm32f103, I am very positive this is no probe issue. Post #11
By pressing the buttons the shadow pulses are shifting at 180 deg they in line with main pulses.

The OP is double posting:

http://www.stm32duino.com/viewtopic.php?f=19&t=4523&p=52717

You’re more likely to get an answer over there as the STM32 is not an Arduino.

PS: you cannot cannot use the delay() function in combination with PWM timing and expect it to work.

shifted stable pulses mentioned @ post #11

HardwareTimer pwmtimer1(1);
HardwareTimer pwmtimer4(4);
#include <LiquidCrystal.h>
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
int i;
int ovfi;

void setup() {
  pinMode(PA8, PWM); //Rx
  pinMode(PB7, PWM); //Tx
  pinMode(PB6, INPUT_PULLDOWN);
  pinMode(PB9, INPUT_PULLDOWN);
  lcd.begin(16, 2);
   Serial.begin(9600);
   //////////////////////////////////
  pwmtimer1.pause();
  pwmtimer1.setPrescaleFactor(1);
  pwmtimer1.setOverflow(5760 - 1);
  pwmtimer1.setCompare(TIMER_CH1, 2880);
  pwmtimer1.refresh();
  pwmtimer1.resume();

delayMicroseconds(50);

  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(1);
  pwmtimer4.setOverflow(5760 - 1);
  pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();
   /////////////////////////////////////

 
}

void loop() 
{
/*
/////////////////////////////////////////////
  pwmtimer1.pause();
  pwmtimer1.setPrescaleFactor(1);
  pwmtimer1.setOverflow(5760 - 1);
  pwmtimer1.setCompare(TIMER_CH1, 2880);
  pwmtimer1.refresh();
  pwmtimer1.resume();

delayMicroseconds(i);

  pwmtimer4.pause();
  pwmtimer4.setPrescaleFactor(1);
  pwmtimer4.setOverflow(5760 - 1);
  pwmtimer4.setCompare(TIMER_CH2, 2880);
  pwmtimer4.refresh();
  pwmtimer4.resume();
///////////////////////////////////////////////////
*/
}