Hi,
I am working on a light control project, and i need 16 PWM pins with exactly 100Hz, and individually alter the dutycycle. I need to Control 16 dimmers this way, so I can co it either with 3 UNO´s or 2 Mega´s.
On Uno, 4 pins work, and 2 gives me error.
On Mega I experience weird behaviour on most of the pins, and 2 gives me error. They do not give the correct DutyCycle. Here follows the code examples for both boards. I have measured the dutycycle with picoscope, and written the results commented into the code below. Do you have Any Idea how I can achieve my goal using this Library?
//CODE FOR MEGA
#include <PWM.h>
void setup() {
Serial.begin(9600);
InitTimers();
if (!SetPinFrequency(2, 100))Serial.println("PWM pin 2 failed.");
if (!SetPinFrequency(3, 100))Serial.println("PWM pin 3 failed.");
if (!SetPinFrequency(4, 100))Serial.println("PWM pin 4 failed.");
if (!SetPinFrequency(5, 100))Serial.println("PWM pin 5 failed.");
if (!SetPinFrequency(6, 100))Serial.println("PWM pin 6 failed.");
if (!SetPinFrequency(8, 100))Serial.println("PWM pin 7 failed.");
if (!SetPinFrequency(9, 100))Serial.println("PWM pin 8 failed.");
if (!SetPinFrequency(10, 100))Serial.println("PWM pin 9 failed.");
if (!SetPinFrequency(11, 100))Serial.println("PWM pin 10 failed.");
if (!SetPinFrequency(12, 100))Serial.println("PWM pin 11 failed.");
if (!SetPinFrequency(13, 100))Serial.println("PWM pin 12 failed.");
Serial.println("Running..");
}
void loop() {
pwmWrite(2, 25); //Should have been ca 10%, actual is 40% not changed by changing 25
pwmWrite(3, 51); //Should have been ca 20%, actual is 10% seemes to be changing with pin 2
pwmWrite(4, 76); //Should have been ca 30%, actual is 30%
pwmWrite(5, 102); //Should have been ca 40%, actual is 80%
pwmWrite(6, 127); //Should have been ca 50%, actual is 20%
pwmWrite(7, 153); //Should have been ca 60%, actual is50%
pwmWrite(8, 177); //Should have been ca 70%, actual is60%
pwmWrite(9, 204); //Should have been ca 80%, actual is90%
pwmWrite(10, 230); //No duty cycle
pwmWrite(11, 204); //Should have been ca 80%, actual is80%
pwmWrite(12, 177); //Should have been ca 70%, actual is70%
pwmWrite(13, 153); //No duty cycle
delay(30);
}
//CODE FOR UNO
#include <PWM.h>
void setup() {
Serial.begin(9600);
InitTimers();
if (!SetPinFrequency(3, 100))Serial.println("PWM pin 3 failed.");
if (!SetPinFrequency(5, 100))Serial.println("PWM pin 5 failed.");
if (!SetPinFrequency(6, 100))Serial.println("PWM pin 6 failed.");
if (!SetPinFrequency(9, 100))Serial.println("PWM pin 9 failed.");
if (!SetPinFrequency(10, 100))Serial.println("PWM pin 10 failed.");
if (!SetPinFrequency(11, 100))Serial.println("PWM pin 11 failed.");
Serial.println("Running..");
}
void loop() {
pwmWrite(3, 26); //DutyCycle 10% OK
pwmWrite(5, 51); //DutyCycle 20% OK
pwmWrite(6, 76); //No duty cycle
pwmWrite(9, 102); //DutyCycle 40% OK
pwmWrite(10, 127); //DutyCycle 50% OK
pwmWrite(11, 153); //No duty cycle
delay(30);
}