expected '=', ',', ';', 'asm' or '__attribute__' before

Go To Last Post
40 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it is getting realy frustrating to do 30% code and 70% dealing with strange errors and problems.

i am trying to make a VERY simple variable in a .h file.

i have many other variable in diffrent .h files, all of them are working but in this special .h file i am getting this error when ever i am trying to add a new variable or function definition, this is inspite that it already contains one function definition that IS working.

not only that, when i try to add the variable to a diffrent .h file it sometimes compile and shows the results as expected but with diffrent times it suddenly decides he can't find the variable that only a minute ago he found with no problems.

this is the .h file:

#define inp(port) (port)
#define outp(val, port) (port) = (val)
#define inb(port) (port)
#define outb(port, val) (port) = (val)
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))

extern u16 SavedValue; // error
extern u08 USARTcount; // error

void Setup(void);

for both lines i am getting:

expected '=', ',', ';', 'asm' or '__attribute__' before 'the variable'

Thanks and Regards, Ran.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to define "u16" and "u08" somewhere. The avr-libc headers define types as:

(u)int[w]_t

Where "u" means unsigned, and "w" is the bit width. For example:

uint8_t // Unsigned 8-bit variable
int8_t // Signed 8-bit variable
uint32_t // Unsigned 32-bit variable

You'll have to either use the avr-libc typedefs, or alias them to your own type naming scheme.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you right :oops:

i didn't included the .h that defined the u08 and u16

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now the question is that is it nice to include other headers in a .h file, or should the .h file be included last in a .c file where all other needed headers are included.

I've been under assumption no, but a single exception to this was said to be required in a C++ object oriented programming course.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jepael wrote:
Now the question is that is it nice to include other headers in a .h file, or should the .h file be included last in a .c file where all other needed headers are included.
I've seen it done both ways. In general, it's fine to include headers in headers. However, to protect from "redefinition" errors, you will see folks do the following:
/* MyHeader.h */

#ifndef __myheader_h__
#define __myheader_h__

. . . rest of header text . . .

#endif /* __myheader_h__ */

This way, if the header is included more than once, the second (and subsequent) includes will not cause errors.

Stu

Edit 1: PS: I've been known to split type definitions and function prototypes into separate headers so I could include types without getting the function prototypes. Of course, in C++, this is not practical (or desirable) in most cases.

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Now the question is that is it nice to include other headers in a .h file, or should the .h file be included last in a .c file where all other needed headers are included.

stu_san says he's seen it done both ways. I'll go farther and say I've seen endless pointless religious arguments over which is the right way. As my brother-in-law the USAF Lt. Col. says: "There's the right way, the wrong way, and the Army way." The point being consistency has benefits over academic "correctness". So, pick the ranc80 way and stick to it.

FWIW, the dbc way is exactly like stu_san's #ifndef example, applied with religious regularity.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah I also do the protective wrapper #ifndef.

And to be honest, I've always avoided #includes in header files, which makes it an awful headache to include all the headers required by a certain header - most commonly ones with standard types like uint8_t etc.

So I think I'll change my habits and do includes in headers too, it should make my life a bit easier.

It would also enable me to do some interesting tricks, like having multiple targets for a system, like including target.h would really include target_pc.h or target_avr.h and the like.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Freaks !
It happens that I have the same kind of problem (or at least I think so)

When trying to compilate a driver file (that is not written by me) I get the following message :
../timer16_drv.h:191: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'timer16_get_counter'

at this line

extern  U16 timer16_get_counter(void);

I though the compiler was not finding the U16 type so I tried the following:
- defining U16 as

#define U16 uint16_t

- replacing every U16 by a simple type (int)
- adding the libc.a in the linker

But I always get the same error !!!
I really do not find where it comes from...
Could you please help me ???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read the thread a bit more carefully.

Ran had omitted that does the uint16_t ...

You have just called U16 a uint16_t, but probably also have omitted the header file.

Regarding headers:
if your project has several .C files project1.c project2.c project3.c ...

you can put all your "usual" system headers in a single "project.h" and subsequently #include only "project.h"

You may well have some unnecessary includes but at least they are all in one place.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

arg...

Thank you David it was that! I did not include the header in the right place.
Anyway, thanks also for your advice about headers including!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all...

Im getting this error message too, but all im trying to do is declare a new class.
the error
expected '=', ',', ';', 'asm' or '__attribute__' before
is comming up in the header file which looks like this...

#ifndef TESTME_H_
#define TESTME_H_

class testMe
{
public:
testMe();
virtual ~testMe();
};

#endif /* TESTME_H_ */

any ideas...please?!?!

thanks
Sam

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look at the error line #.

I guess that avr-gcc is expecting a C program.
Does it complain about "virtual" or "class"

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David.
Thanks for replying to both of my posts!
maybe avr-gcc is expecting a C program, im using Eclipse and I have the compiler command as arm-elf-g++.exe but to be honest it doesnt seam to make much difference what I choose, I think my problem is the make file.
Sam

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ps: the error line # is on

