For the past week i've been verifing the differences between to programs (Assembly & Arduino) running on the same target(ATmega328P). The two programs perform the same operations which is to basically use the Timer/Counter_1 and Timer/Counter_2 to emit two PWM signals on separate pins continuously. Before someone says "there are better ways to examine the differences between the two languages" I just want to say "I agree there are" but i'm examining specifics in relation to my application and to just further my knowledge.
I have a question that I can't seem to answer myself yet and thought I would get a better answer from you wonderful fellows that have had more experience in using the numerous libraries out there for PWM that use the Timer/Counters. There seems to be more than one library out there that do this.
In assembly, I can enable the timer/counters and have them running in the background before I enter my main loop. However, in my Arduino program I can't seem to get my program to do this. I tried throwing the lines of code that does this in the void setup(){} but it doesn't compile. For example the following just won't compile.
#include <PWM.h>
int pwmpin1 = 2;
int pwmpin2 = 8;
void setup(){
pinMode(pwmpin1, OUTPUT);
pinMode(pwmpin2, OUTPUT);
SetPinFrequency(pwmpin1, 125); //frequency
pwmWrite(pwmpin1, 64); //duty cylce
SetPinFrequency(pwmpin2,250); //frequency
pwmWrite(pwmpin2, 64);} //duty cycle
void loop(){}
Therefore, i'm forced to do the following in order for it to compile
#include <PWM.h>
int pwmpin1 = 2;
int pwmpin2 = 8;
void setup(){
pinMode(pwmpin1, OUTPUT);
pinMode(pwmpin2, OUTPUT);}
void loop(){
SetPinFrequency(pwmpin1, 125); //frequency
pwmWrite(pwmpin1, 64); //duty cylce
SetPinFrequency(pwmpin2,250); //frequency
pwmWrite(pwmpin2, 64);} //duty cycle
Therefore, is there some way I can enable these counters in the background without doing this inside the main loop? I can't seem to put down the words to explain what i'm wanting. I guess what i'm trying to do is enable the timers back to back in the most efficient way in mitigating the delay from time Timer1 is enabled to time Timer2 is enabled. Hope this explains what i'm asking.
I am by no means creating an argument on which language is better as this seems to be a highly sensitive subject as I've noticed in avrfreaks.net. Just asking for some friendly guidance from those of you who have messed around with different methodologies in enabling Timer/Counters.