I would like to generate a PWM waveform with Arduino Uno at freq <>490 or 980Hz

Hello, in search for a solution for subject I have found a competently written instructable at https://www.instructables.com/id/Arduino-Timer-Interrupts/
and I decided to give a try to the use of interrupts. I succeed at generating a PWM at ~7800Hz with a given on-off ratio, but as soon as I try to change the latter the output goes to 0 and remains there no matter what I try to load in the OCR2A register that should, according to the Atmel328 datasheet, determine its value. As suggested in the 328 datasheet, page 151, I use an ISR (interrupt service routine) to modify the value of the OCR2A, which seems to run fine, but when I inspect the value of the said register after I attempt to modify it I find it always equal to zero. Before the modification attempt the value is whatever I set up. An LED connected to the output is bright or dim in accordance to the value of OCR2A. What am I doing wrong? I enclose the relevant portions the code for the Arduino IDE. Thanks in advance for any idea, regards,
Alessandro

void setup() {
...
noInterrupts();
//set timer2 for fast PMW ~7800Hz
  TCCR2A = 0; // set entire TCCR0A register to 0
  TCCR2B = 0; // same for TCCR0B
  TCNT2  = 0; //initialize counter value to 0
  TIMSK2 = 0;  // clear mask register
  TIFR2= 0x00; // clear interrupt flags
  OCR2A = 50;  // smallish initial value
// turn on fast PWM mode
  TCCR2A |= 0x03 ;
// set non inverting mode
  TCCR2A |= 0x80 ;
// Set CS22:0 for 8 prescaler, CS02:0= 2  
  TCCR2B |= (1 << CS21);
// enable timer overflow interrupt, TIMSK22:0 = 1
  TIMSK2 |= 0x01; 
interrupts();
}

ISR(TIMER2_OVF_vect){
cli();          // stops all interrupts
TIFR2= 0x00;    // clear interrupt flag ((not needed)
if (newval) {   // new value available for OCR2A
  newval = false;
  OCR2A = deltatime;    // deltatime contains the new value of OCR2A, loaded from keyboard
//  Serial.println("been here");
  } 
sei();   // enables interrupts;
return;
}
ISR(TIMER2_OVF_vect){
//cli();          // stops all interrupts
TIFR2= 0x00;    // clear interrupt flag ((not needed)
if (newval) {   // new value available for OCR2A
  newval = false;
  OCR2A = deltatime;    // deltatime contains the new value of OCR2A, loaded from keyboard
//  Serial.println("been here");
  }
//sei();   // enables interrupts;
//return;
}

cli(), sei() and return are not needed within the ISR. They are duplicating actions which occur automatically with an interrupt service routine.

I enclose the relevant portions the code for the Arduino IDE. Thanks in advance for any idea, regards,

Often, the problem is with the code you don't post, and you will need to provide more code than you provided. Can your write an minimal example which will compile and demonstrates the problem?

Have you verified that the keyboard entry of deltatime is working properly, and the variable type is appropriate?

Thanks a lot! The problem was exactly what you suggested where you suggested! I was using an "int" (deltatime) to assign a value to a register (OCR2A). Just changing the type deltatime in the declaration solved the problem. I assumed - just as the saying goes... - that truncation would take place as in an assigment of the byte = int variables type, whereas in this case truncation preserves the high byte, which must be the 0 value I constantly found in OCR2A.
Thanks a lot again! Cheers,
Alessandro