class testMe{

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

By default avr-gcc will pass .c files to the C compiler and .C files to the C++ compiler - so maybe try renaming the file with an upper case C extension?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

but where is the right place? i am confused. i did include into my .c file but still this error appears

stamm0 wrote:
arg...

Thank you David it was that! I did not include the header in the right place.
Anyway, thanks also for your advice about headers including!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

spartakuskus wrote:
but where is the right place? i am confused. i did include into my .c file but still this error appears

Please show use the code (using the Code tag) were the problem is.
stdint.h needs to be seen be all files that use a definition in that header.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A missing include of is not the one and only possibility for this error. In fact there are lots of possibilities. So post your code, or absolutely no one can help you.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wow that's fast! this is my first try on avr controllers :(
here is my poor code

#include "config.h"

#include 
#include 
#include "timer16_drv.h"


int main(void)
{
	Timer16_select(timer16_1);
	Timer16_set_compare_a(255);
	Timer16_set_compare_b(127);
	
	Timer16_set_mode_output_a(TIMER16_COMP_MODE_NORMAL);
	Timer16_set_mode_output_b(TIMER16_COMP_MODE_NORMAL);

	Timer16_set_waveform_mode(TIMER16_WGM_NORMAL);


	Timer16_set_clock(TIMER16_CLKIO_1024);


	while (1);

}

timer16_drv is a library from atmel site for at90can

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which line is the problem on?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the error is in timer16_drv.h because there u16 and u8 is used

../timer16_drv.h:475: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'timer16_get_counter'

extern  U16 timer16_get_counter(void);

i already tried to include stdint.h there but it makes no difference

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You really are pushing the patience of the gentlemen answering you above to the limit, spartakuskus. They love helping other people out, but they do not like to play hide-and-seek.

You have an error message. It shows a filename and a line number. Copy that error message and quote it verbatim here. Attach the file mentioned in the message to a post here.

If I should be guessing, based on your last post above where you talk about "u8" but show code that mentions "U8", I'd say you need to be meticolous with the casing of things when programming in C.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i already tried to include stdint.h there but it makes no difference


-- If you are going to use the types from , then why not use them? I.e. uint16_t instead of U16 or u16?
-- "If your eye causes you to stumble, throw it out; ...". Us old guys just say "unsigned int", or maybe "unsigned short" or "unsigned short int". The same wording that a compiler uses in Chapter 2 of the doc, "Data Types".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry, i thought it would be to long

///******************************************************************************
//! @file $RCSfile: timer16_drv.h,v $
//!
//! Copyright (c) 2007 Atmel.
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the prototypes and the macros of the
//!        low level functions (drivers) of:
//!             - 16-bit timer(s)
//!             - for AT90CAN128/64/32.
//!
//! This file can be parsed by Doxygen for automatic documentation generation.
//! This file has been validated with AVRStudio-413528/WinAVR-20070122.
//!
//! @version $Revision: 3.20 $ $Name: jtellier $
//!
//! @todo
//! @bug
//******************************************************************************

#ifndef _TIMER16_DRV_H_
#define _TIMER16_DRV_H_

//_____ I N C L U D E S ________________________________________________________

#include "config.h"


//_____ G E N E R A L    D E F I N I T I O N S _________________________________

#ifndef FOSC
#  error  You must define FOSC in "config.h" file
#endif
    // ----------
#ifndef TIMER16_1            // 16-bit TIMER 1 Defintion
#define TIMER16_1       0x01
#endif
#ifndef TIMER16_3            // 16-bit TIMER 3 Defintion
#define TIMER16_3       0x03
#endif
#ifndef BOTH_TIMER16         // Both the 16-bit TIMERs Defintion
#define BOTH_TIMER16    0xFF
#endif

//_____ M A C R O S ____________________________________________________________

    // ---------- To order the loading (reading) of 16-bit registers
#define Timer16_get_counter()       ( timer16_get_counter() )        // c.f. "timer16_drv.c" file
#define Timer16_get_capture()       ( timer16_get_capture() )        // c.f. "timer16_drv.c" file
    // ---------- Two ways to have a look on the things
#define Timer16_set_pwm_a(value)    ( Timer16_set_compare_a(value) ) // c.f. above !
#define Timer16_set_pwm_b(value)    ( Timer16_set_compare_b(value) ) // c.f. above !
#define Timer16_set_pwm_c(value)    ( Timer16_set_compare_c(value) ) // c.f. above !
#define Timer16_get_pwm_a()         ( Timer16_get_compare_a() )      // c.f. above !
#define Timer16_get_pwm_b()         ( Timer16_get_compare_b() )      // c.f. above !
#define Timer16_get_pwm_c()         ( Timer16_get_compare_c() )      // c.f. above !
    // ---------- If no clock, the timer is off !
#define Timer16_off()                 Timer16_set_clock(TIMER16_NO_CLOCK)

//_____ D E F .  &   M A C R O S   for   H W   C O N F . _______________________

    //----- CARE WITH THE ORDER WHEN 16-BIT REGISTERS ARE READ
    //      ==================================================
    //----- For sensitive 16-bit registers (c.f. temporary reg), the macros are:
    //-----     *  Timer16_get_nnn_low()
    //-----     *  Timer16_get_nnn_high()
    //----- For instance, in your main, do not write:
    //-----     short_temp = ((Timer16_get_nnn_high())<<8) | (Timer16_get_nnn_low());
    //-----   or
    //-----     short_temp = (Timer16_get_nnn_low()) | ((Timer16_get_nnn_high())<<8);
    //-----   because IAR and ImageCraft doesn't evaluate the operandes in the same order!
    //-----
    //----- The good way to write a READ (load) sequence is in 2 times:
    //-----     short_temp  =  Timer16_get_nnn_low();
    //-----     short_temp |= (Timer16_get_nnn_high() << 8 );
    //-----
    //----- Otherwise a macro "Timer16_get_nnn()" exits and call "timer16_get_counter()" function

#ifndef USE_TIMER16
#       error You must define USE_TIMER16 to TIMER16_1 or TIMER16_3 or BOTH_TIMER16 in "config.h" file
#   elif (USE_TIMER16 == TIMER16_1)        //!< 16-bit TIMER 1 used
    //!< =================================
    //!< ------ Only TIMER16_1 used ------
    //!< =================================
#       define Timer16_select(timer16_num)     // Empty !
    // ---------- Macros
#       define Timer16_clear()  ( TCCR1B=0, TCCR1A=0, TCCR1C=0, TCNT1H=0, TCNT1L= 0, OCR1AH=0, OCR1AL=0, \
                                  OCR1BH=0, OCR1BL=0, OCR1CH=0, OCR1CL=0, ICR1H=0, ICR1L=0              )
        // ----------
#       define Timer16_set_counter(value)       ( TCNT1H = ((U8)(value>>8)), TCNT1L = ((U8)(value)))
#       define Timer16_get_counter_low()        ((U16)(TCNT1L))
#       define Timer16_get_counter_high()       ((U16)(TCNT1H))
        // ----------
#       define Timer16_set_compare_a(value)     ( OCR1AH = ((U8)(value>>8)), OCR1AL = ((U8)(value)))
#       define Timer16_set_compare_b(value)     ( OCR1BH = ((U8)(value>>8)), OCR1BL = ((U8)(value)))
#       define Timer16_set_compare_c(value)     ( OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)))
#       define Timer16_get_compare_a()          ( OCR1A )      // The temporary register is not used
#       define Timer16_get_compare_b()          ( OCR1B )      // The temporary register is not used
#       define Timer16_get_compare_c()          ( OCR1C )      // The temporary register is not used
        // ----------
#       define Timer16_set_capture(value)       { ICR1H = ((U8)(value>>8)); ICR1L = ((U8)(value)); }
#       define Timer16_get_capture_low()        ((U16)(ICR1L))
#       define Timer16_get_capture_high()       ((U16)(ICR1H))
        // ----------
#       define Timer16_set_mode_output_a(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM1A0) )
#       define Timer16_set_mode_output_b(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM1B0) )
#       define Timer16_set_mode_output_c(conf)  ( TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM1C0) )
#       define Timer16_get_mode_output_a()      ((TCCR1A & TIMER16_COMP_MODE_MASK_A) >> COM1A0 )
#       define Timer16_get_mode_output_b()      ((TCCR1A & TIMER16_COMP_MODE_MASK_B) >> COM1B0 )
#       define Timer16_get_mode_output_c()      ((TCCR1A & TIMER16_COMP_MODE_MASK_C) >> COM1C0 )
        // ----------
