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