ok i have a feeling this might be simple but i cannot get my head around it
i am trying to make a simple pwm file which , for learning purposes will only use the 8 bit timer
along with PIN D6 (OCOA)...the code for that looks like thislooks like this
TCCR0A |= ((1<<COM0A1) | (1<<WGM01) | (1<<WGM00)) ; //set to use pin d6 and set to fast pwm
TCCR0B |= ((1<<CS02) | (1<<CS00)) ; //set the prescaler
TIMSK0 |= ((1<<TOIE0));// set timer overflow interrupt .. not sure if its is propper to use interrupts in files outside of main program
void startPWM ( )
OCR0A =((pulseWidth / 100) * 255.0); // set output compare to a percentage of 255
OCR0A =((pulseWidth / 100) * 255.0); //after the first interrupt this should just keep going and going
now my problem is i need to pass a pulsewidth in my main code if i use #define pulsewidth then i cant change the pulse width
and if i use a regular deffinition then its not seen by the pwm library...
my main code looks like this
#define F_CPU 16000000L
int pulseWidth = 50; // <--here is the problem
i know i can set the start pwm function to accept a parameter but then how do i get the ISR routine to also see that parameter if ISR accepts no parameters , only way would be to have a global variable , but then i cant change it....feels like a catch 22 , but im sure its just lack of knowledge..
can anyone enlighten me
furthermore is malpractice to use interrupts inside a .h file?
i know .h files are for definitions only , i will soon be attempting to learn about libraries . i just want to test out what can be done in an .h file