Go Down

Topic: making a library using timer.c (Read 1 time) previous topic - next topic

Benoît ROUSSEAU

Jul 08, 2006, 01:04 am Last Edit: Jul 08, 2006, 12:35 pm by Benoit Reason: 1
Hello,

First, please excuse me for my poor english.

I'm trying to make a clock library using timer.c.

By modify wiring.c & .h I have made a clock with Arduino : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1151887411. Now, I want to do it better by writing a library to generate precise delays using interrupts (at min vector 7). This library named "TicTac", I think, could be very useful for many users and projects.

HELP !  :'(

First I'm try to do this :
Code: [Select]

[...]

#undef PI
#include "timer.h"

[...]

void TicTac::Start()
{

 // arrêt des fonctions PWM
 timer1PWMOff();

 // réglage du pré-diviseur de fréquence
 // TCNT1 sera incrémenté tous les 1024 tics
 // de l'horloge du micro-controlleur
 timer1SetPrescaler(TIMER_CLK_DIV1024);

 // liaison de l'interruption TIMER1OUTCOMPAREA_INT
 // avec la fonction TicTac
 timerAttach(TIMER1OUTCOMPAREA_INT, Bip);
 
 [...]
}

The compiler respond me :
lib\targets\libraries\TicTac\TicTac.o: In function `TicTac::Start()':


/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:77: undefined reference to `timer1PWMOff()'


/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:93: undefined reference to `timer1SetPrescaler(unsigned char)'


/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:98: undefined reference to `timerAttach(unsigned char, void (*)())'

I think that the linker does not found the timer.o.

In second time I 'm trying to do something like that :
Replacing all the timer.c functions by mine's, including the ISR function.
Code: [Select]

[...]
ISR(SIG_OUTPUT_COMPARE1B)
{
 [...]
}

[...]

void TicTac::Start()
{

 // arrêt des fonctions PWM
 // timer1PWMOff();
     // turn off timer1 PWM mode
     cbi(TCCR1A,PWM11);
     cbi(TCCR1A,PWM10);
     // turn off channel A (OC1A) PWM output
     // set OC1A (OutputCompare action) to none
     cbi(TCCR1A,COM1A1);
     cbi(TCCR1A,COM1A0);
     // turn off channel B (OC1B) PWM output
     // set OC1B (OutputCompare action) to none
     cbi(TCCR1A,COM1B1);
     cbi(TCCR1A,COM1B0);
 
 // réglage du pré-diviseur de fréquence
 // TCNT1 sera incrémenté tous les 1024 tics
 // de l'horloge du micro-controlleur
 // timer1SetPrescaler(TIMER_CLK_DIV1024);
     outb(TCCR1B, (inb(TCCR1B) & ~TIMER_PRESCALE_MASK) | TIMER_CLK_DIV1024);

 // liaison de l'interruption TIMER1OUTCOMPAREA_INT
 // avec la fonction TicTac
 // timerAttach(TIMER1OUTCOMPAREA_INT, Bip);

 [...]
}

The compiler respond me :
C:\DOCUME~1\Benoit\LOCALS~1\Temp\build28293.tmp\timer.c.o: In function `__vector_7':


E:\Arduino\arduino-0004-win\arduino-0004\lib\targets\arduino\timer.c:458: multiple definition of `__vector_7'


lib\targets\libraries\TicTac\TicTac.o:/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/lib\targets\libraries\TicTac\TicTac.cpp:54: first defined here


/cygdrive/e/Arduino/arduino-0004-win/arduino-0004/tools/avr/bin/../lib/gcc/avr/4.0.2/../../../../avr/bin/ld: Warning: size of symbol `__vector_7' changed from 148 in lib\targets\libraries\TicTac\TicTac.o to 90 in C:\DOCUME~1\Benoit\LOCALS~1\Temp\build28293.tmp\timer.c.o

Ok, that's right,  `__vector_7' was defined in timer.c.

How can I do ? Is somebody have any idea ?
Cordialement,
Benoît ROUSSEAU

Go Up