#       define Timer16_set_waveform_mode(conf)  { TCCR1A = (TCCR1A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM10); \
                                                  TCCR1B = (TCCR1B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM12)  }
#       define Timer16_get_waveform_mode()     (((TCCR1A & TIMER16_WGM_RA_MASK) >> WGM10) |         \
                                               (((TCCR1B & TIMER16_WGM_RB_MASK) >> WGM12) << 0x2)   )
        // ----------
#       define Timer16_set_clock(value)        ( TCCR1B = (TCCR1B & (~TIMER16_CLK_MASK)) | (value << CS10) )
#       define Timer16_get_clock()            (((TCCR1B & TIMER16_CLK_MASK) >> CS10) )
        // ----------
#       define Timer16_set_input_filter()      ( TCCR1B |=  (1<<ICNC1) )
#       define Timer16_clear_input_filter()    ( TCCR1B &= ~(1<<ICNC1) )
#       define Timer16_get_input_filter()      ((TCCR1B  &  (1<<ICNC1)) >> ICNC1 )
    // ----------
#       define Timer16_set_input_rising_edge() ( TCCR1B |=  (1<<ICES1) )
#       define Timer16_set_input_falling_edge()( TCCR1B &= ~(1<<ICES1) )
#       define Timer16_get_input_capture_edge()((TCCR1B &   (1<<ICES1)) >> ICES1 )
    // ----------
#       define Timer16_set_compare_force_a()   ( TCCR1C |=  (1<<FOC1A) )
#       define Timer16_set_compare_force_b()   ( TCCR1C |=  (1<<FOC1B) )
#       define Timer16_set_compare_force_c()   ( TCCR1C |=  (1<<FOC1C) )
#       define Timer16_clear_compare_force_a() ( TCCR1C &= ~(1<<FOC1A) )
#       define Timer16_clear_compare_force_b() ( TCCR1C &= ~(1<<FOC1B) )
#       define Timer16_clear_compare_force_c() ( TCCR1C &= ~(1<<FOC1C) )
#       define Timer16_get_compare_force_a()   ((TCCR1C  &  (1<<FOC1A)) >> FOC1A )
#       define Timer16_get_compare_force_b()   ((TCCR1C  &  (1<<FOC1B)) >> FOC1B )
#       define Timer16_get_compare_force_c()   ((TCCR1C  &  (1<<FOC1C)) >> FOC1C )
    // ----------
#       define Timer16_overflow_it_enable()    ( TIMSK1 |=  (1<<TOIE1)  )
#       define Timer16_overflow_it_disable()   ( TIMSK1 &= ~(1<<TOIE1)  )
#       define Timer16_compare_a_it_enable()   ( TIMSK1 |=  (1<<OCIE1A) )
#       define Timer16_compare_a_it_disable()  ( TIMSK1 &= ~(1<<OCIE1A) )
#       define Timer16_compare_b_it_enable()   ( TIMSK1 |=  (1<<OCIE1B) )
#       define Timer16_compare_b_it_disable()  ( TIMSK1 &= ~(1<<OCIE1B) )
#       define Timer16_compare_c_it_enable()   ( TIMSK1 |=  (1<<OCIE1C) )
#       define Timer16_compare_c_it_disable()  ( TIMSK1 &= ~(1<<OCIE1C) )
#       define Timer16_capture_it_enable()     ( TIMSK1 |=  (1<<ICIE1)  )
#       define Timer16_capture_it_disable()    ( TIMSK1 &= ~(1<<ICIE1)  )
#       define Timer16_get_overflow_it_mask()  ((TIMSK1  &  (1<<TOIE1) ) >> TOIE1  )
#       define Timer16_get_compare_a_it_mask() ((TIMSK1  &  (1<<OCIE1A)) >> OCIE1A )
#       define Timer16_get_compare_b_it_mask() ((TIMSK1  &  (1<<OCIE1B)) >> OCIE1B )
#       define Timer16_get_compare_c_it_mask() ((TIMSK1  &  (1<<OCIE1C)) >> OCIE1C )
#       define Timer16_get_capture_it_mask()   ((TIMSK1  &  (1<<ICIE1) ) >> ICIE1  )
    // ----------
#       define Timer16_clear_overflow_it()     ( TIFR1 |=  (1<<TOV1)  )
#       define Timer16_clear_compare_a_it()    ( TIFR1 |=  (1<<OCF1A) )
#       define Timer16_clear_compare_b_it()    ( TIFR1 |=  (1<<OCF1B) )
#       define Timer16_clear_compare_c_it()    ( TIFR1 |=  (1<<OCF1C) )
#       define Timer16_clear_capture_it()      ( TIFR1 |=  (1<<ICF1)  )
#       define Timer16_get_overflow_it()       ((TIFR1  &  (1<<TOV1) ) >> TOV1  )
#       define Timer16_get_compare_a_it()      ((TIFR1  &  (1<<OCF1A)) >> OCF1A )
#       define Timer16_get_compare_b_it()      ((TIFR1  &  (1<<OCF1B)) >> OCF1B )
#       define Timer16_get_compare_c_it()      ((TIFR1  &  (1<<OCF1C)) >> OCF1C )
#       define Timer16_get_capture_it()        ((TIFR1  &  (1<<ICF1) ) >> ICF1  )

#   elif USE_TIMER16 == TIMER16_3          //!< 16-bit TIMER 3 used
    //!< =================================
    //!< ------ Only TIMER16_3 used ------
    //!< =================================
#       define Timer16_select(timer16_num)     // Empty !
    // ---------- Macros
#       define Timer16_clear()  { TCCR3B=0; TCCR3A=0; TCCR3C=0; TCNT3H=0; TCNT3L= 0; OCR3AH=0; OCR3AL=0; \
                                  OCR3BH=0; OCR3BL=0; OCR3CH=0; OCR3CL=0; ICR3H=0, ICR3L=0;              }
        // ----------
#       define Timer16_set_counter(value)       ( TCNT3H = ((U8)(value>>8)), TCNT3L = ((U8)(value)))
#       define Timer16_get_counter_low()        ((U16)(TCNT3L))
#       define Timer16_get_counter_high()       ((U16)(TCNT3H))
        // ----------
#       define Timer16_set_compare_a(value)     { OCR3AH = ((U8)(value>>8)); OCR3AL = ((U8)(value)); }
#       define Timer16_set_compare_b(value)     { OCR3BH = ((U8)(value>>8)); OCR3BL = ((U8)(value)); }
#       define Timer16_set_compare_c(value)     { OCR3CH = ((U8)(value>>8)); OCR3CL = ((U8)(value)); }
#       define Timer16_get_compare_a()          ( OCR3A )      // The temporary register is not used
#       define Timer16_get_compare_b()          ( OCR3B )      // The temporary register is not used
#       define Timer16_get_compare_c()          ( OCR3C )      // The temporary register is not used
        // ----------
