Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

AnalogWrite dont work in arduino

2 posters

Go down  Message [Page 1 of 1]

1AnalogWrite dont work in arduino Empty AnalogWrite dont work in arduino Tue Apr 27, 2021 7:03 pm

vtarias



Hello greetings.
The analogWrite function does not work on any PWM pin for the arduino mega and arduino uno. Setting the microcontroller registers to generate a pwm signal does not work either.
In simulIDE 4.13 I have managed to generate a signal from pwm, manipulating the registers of the timers, but with analogWrite I have not been able to.
Thank you in advance for your help.

code for analogWrite

void setup() {
 // put your setup code here, to run once:
 pinMode(13,OUTPUT);
 analogWrite(13,150);
}

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

}

code manipulating registers


const int Pin = 8;

void setup() {
pinMode(Pin, OUTPUT);
//se desea una resolución de 9 bits con una frecuencia de 3900 HZ:
TCCR4A=TCCR4B=0;
TCCR4A |= (1 << WGM41);
TCCR4B |= (1 << WGM42 | 1 << CS41);
TCCR4A |= (1 << COM4C1); //configura pin para salida pwm
OCR4C = 333; //va de 0 a 511

}

void loop() {
   for (int brightness = 0; brightness < 511; brightness++) {
     OCR4C = brightness;
     delay(10);
   }
   // fade the LED on thisPin from brightest to off:
   for (int brightness = 511; brightness >= 0; brightness--) {
     OCR4C = brightness;
     delay(10);
   }
   delay(100);
}



Last edited by arcachofo on Fri Dec 24, 2021 3:02 am; edited 1 time in total (Reason for editing : Marked as solved (green color))

2AnalogWrite dont work in arduino Empty Re: AnalogWrite dont work in arduino Wed Apr 28, 2021 10:50 am

arcachofo

arcachofo

Hi.

I did some test and there are indeed some PWM channels not worling:

Arduino Uno, all working.

Arduino Mega, not working:
2, 4, 7,8, 12, 13.

I will have a look to those not working.

3AnalogWrite dont work in arduino Empty Re: AnalogWrite dont work in arduino Wed Apr 28, 2021 12:17 pm

arcachofo

arcachofo

Fortunately this error can be solved easily:

Attached is mega.package file (unzip it).
Replace the original file at:
SimulIDE_0.4.15-SR1_XX/share/simulide/data/arduino/old/

Start simulide and test if it is working for you.
Attachments
AnalogWrite dont work in arduino Attachmentmega.package.zip
You don't have permission to download attachments.
(2 Kb) Downloaded 0 times

4AnalogWrite dont work in arduino Empty Re: AnalogWrite dont work in arduino Thu Apr 29, 2021 1:01 am

vtarias



gracias, voy a utilizar lo que me has aconsejado.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum