1

I've recently been looking at Timers and I'm trying to generate a PWM frequency at 250000Hz using Timer0 on PIN 4. When I set OCR0A = 63 I get nothing from the light however when I set OCR0A = 125 it turns on ( 128000Hz - according to the formula in the datasheet unless I've been working it out wrong). What's the reason for it not working when OCR0A = 63

#include <DmxSimple.h>


void setup() {
  // put your setup code here, to run once:
  Serial.begin(250000);
  pinMode(2,OUTPUT);  // SHIELD DRIVER OUTPUT ENABLE
  digitalWrite( 2 , HIGH); // SHEILD DE HIGH
  DDRG |= bit(DDG5); 



  TCCR0A = 0;
  TCCR0B = 0;
  TCNT0 =  0;

  TCCR0A = bit(COM0A1)| bit(COM0B1)| bit(WGM01)| bit(WGM00);
  TCCR0B = bit(WGM02) | bit(CS00);
  OCR0A = 63 ;
  OCR0B = 31;

}

void loop() {
  // put your main code here, to run repeatedly:

(1,PORTG |= (1<<5));
(1,PORTG &= ~(1<<5));


}


6
  • Except for the loop code (that shouldn't be affecting anything, as it's using alternate pin function) and pointless COM0A1, I can't see any problem. Well, except one of my multimeters showed the wrong frequency, second one shows correct 248.76kHz and 50% pulse width. Commented Apr 20, 2020 at 16:32
  • @KIIV Could the DmxSimple library be causing a problem ? . I don't have an oscilloscope or multimeter to check the output frequency but your multimeter showed 250kHz when OCR0A = 63 ? Commented Apr 20, 2020 at 16:38
  • DmxSimple uses Timer2 so it shouldn't be a problem. At least as far as you don't use anything millis related, like delay or so (because it's updated by Timer0 overflow and it won't happen with that changes) Commented Apr 20, 2020 at 16:41
  • I've made sure to leave any delays out . I'm not sure what the issue could be . Would it worth changing to see if it works in Fast PWM mode when TOP = 0xff Commented Apr 20, 2020 at 17:13
  • 1
    It's a non branded DMX light that I had . The period is not necessary . I'm just trying to get a distinct modulated that signal that can be picked up by the photodiode. I was previously trying to get OOK modulation to work but was unable so I'm now trying PWM . Any suggestions would be much appreciated Commented Apr 20, 2020 at 17:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.