#       define Timer16_set_capture(value)       { ICR3H = ((U8)(value>>8)); ICR3L = ((U8)(value)); }
#       define Timer16_get_capture_low()        ((U16)(ICR3L))
#       define Timer16_get_capture_high()       ((U16)(ICR3H))
        // ----------
#       define Timer16_set_mode_output_a(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM3A0) )
#       define Timer16_set_mode_output_b(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM3B0) )
#       define Timer16_set_mode_output_c(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM3C0) )
#       define Timer16_get_mode_output_a()      ((TCCR3A & TIMER16_COMP_MODE_MASK_A) >> COM3A0 )
#       define Timer16_get_mode_output_b()      ((TCCR3A & TIMER16_COMP_MODE_MASK_B) >> COM3B0 )
#       define Timer16_get_mode_output_c()      ((TCCR3A & TIMER16_COMP_MODE_MASK_C) >> COM3C0 )
        // ----------
#       define Timer16_set_waveform_mode(conf)  ( TCCR3A = (TCCR3A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM30), \
                                                  TCCR3B = (TCCR3B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM32)  )
#       define Timer16_get_waveform_mode()     (((TCCR3A & TIMER16_WGM_RA_MASK) >> WGM30) |         \
                                               (((TCCR3B & TIMER16_WGM_RB_MASK) >> WGM32) << 0x2)   )
        // ----------
#       define Timer16_set_clock(value)        ( TCCR3B = (TCCR3B & (~TIMER16_CLK_MASK)) | (value << CS30) )
#       define Timer16_get_clock()            (((TCCR3B & TIMER16_CLK_MASK) >> CS30) )
        // ----------
#       define Timer16_set_input_filter()      ( TCCR3B |=  (1<<ICNC3) )
#       define Timer16_clear_input_filter()    ( TCCR3B &= ~(1<<ICNC3) )
#       define Timer16_get_input_filter()      ((TCCR3B  &  (1<<ICNC3)) >> ICNC3 )
    // ----------
#       define Timer16_set_input_rising_edge() ( TCCR3B |=  (1<<ICES3) )
#       define Timer16_set_input_falling_edge()( TCCR3B &= ~(1<<ICES3) )
#       define Timer16_get_input_capture_edge()((TCCR3B &   (1<<ICES3)) >> ICES3 )
    // ----------
#       define Timer16_set_compare_force_a()   ( TCCR3C |=  (1<<FOC3A) )
#       define Timer16_set_compare_force_b()   ( TCCR3C |=  (1<<FOC3B) )
#       define Timer16_set_compare_force_c()   ( TCCR3C |=  (1<<FOC3C) )
#       define Timer16_clear_compare_force_a() ( TCCR3C &= ~(1<<FOC3A) )
#       define Timer16_clear_compare_force_b() ( TCCR3C &= ~(1<<FOC3B) )
#       define Timer16_clear_compare_force_c() ( TCCR3C &= ~(1<<FOC3C) )
#       define Timer16_get_compare_force_a()   ((TCCR3C  &  (1<<FOC3A)) >> FOC3A )
#       define Timer16_get_compare_force_b()   ((TCCR3C  &  (1<<FOC3B)) >> FOC3B )
#       define Timer16_get_compare_force_c()   ((TCCR3C  &  (1<<FOC3C)) >> FOC3C )
    // ----------
#       define Timer16_overflow_it_enable()    ( TIMSK3 |=  (1<<TOIE3)  )
#       define Timer16_overflow_it_disable()   ( TIMSK3 &= ~(1<<TOIE3)  )
#       define Timer16_compare_a_it_enable()   ( TIMSK3 |=  (1<<OCIE3A) )
#       define Timer16_compare_a_it_disable()  ( TIMSK3 &= ~(1<<OCIE3A) )
#       define Timer16_compare_b_it_enable()   ( TIMSK3 |=  (1<<OCIE3B) )
#       define Timer16_compare_b_it_disable()  ( TIMSK3 &= ~(1<<OCIE3B) )
#       define Timer16_compare_c_it_enable()   ( TIMSK3 |=  (1<<OCIE3C) )
#       define Timer16_compare_c_it_disable()  ( TIMSK3 &= ~(1<<OCIE3C) )
#       define Timer16_capture_it_enable()     ( TIMSK3 |=  (1<<ICIE3)  )
#       define Timer16_capture_it_disable()    ( TIMSK3 &= ~(1<<ICIE3)  )
#       define Timer16_get_overflow_it_mask()  ((TIMSK3  &  (1<<TOIE3) ) >> TOIE3  )
#       define Timer16_get_compare_a_it_mask() ((TIMSK3  &  (1<<OCIE3A)) >> OCIE3A )
#       define Timer16_get_compare_b_it_mask() ((TIMSK3  &  (1<<OCIE3B)) >> OCIE3B )
#       define Timer16_get_compare_c_it_mask() ((TIMSK3  &  (1<<OCIE3C)) >> OCIE3C )
#       define Timer16_get_capture_it_mask()   ((TIMSK3  &  (1<<ICIE3) ) >> ICIE3  )
    // ----------
#       define Timer16_clear_overflow_it()     ( TIFR3 |=  (1<<TOV3)  )
#       define Timer16_clear_compare_a_it()    ( TIFR3 |=  (1<<OCF3A) )
#       define Timer16_clear_compare_b_it()    ( TIFR3 |=  (1<<OCF3B) )
#       define Timer16_clear_compare_c_it()    ( TIFR3 |=  (1<<OCF3C) )
#       define Timer16_clear_capture_it()      ( TIFR3 |=  (1<<ICF3)  )
#       define Timer16_get_overflow_it()       ((TIFR3  &  (1<<TOV3) ) >> TOV3  )
#       define Timer16_get_compare_a_it()      ((TIFR3  &  (1<<OCF3A)) >> OCF3A )
#       define Timer16_get_compare_b_it()      ((TIFR3  &  (1<<OCF3B)) >> OCF3B )
#       define Timer16_get_compare_c_it()      ((TIFR3  &  (1<<OCF3C)) >> OCF3C )
#       define Timer16_get_capture_it()        ((TIFR3  &  (1<<ICF3) ) >> ICF3  )

#   elif USE_TIMER16 == BOTH_TIMER16   //!< Both the 16-bit TIMERs
    //!< =========================================
    //!< ------ Both TIMER16_1 & 3 are used ------
    //!< =========================================
        extern U8 timer16_selected;         // $$$-- EXTERNAL DECLARATION --$$$
