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);
}
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))