I'm currently working on a PWM modulator to "simulate" a car engine ignition commutation. Then, I will use it to drive another microcontroller which handles the conversion from a raw signal (engine's commutator) to a clean output voltage, going through the RPM-counter's galvanometer.
This project is also a pretext for me to learn how to have a better control upon my microcontroller.
Well, I wrote a small program, using timer0 (8 bits), and I need to trigger two interrupt service routines (ISRs):
- TIMER0_OVF_vect: overflow interruption
- TIMER0_COMPA_vect: fires on compare
I have the following functions:
void configureTimer0(parameters)
{
cli();
// Some maths
TCCR0A = (1<<WGM01) | (1<<WGM00); // I tried to use the "Fast PWM" waveform generation mode
TCCR0B &= 0b00110000; // 5th and 4th bits are reserved. Every other bits is set to 0.
TCNT0 = 0; // Initialize counter value to 0
TCCR0B |= select_prescaler(prescaler); // Custom function to determine the right prescaler
OCR0A = ext_OnTicks; // Output compare register is set to a predetermined numbers of ticks
// Enabling overflows interrupt:
TIMSK0 |= (1 << TOIE0);
sei(); // Enable interrupts
}
Then, under certain conditions, I switch the OCIE0 bit in TIMSK0 on and off depending on the situation. However, the overflow interruption is always enabled.
When I try to compile, I end up with these errors:
"C:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_8383\sketch\PWM_modulator.ino.cpp.o" "C:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_8383/..\arduino_cache_395570\core\core_arduino_avr_uno_a94ab6aaf61dfb93b4a8079c694a14c2.a" "-LC:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_8383" -lm
wiring.c.o (symbol from plugin): In function `__vector_16':
(.text+0x0): multiple definition of `__vector_16'
C:\Users\UTILIS~1\AppData\Local\Temp\arduino_build_8383\sketch\PWM_modulator.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Erreur de compilation pour la carte Arduino/Genuino Uno // Compilation error for Uno board (French)
I tried to compile with ISR(TIMER0_COMPB_vect) instead of ISR(TIMER0_OVF_vect), and it works, but indeed it's not the point of my program.
I also tried ISR(TIMER2_OVF_vect) which is an 8-bit timer as well. I could synchronize Timer0 and Timer2 to achieve the desired effect, however I don't think it is quite clean to do so (and it prevents me to use the Timer2 capabilities).
There is something wrong in my code, but cannot understand where the mistake is hiding. There is definitely something related to the wiring.c.o file.
PS: I've looked for a solution quite a long time since the problem appears, but I could not find any way to ask Google correctly neither the Stack Overflow site. Apologies if I missed the right search string!