#       define Timer16_select(timer16_num)     (timer16_selected=timer16_num)
    // ---------- Macros
#       define Timer16_clear()              ((timer16_selected==TIMER16_1)? \
                                                (TCCR1B=0, TCCR1A=0, TCCR1C=0, TCNT1H=0, TCNT1L= 0, OCR1AH=0, OCR1AL=0, \
                                                 OCR1BH=0, OCR1BL=0, OCR1CH=0, OCR1CL=0, ICR1H=0, ICR1L=0 )             \
                                                : \
                                                (TCCR3B=0, TCCR3A=0, TCCR3C=0, TCNT3H=0, TCNT3L= 0, OCR3AH=0, OCR3AL=0, \
                                                 OCR3BH=0, OCR3BL=0, OCR3CH=0, OCR3CL=0, ICR3H=0, ICR3L=0 )             )
        // ----------
#       define Timer16_set_counter(value)   ((timer16_selected==TIMER16_1)? \
                                                (TCNT1H = ((U8)(value>>8)), TCNT1L = ((U8)(value)) ) \
                                                : \
                                                (TCNT3H = ((U8)(value>>8)), TCNT3L = ((U8)(value)) ) )
#       define Timer16_get_counter_low()    ((timer16_selected==TIMER16_1)? ((U16)(TCNT1L)) : ((U16)(TCNT3L)) )
#       define Timer16_get_counter_high()   ((timer16_selected==TIMER16_1)? ((U16)(TCNT1H)) : ((U16)(TCNT3H)) )
        // ----------
#       define Timer16_set_compare_a(value) ((timer16_selected==TIMER16_1)? \
                                                (OCR1AH = ((U8)(value>>8)), OCR1AL = ((U8)(value)) ) \
                                                : \
                                                (OCR3AH = ((U8)(value>>8)), OCR3AL = ((U8)(value)) ) )
#       define Timer16_set_compare_b(value) ((timer16_selected==TIMER16_1)? \
                                                (OCR1BH = ((U8)(value>>8)), OCR1BL = ((U8)(value)) ) \
                                                : \
                                                (OCR3BH = ((U8)(value>>8)), OCR3BL = ((U8)(value)) ) )
#       define Timer16_set_compare_c(value) ((timer16_selected==TIMER16_1)? \
                                                (OCR3CH = ((U8)(value>>8)), OCR3CL = ((U8)(value)) ) \
                                                : \
                                                (OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)) ) )
#       define Timer16_get_compare_a()      ((timer16_selected==TIMER16_1)? (OCR1A) : (OCR3A) )   // The temporary register is not used
#       define Timer16_get_compare_b()      ((timer16_selected==TIMER16_1)? (OCR1B) : (OCR3B) )   // The temporary register is not used
#       define Timer16_get_compare_c()      ((timer16_selected==TIMER16_1)? (OCR1C) : (OCR3C) )   // The temporary register is not used
        // ----------
#       define Timer16_set_capture(value)   ((timer16_selected==TIMER16_1)? \
                                                (ICR1H = ((U8)(value>>8)), ICR1L = ((U8)(value))) \
                                                : \
                                                (ICR3H = ((U8)(value>>8)), ICR3L = ((U8)(value))) )
#       define Timer16_get_capture_low()    ((timer16_selected==TIMER16_1)? ((U16)(ICR1L)) : ((U16)(ICR3L)) )
#       define Timer16_get_capture_high()   ((timer16_selected==TIMER16_1)? ((U16)(ICR1H)) : ((U16)(ICR3H)) )
        // ----------
#       define Timer16_set_mode_output_a(conf)  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM1A0)) \
                                                    : \
                                                    (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_A)) | (conf << COM3A0)) )
#       define Timer16_set_mode_output_b(conf)  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM1B0)) \
                                                    : \
                                                    (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_B)) | (conf << COM3B0)) )
#       define Timer16_set_mode_output_c(conf)  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1A = (TCCR1A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM1C0)) \
                                                    : \
                                                    (TCCR3A = (TCCR3A & (~TIMER16_COMP_MODE_MASK_C)) | (conf << COM3C0)) )
#       define Timer16_get_mode_output_a()   ((timer16_selected==TIMER16_1)? \
                                                ((TCCR1A & TIMER16_COMP_MODE_MASK_A) >> COM1A0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_A) >> COM3A0 ) )
#       define Timer16_get_mode_output_b()   ((timer16_selected==TIMER16_1)? \
                                                ((TCCR1A & TIMER16_COMP_MODE_MASK_B) >> COM1B0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_B) >> COM3B0) )
#       define Timer16_get_mode_output_c()   ((timer16_selected==TIMER16_1)? \
                                                ((TCCR1A & TIMER16_COMP_MODE_MASK_C) >> COM1C0) : ((TCCR3A & TIMER16_COMP_MODE_MASK_C) >> COM3C0) )
        // ----------
#       define Timer16_set_waveform_mode(conf)  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1A = (TCCR1A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM10) , \
                                                     TCCR1B = (TCCR1B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM12) ) \
                                                     : \
                                                    (TCCR3A = (TCCR3A & (~TIMER16_WGM_RA_MASK)) | ((conf &  0x3) << WGM30) , \
                                                     TCCR3B = (TCCR3B & (~TIMER16_WGM_RB_MASK)) | ((conf >> 0x2) << WGM32) ) )
#       define Timer16_get_waveform_mode()   ((timer16_selected==TIMER16_1)? \
                                                (((TCCR1A & TIMER16_WGM_RA_MASK) >> WGM10) | (((TCCR1B & TIMER16_WGM_RB_MASK) >> WGM12) << 0x2)) \
                                                : \
                                                (((TCCR3A & TIMER16_WGM_RA_MASK) >> WGM30) | (((TCCR3B & TIMER16_WGM_RB_MASK) >> WGM32) << 0x2)) )
        // ----------
#       define Timer16_set_clock(value)      ((timer16_selected==TIMER16_1)? \
                                                (TCCR1B = (TCCR1B & (~TIMER16_CLK_MASK)) | (value << CS10)) \
                                                : \
                                                (TCCR3B = (TCCR3B & (~TIMER16_CLK_MASK)) | (value << CS30)) )

#       define Timer16_get_clock()           ((timer16_selected==TIMER16_1)? \
                                                (((TCCR1B & TIMER16_CLK_MASK) >> CS10)) : (((TCCR3B & TIMER16_CLK_MASK) >> CS30)) )
        // ----------
#       define Timer16_set_input_filter()    ((timer16_selected==TIMER16_1)? \
                                                (TCCR1B |= (1<<ICNC1)) : ( TCCR3B |= (1<<ICNC3)) )
