1

I am using a ZCD circuit controlling a TRIAC. Now I am using Dimmer library for this purpose. It works fine with ATMega 328 but whenever I try to upload the code in ATMega 128 using Arduino IDE this error pops up:

Arduino: 1.8.4 (Windows 10), Board: "ATmega128, 2.7v, Disabled (default), 16 MHz external"

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp: In member function 'void Dimmer::begin(uint8_t, bool)':

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:15:20: error: 'TCCR2A' was not declared in this scope

 #define _TCCRxA(X) TCCR ## X ## A

                    ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:16:19: note: in expansion of macro '_TCCRxA'

 #define TCCRxA(X) _TCCRxA(X)

                   ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:157:5: note: in expansion of macro 'TCCRxA'

     TCCRxA(DIMMER_TIMER) = TCCRxA_VALUE;         // Timer config byte A

     ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:17:20: error: 'TCCR2B' was not declared in this scope

 #define _TCCRxB(X) TCCR ## X ## B

                    ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:18:19: note: in expansion of macro '_TCCRxB'

 #define TCCRxB(X) _TCCRxB(X)

                   ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:158:5: note: in expansion of macro 'TCCRxB'

     TCCRxB(DIMMER_TIMER) = TCCRxB_VALUE;         // Timer config byte B

     ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:19:20: error: 'TIMSK2' was not declared in this scope

 #define _TIMSKx(X) TIMSK ## X

                    ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:20:19: note: in expansion of macro '_TIMSKx'

 #define TIMSKx(X) _TIMSKx(X)

                   ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:159:5: note: in expansion of macro 'TIMSKx'

     TIMSKx(DIMMER_TIMER) = 0x02;                 // Timer Compare Match Interrupt Enable

     ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:21:19: error: 'OCR2A' was not declared in this scope

 #define _OCRxA(X) OCR ## X ## A

                   ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:22:18: note: in expansion of macro '_OCRxA'

 #define OCRxA(X) _OCRxA(X)

                  ^

C:\Program Files (x86)\Arduino\libraries\Dimmer-master\src\Dimmer.cpp:160:5: note: in expansion of macro 'OCRxA'

     OCRxA(DIMMER_TIMER) = 100 * 60 / acFreq - 1; // Compare value (frequency adjusted)

     ^

exit status 1
Error compiling for board ATmega128.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any idea what is the issue ?

  • 2
    ATMega328 and ATMega128 are not completely interchangeable .... the header file has either different register names or the registers do not exist in ATMega128 – jsotola Oct 29 '18 at 17:44
  • what core you use? it is possible, it has only different names. I checked the Dimmer library with MightyCore and for Atmega16/32/164 I get errors because they don't have the timer used by the library. but your errors a different. MightyCore doesn't support 128 (although it is in readme) – Juraj Oct 30 '18 at 8:27
  • @Juraj I am using Megacore. I need to use 128 because I need a lot of ports. – TechCreogen Oct 30 '18 at 9:07
  • @jsotola What you have pointed out looks like the problem.. that is obvious. but is there any work around ? – TechCreogen Oct 30 '18 at 9:08
  • I need a lot of ports .... for what purpose? ..... it appears that this is an X-Y problem ..... you may or may not have a misguided solution to a lack of I/O pins and you are asking your question in an effort to make the solution work – jsotola Oct 30 '18 at 16:54
1

The Dimmer library doesn't support Atmega128/164/16/32. It has

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define DIMMER_TIMER 4
#elif defined(__AVR_ATmega32U4__)
#define DIMMER_TIMER 3
#else
#define DIMMER_TIMER 2
#endif

For the Atmega128/164/16/32 it will use timer 2. The main errors are:

'OCR2A' was not declared in this scope
'TCCR2A' was not declared in this scope
'TCCR2B' was not declared in this scope
'TIMSK2' was not declared in this scope

Possible solution:

You could try to use timer 3. Only you need to change the timer number in Dimmer.h and in Dimmer.cpp on line 159 change TIMSKx(DIMMER_TIMER) = 0x02 perhaps to bitSet(ETIMSK, 3);. Check the datasheet. I can't test it, I don't have the chip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.