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);

}
delay(100);

That won't work with interrupts turned off. You'll likely deadlock right there.

I think it would be a good idea to describe what it is that you want and what it is that you are trying to accomplish. What "jitter" are you observing? Your question is really vague and lacks any context. What board you're using might also be a critical piece of information. Really, better to give information that isn't needed than to ask a vague question that can't be answered because nobody knows what you're talking about.

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

BTW: The code you posted doesn't compile. You have a bunch of code that isn't inside a function. Loop ends on the brace after the //////// line.

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

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

OK, can we have the code that you are actually running? How about a trace from the scope that shows this jitter?

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 picture from #6

8e311c8e5a0fd4f4c55f26beb3aa0814fec01fe4.jpg

What are we looking at there? I see a nice square wave. Is there a timing issue?

The little spikes = shaking double vertical lines

Vik321:
The little spikes = shaking double vertical lines

That's not the code or anything you can fix with the code. That's noise. That's not "jitter"

The jitter that an interrupt might cause would be one wave being a little bit longer than it should every now and then.

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

Pic from #11

966a3c6faa67e9c9f71d92f825229a9865c0bce8.jpg

Let me ask again about what are we looking at here. Where do you have the probes exactly? You're measuring the Arduino pins?

This still isn't something that is related to interrupts on the micro.

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.

Vik321:
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.

OK, I believe you. That shaking is still not related to the code running on the Arduino. That is not jitter. That's niose.

The thing that disabling interrupts fixes is jitter, where an occasional pulse is longer than the others. I don't see that here. And you haven't described that problem.

As for the shadow pulses I'm not sure what you're seeing, but again I can be certain that it isn't the code or interrupts causing it.

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();
///////////////////////////////////////////////////
*/
}

WattsThat:
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.

I reported it so they can combine them.