#       define Timer16_clear_input_filter()  ((timer16_selected==TIMER16_1)? \
                                                (TCCR1B &= ~(1<<ICNC1)) :  ( TCCR3B &= ~(1<<ICNC3)) )
#       define Timer16_get_input_filter()    ((timer16_selected==TIMER16_1)? \
                                                ((TCCR1B & (1<<ICNC1)) >> ICNC1) : ((TCCR3B & (1<<ICNC3)) >> ICNC3) )
    // ----------
#       define Timer16_set_input_rising_edge()  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1B |= (1<<ICES1)) : (TCCR3B |= (1<<ICES3)) )
#       define Timer16_set_input_falling_edge() ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1B &= ~(1<<ICES1)) : ( TCCR3B &= ~(1<<ICES3)) )
#       define Timer16_get_input_capture_edge() ((timer16_selected==TIMER16_1)? \
                                                    ((TCCR1B & (1<<ICES1)) >> ICES1) : ((TCCR3B & (1<<ICES3)) >> ICES3) )
    // ----------
#       define Timer16_set_compare_force_a()    ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C |= (1<<FOC1A)) : (TCCR3C |= (1<<FOC3A)) )
#       define Timer16_set_compare_force_b()    ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C |= (1<<FOC1B)) : (TCCR3C |= (1<<FOC3B)) )
#       define Timer16_set_compare_force_c()    ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C |= (1<<FOC1C)) : (TCCR3C |= (1<<FOC3C)) )
#       define Timer16_clear_compare_force_a()  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C &= ~(1<<FOC1A)) : (TCCR3C &= ~(1<<FOC3A)) )
#       define Timer16_clear_compare_force_b()  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C &= ~(1<<FOC1B)) : (TCCR3C &= ~(1<<FOC3B)) )
#       define Timer16_clear_compare_force_c()  ((timer16_selected==TIMER16_1)? \
                                                    (TCCR1C &= ~(1<<FOC1C)) : (TCCR3C &= ~(1<<FOC3C)) )
#       define Timer16_get_compare_force_a()    ((timer16_selected==TIMER16_1)? \
                                                    ((TCCR1C & (1<<FOC1A)) >> FOC1A) : ((TCCR3C & (1<<FOC3A)) >> FOC3A) )
#       define Timer16_get_compare_force_b()    ((timer16_selected==TIMER16_1)? \
                                                    ((TCCR1C & (1<<FOC1B)) >> FOC1B) : ((TCCR3C & (1<<FOC3B)) >> FOC3B) )
#       define Timer16_get_compare_force_c()    ((timer16_selected==TIMER16_1)? \
                                                    ((TCCR1C & (1<<FOC1C)) >> FOC1C) : ((TCCR3C & (1<<FOC3C)) >> FOC3C) )
    // ----------
#       define Timer16_overflow_it_enable()     ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 |= (1<<TOIE1)) : (TIMSK3 |= (1<<TOIE3)) )
#       define Timer16_overflow_it_disable()    ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 &= ~(1<<TOIE1)) : (TIMSK3 &= ~(1<<TOIE3)) )
#       define Timer16_compare_a_it_enable()    ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 |= (1<<OCIE1A)) : (TIMSK3 |= (1<<OCIE3A)) )
#       define Timer16_compare_a_it_disable()   ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 &= ~(1<<OCIE1A)) : (TIMSK3 &= ~(1<<OCIE3A)) )
#       define Timer16_compare_b_it_enable()    ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 |= (1<<OCIE1B)) : (TIMSK3 |= (1<<OCIE3B)) )
#       define Timer16_compare_b_it_disable()   ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 &= ~(1<<OCIE1B)) : (TIMSK3 &= ~(1<<OCIE3B)) )
#       define Timer16_compare_c_it_enable()    ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 |= (1<<OCIE1C)) : (TIMSK3 |= (1<<OCIE3C)) )
#       define Timer16_compare_c_it_disable()   ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 &= ~(1<<OCIE1C)) : (TIMSK3 &= ~(1<<OCIE3C)) )
#       define Timer16_capture_it_enable()      ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 |= (1<<ICIE1)) : (TIMSK3 |= (1<<ICIE3)) )
#       define Timer16_capture_it_disable()     ((timer16_selected==TIMER16_1)? \
                                                    (TIMSK1 &= ~(1<<ICIE1)) : (TIMSK3 &= ~(1<<ICIE3)) )
#       define Timer16_get_overflow_it_mask()   ((timer16_selected==TIMER16_1)? \
                                                    ((TIMSK1 & (1<<TOIE1)) >> TOIE1) : ((TIMSK3 & (1<<TOIE3)) >> TOIE3) )
#       define Timer16_get_compare_a_it_mask()  ((timer16_selected==TIMER16_1)? \
                                                    ((TIMSK1 & (1<<OCIE1A)) >> OCIE1A) : ((TIMSK3 & (1<<OCIE3A)) >> OCIE3A) )
#       define Timer16_get_compare_b_it_mask()  ((timer16_selected==TIMER16_1)? \
                                                    ((TIMSK1 & (1<<OCIE1B)) >> OCIE1B) : ((TIMSK3 & (1<<OCIE3B)) >> OCIE3B) )
#       define Timer16_get_compare_c_it_mask()  ((timer16_selected==TIMER16_1)? \
                                                    ((TIMSK1 & (1<<OCIE1C)) >> OCIE1C) : ((TIMSK3 & (1<<OCIE3C)) >> OCIE3C) )
#       define Timer16_get_capture_it_mask()    ((timer16_selected==TIMER16_1)? \
                                                    ((TIMSK1 & (1<<ICIE1)) >> ICIE1) : ((TIMSK3 & (1<<ICIE3)) >> ICIE3) )
    // ----------
#       define Timer16_clear_overflow_it()      ((timer16_selected==TIMER16_1)? \
                                                    (TIFR1 |= (1<<TOV1)) : (TIFR3 |= (1<<TOV3)) )
#       define Timer16_clear_compare_a_it()     ((timer16_selected==TIMER16_1)? \
                                                    (TIFR1 |= (1<<OCF1A)) : (TIFR3 |= (1<<OCF3A)) )
#       define Timer16_clear_compare_b_it()     ((timer16_selected==TIMER16_1)? \
                                                    (TIFR1 |= (1<<OCF1B)) : (TIFR3 |= (1<<OCF3B)) )
#       define Timer16_clear_compare_c_it()     ((timer16_selected==TIMER16_1)? \
                                                    (TIFR1 |= (1<<OCF1C)) : (TIFR3 |= (1<<OCF3C)) )
#       define Timer16_clear_capture_it()       ((timer16_selected==TIMER16_1)? \
                                                    (TIFR1 |= (1<<ICF1)) : (TIFR3 |= (1<<ICF3)) )
