-1

I recently made a project where output is coming from the differential between data reading and reference value. It works on my Proteus simulation but there is no PWM output on my real world device.

Here is my code listing

for (z = 0; z <= output2; z++)
  if (output2 >= 30) {
   toggle == HIGH; 
   en = !en;
  }
if (en == true) {
  OCR1A = map(z, 0, 255, 0, ICR1); ;
  OCR1B = 0;
} else {
  OCR1A=0; 
  OCR1B = map(z, 0, 255, 0, ICR1);
}
if (output2 < 30) {
  en = !en;
  analogWrite(9, 0);
  analogWrite(10, 0);
}
  • 1
    What do you want to achieve by calling map()? Do you know what OCR1A/B are and how the analogWrite() function works? – Sim Son Apr 16 at 9:07
  • i saw from other program that is for setting up the carrier frequency, so if icr1=1600, 0-255 = 0-10khz, cmiiw, – john caren Apr 16 at 9:34
1

I’m not sure what you’re trying to accomplish, but you’re writing a constant 0 to the analog output.

if (output2 < 30) {
  en = !en;
  analogWrite(9, 0);
  analogWrite(10, 0);
}

To quote the analogWrite() doc

Syntax

analogWrite(pin, value)

Parameters

pin: the pin to write to. Allowed data types: int.

value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int

If you want to see an output, you have to write a value between 0 and 255.

  • yes it is purposely gives 0 cycle when the output is less than 30 – john caren Apr 16 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.