Close

PWM Pain

A project log for Arduino Nextion Android Midi Valve Guitar Amp

Control a Marshall JCM800 2204 style guitar amp using touch screens, midi foot pedals and an Android App

paul-burfordPaul Burford 09/08/2019 at 16:060 Comments

After completion of the PCBs, the main problem I encountered was the Arduino's use of PWM. At stock operating frequency / bit level there just wasn't the detail needed to provide adequate steps for the optoisolator to adjust it's resistance smoothly. 256 steps in itself was enough but the optoisolators aren't linear. To combat this, I tried changing the resolution of the PWM to it's maximum of 65535 steps or 16 bits (for the applicable timers). This gave more than enough steps to fake linearity with the optoisolators but created a tremolous warbling sound when guitar was played. More research led me to deduce that an increase in the bit rate decreased the operating frequency to the point where it could be heard in the guitar sound. A compromise needed to be reached and was found at a PWM rate of  749... high enough to fake some sense of linearity but low enough not to affect the guitar tone. The code used (repeated for all applicable timers) was...

  TCCR1A=0;

  TCCR1A |= (1 << WGM11);  
  TCCR1B |= (1 << WGM12) | (1 << WGM13) | (1 << CS10);
  ICR1=749;

Finally, the optoisolators and Arduino were doing their job.

Discussions