#       define Timer16_get_overflow_it()        ((timer16_selected==TIMER16_1)? \
                                                    ((TIFR1 & (1<<TOV1)) >> TOV1) : ((TIFR3 & (1<<TOV3)) >> TOV3) )
#       define Timer16_get_compare_a_it()       ((timer16_selected==TIMER16_1)? \
                                                    ((TIFR1 & (1<<OCF1A)) >> OCF1A) : ((TIFR3 & (1<<OCF3A)) >> OCF3A) )
#       define Timer16_get_compare_b_it()       ((timer16_selected==TIMER16_1)? \
                                                    ((TIFR1 & (1<<OCF1B)) >> OCF1B) : ((TIFR3 & (1<<OCF3B)) >> OCF3B) )
#       define Timer16_get_compare_c_it()       ((timer16_selected==TIMER16_1)? \
                                                    ((TIFR1 & (1<<OCF1C)) >> OCF1C) : ((TIFR3 & (1<<OCF3C)) >> OCF3C) )
#       define Timer16_get_capture_it()         ((timer16_selected==TIMER16_1)? \
                                                    ((TIFR1 & (1<<ICF1)) >> ICF1) : ((TIFR3 & (1<<ICF3)) >> ICF3) )

    #else
        #error USE_TIMER16 definition is not referenced in "timer16_drv.h" file
#endif

//_____ T I M E R   D E F I N I T I O N S ______________________________________

    // ---------- Pre-definitions for "conf" field for Timer16_set(get)_mode_output_x(conf) macros
#define TIMER16_COMP_MODE_NORMAL    (0)
#define TIMER16_COMP_MODE_TOGGLE    (1)
#define TIMER16_COMP_MODE_CLEAR_OC  (2)
#define TIMER16_COMP_MODE_SET_OC    (3)
#define TIMER16_COMP_MODE_MASK_A    (3<<COM1A0)
#define TIMER16_COMP_MODE_MASK_B    (3<<COM1B0)
#define TIMER16_COMP_MODE_MASK_C    (3<<COM1C0)
    // ---------- Pre-definitions for "conf" field for Timer16_set_waveform_mode(conf) macro
#define TIMER16_WGM_NORMAL          (0)
#define TIMER16_WGM_CTC_OCR         (4)
#define TIMER16_WGM_CTC_ICR         (12)
#define TIMER16_WGM_PWM_PC8         (1)
#define TIMER16_WGM_PWM_PC9         (2)
#define TIMER16_WGM_PWM_PC10        (3)
#define TIMER16_WGM_PWM_PC_ICR      (10)
#define TIMER16_WGM_PWM_PC_OCR      (11)
#define TIMER16_WGM_PWM_PFC_ICR     (8)
#define TIMER16_WGM_PWM_PFC_OCR     (9)
#define TIMER16_WGM_FAST_PWM8       (5)
#define TIMER16_WGM_FAST_PWM9       (6)
#define TIMER16_WGM_FAST_PWM10      (7)
#define TIMER16_WGM_FAST_PWM_ICR    (14)
#define TIMER16_WGM_FAST_PWM_OCR    (15)
#define TIMER16_WGM_RA_MASK         (3<<WGM10)
#define TIMER16_WGM_RB_MASK         (3<<WGM12)
    // ---------- Pre-definitions for "value" field for Timer16_set_clock(value) macro
#define TIMER16_NO_CLOCK                 (0)
#define TIMER16_CLKIO_BY_1               (1)
#define TIMER16_CLKIO_BY_8               (2)
#define TIMER16_CLKIO_BY_64              (3)
#define TIMER16_CLKIO_BY_256             (4)
#define TIMER16_CLKIO_BY_1024            (5)
#define TIMER16_EXT_CLOCK_FALLING_EDGE   (6)
#define TIMER16_EXT_CLOCK_RISING_EDGE    (7)
#define TIMER16_CLK_MASK                 (7<<CS10)


//_____ D E C L A R A T I O N S ________________________________________________

//------------------------------------------------------------------------------
//  @fn timer16_get_counter
//!
//! This function READ the 16-bit TIMER counter.
//!
//! @warning
//!
//! @param
//!
//! @return 16-bit counter value
//!
extern  U16 timer16_get_counter(void);

//------------------------------------------------------------------------------
//  @fn timer16_get_capture
//!
//! This function READ the 16-bit TIMER capture register.
//!
//! @warning
//!
//! @param
//!
//! @return 16-bit capture value
//!
extern  U16 timer16_get_capture(void);

//______________________________________________________________________________

#endif  // _TIMER16_DRV_H_
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

sorry, i thought it would be to long

Thats why I said "attach it"..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Best guess: the type U16 is unknown to the compiler. You need to include the header file where this type is defined. Hint: it is not stdint.h.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

shame on me, now i got it!
there is a compiler.h for this library

sorry, sometimes i am a fool
anyway thanks for your advices!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using the same Timer16_drv.h library, but in my case I am using both timers (BOTH_TIMER16).

I am using all compare interrupts (a,b & c) on Timer3, and only the last one (c) on Timer1. The tricky thing is that while Timer3 a, b & c are used in Toggle mode and I use the output directly on the pins (OC3A, OC3B and OC3C pins), Timer1_c is used in Normal mode and I am using the interrupt routine to turn on/off a different pin (not OC1C).

First problem that I've experienced is the compiler message "There is a missing reference to timer16_selected" since in Timer16_drv.h it is defined as extern. This didn't make too much sense to me, so I removed the "extern" and the compiler stopped complaining.

Now I can see that the toggling of the pin OC3C doesn't work - like the normal mode of OC1C has interferred in some way, although I use Timer16_select(TIMER16_3); or Timer16_select(TIMER16_1); correspondingly. I am afraid that the library isn't working optimally when in BOTH_TIMER16 mode.

Any ideas on what might be the problem?

Regards,
P.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Funny stuff - I defined now U8 timer16_selected as external in timer16_drv.h and at the same time defined U8 timer16_selected in main.c as originator. This extended the scope of the variable and now I can trace it with the Watch in the debugger.

The funny thing is that in the code below, the debugger jumps over the first Timer16_select statement (in the Watch window timer16_selected is still 0), but executes the second one below (timer16_selected becomes 1) ???

	// Enable and config the Timer16_3
	Timer16_select(TIMER16_3); // Debugger skips over
	Timer16_clear();
	Timer16_overflow_it_disable();
	Timer16_compare_a_it_disable();
	Timer16_compare_b_it_disable();
	Timer16_compare_c_it_disable();
	Timer16_capture_it_disable();
	Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR);
	Timer16_set_compare_a(8-1);
	Timer16_set_compare_b(8-1);
	Timer16_set_compare_c(8-1);
	Timer16_set_clock(TIMER16_CLKIO_BY_1024);

	// Enable and config the Timer16_1
	Timer16_select(TIMER16_1); // Executes
	Timer16_clear();
	Timer16_overflow_it_disable();
	Timer16_compare_c_it_disable();
	Timer16_capture_it_disable();
	Timer16_set_waveform_mode(TIMER16_WGM_CTC_OCR);
	Timer16_set_mode_output_c(TIMER16_COMP_MODE_NORMAL);	// Output OC1C is not used, only the interrupt
	Timer16_set_compare_c(1000-1);
	Timer16_set_clock(TIMER16_CLKIO_BY_1024);

What is going on?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After a bit of thinking - If the debugger skips over the first line, this is just because the compiler acknowledged that TIMER16_3 is used and executed the corresponding commands Timer16_xxx on TIMER16_3.

The second Timer16_select command does execute during run-time, but compiler has already done the whole job and assumed that the timer being used is TIMER16_3, and not TIMER16_1 as stated for the second group of commands.

Is this correclty understood? How is it than possible to use both timers in the BOTH_TIMER16 mode? Is this a compiler error?

Regards,
P.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eventually I found where the problem is - there is in fact a mistake in the Atmel library timer16_drv.h. In the section where both timers 1 & 3 are enabled, the correct definition for Timer16_set_compare_c() should be:

#       define Timer16_set_compare_c(value) ((timer16_selected==TIMER16_1)? \
                                                (OCR1CH = ((U8)(value>>8)), OCR1CL = ((U8)(value)) ) \
                                                : \
                                                (OCR3CH = ((U8)(value>>8)), OCR3CL = ((U8)(value)) ) )

In the original library the register names for timer1 and timer3 are exchanged.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll use the post for a while to expose the same problem.
I have exactly the same problem (from the post name) and the stdint.h is included.
my difference is that I use
extern uint8_t var1;
and after replace the uint8_t for just an int, the error disappears.
what could it be?

thanks everyone!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

what could it be?

Until you show code I'll go for the usual phase-of-the-moon or line 42. What happens if you try to cut away stuff until you have a 10-line test program that still exposes the problem? If you haven't nailed it down by then, post that 10-liner here.

And, as always when there is a "strange" syntax error - what is on the line(s) before the reported line?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

and the stdint.h is included.

You may think it is - the signs are that it isn't at the point that line is parsed. Do you have any conditional code with #if/#ifdef used? Could the declaration come before the point of inclusion?

I guess until you follow Johan's advice we can do nothing more but guess?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry about the cross post, initially was at the other, but then find the same problem here where the post name is more representative than the other and try to ask too.
Here is the code.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are #include'ing a .c file?!? But why's it called .c as it's just got extern declarations so it's a .h isn't it??

In fact nothing in any of the supplied code actually defines var1/var2/var3 ??

Anyway I don't get the error you are seeing. The code all builds in fact and all I see is:

avr-gcc  -mmcu=atmega2560 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT test.o -MF dep/test.o.d  -c  ../test.c
../test.c:25: warning: 'TEST_init_mem_values' defined but not used
avr-gcc -mmcu=atmega2560 -Wl,-Map=test.map test.o     -o test.elf
e:/winavr-20100110/bin/../lib/gcc/avr/4.3.3/../../../../avr/lib/avr6/crtm2560.o:(.init9+0x0): undefined reference to `main'
make: *** [test.elf] Error 1
Build failed with 1 errors and 1 warnings...

But that link error is to be expected as there is no main().

If your .rar was supposed to be a "cut down" test program then I'd suggest you cut it TOO far by not including main() and not including the varN variable definitions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
You are #include'ing a .c file?!? But why's it called .c as it's just got extern declarations so it's a .h isn't it??

Here I was following a tutorial of AVRfreaks, "header files should declare, not define" so, because I was defining the external variables... changed it to C.
am I wrong?

clawson wrote:

In fact nothing in any of the supplied code actually defines var1/var2/var3 ??

The variables are defined on globalVariable.c
or that is where the problem beggins??

clawson wrote:

If your .rar was supposed to be a "cut down" test program then I'd suggest you cut it TOO far by not including main() and not including the varN variable definitions.

The main is defined in the Main_.c file... :?:
please verify this for me...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

because I was defining the external variables... changed it to C.
am I wrong?


yes you were wrong. If it starts "extern" it is a DELCARATION not a definition so you weren't defining anything. A declaration is just there to let the compiler know the type(s) of anything involved. The definition is where you say "I'd like some storage put aside for one of these" (it's also a declaration (of type) in fact).
Quote:

The variables are defined on globalVariable.c
or that is where the problem beggins??

No they aren't "defined". As I say they are only declared and as such it should be a .h file not a .c file. In fact if you ever find yourself using "#include "something.c"" there is a 99% chance you are doing something wrong. (advanced readers will know the reason for leaving 1% in that but let's not dwell on that here).
Quote:

The main is defined in the Main_.c file...

That statement is true. rather sadly the .aps file does not list Main_.c as one of the components to be built - so it wasn't.

I added Main_.c to the list of "Source Files" and now when I build I get:

AVR Memory Usage
----------------
Device: atmega2560

Program:     288 bytes (0.1% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)


Build succeeded with 1 Warnings...

No sign of your error about uint8_t being undefined?

But if I had to add Main_.c to the project to even make it build then clearly this is NOT the project you were having problems with so I rather fear this whole exercise may have been a waste of time. Perhaps you'd like to post the actual project where the error is seen? Only this time test that you are seeing the error before you .rar the files.

But before then maybe take a step back to see if you understand the whole declaration/defintion thing and what should be in .c files and what should be in .h files.

Cliff

PS Oh dear God I've just now realised that Main_.c itself has a #include of "test.c" - this is SERIOUS confusion! The same .c file will be built twice - once as a result of it's appearance in the Source Files of the .aps and once as an indirect result of it being #include'd in Main_.c (itself a file with a very odd name!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems to me that all you actually need for this entire thing is:

//gvar.h
#include 
extern uint8_t var, var2, var;
//main.c
#include "gvar.h"
void test_init_vars(void) {
  var1                    =0x0c;
  var2                    =0x00;
  var3                    =0x00;
}

int main(void) {
 test_init_vars();
}
//gvar.c
#include "gvar.h"
uint8_t var1, var2, var3;

Which is an example that splits the use of global variables from where they are defined.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you Cliff, you where very clear, (even the part that God was involved) :)
I started the project again, because after the first try, I start to follow the tutorial, and that was the moment that I made changes on the file name, maybe that was the reason for the main wasn’t included on the compilation. (and the main was moved to other file in the process)
Again, thanks for the help.