Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Atmega128 Teacup #312

Open
shakenov-chinga opened this issue Nov 5, 2018 · 5 comments
Open

Atmega128 Teacup #312

shakenov-chinga opened this issue Nov 5, 2018 · 5 comments

Comments

@shakenov-chinga
Copy link

Hello everybody!
I've designed a new board using Atmega128 (no real reasons, just had several of them). I took sanguinololu as an example: everything is almost the same, except pin numbers and heatbed and extruder heater are connected to digital IO, not PWM. Now I am trying to configure and build Teacup using configtool.
What I've done so far is I created arduino_128.h file, where I use MegaCore pin numbers, and created board.myprinter.h file, which is a copy-paste with little necessery changes from sanguinololu board.

Now, the problem is that in arduino_128.h file I can't understand what and how do I assign DIOn_PWM and DIOn_TCCR values for pins. I have a little idea for DIOn_PWM values assignment, from datasheet I got:
#define OC0 DIO12 #define OC1A DIO13 #define OC1B DIO14 #define OC1C DIO15 #define OC2 DIO15 #define OC3A DIO3 #define OC3B DIO4 #define OC3C DIO5
and these values are used in it, but I have no clue what to do with DIOn_TCCR.

Could you please help to understand this of to find some useful source about it.
Thanks in advance.

@triffid
Copy link
Collaborator

triffid commented Nov 6, 2018

#define DIO14_TCCR TCCR1A should work if OC1B is on DIO14.

DIOx_TCCR just a pointer to the timer configuration register so we can determine the appropriate timer to configure when you set the associated pin as a PWM (heater) output.

@shakenov-chinga
Copy link
Author

shakenov-chinga commented Nov 6, 2018

As I can deduce these are values we use for PWM pins. Can someone confirm them, please?

OC0 DIO12 - -
OC1A DIO13 TCCR1A COM1A1
OC1B DIO14 TCCR1A COM1B1
OC1C DIO15 TCCR1A COM1C1
OC2 DIO15 - -
OC3A DIO3 TCCR3A COM3A1
OC3B DIO4 TCCR3A COM3B1
OC3C DIO5 TCCR3A COM3C1

Tried to build using configtool, but got this error:
analog-avr.c:42:3: error: ‘DIDR0’ undeclared (first use in this function)
DIDR0 = analog_mask & 0xFF;
Where its declaration should be?

Edit:
Just looked through register summary in atmeag128 datasheet, it seems to be that there is no any DIDR registers.

@shakenov-chinga
Copy link
Author

shakenov-chinga commented Nov 6, 2018

Hi everyone,
Seems like atmega128 as well as atmega16 (and maybe other atmegas) doesn't need DIDR0 register to use ADC, so I just added #ifdef DIDR0 macro in analog-avr.c. I hope this will work.
Also I had little problems with timer-avr.c, because compiler complains that TIMSK1 didn't exist, so I had to use macros again to use TIMSK register instead, like:
#ifdef TIMSK
TIMSK = 0;
#else
TIMSK1 = 0;
#endif
Now I have problems with heater-avr.c file, because it uses, as I can understand, timer/counter with pwm little differently. Can anyone tell, please, what is the logic in heater_init() function in this file and why so many TCCR registers are used? Is it there to support several possible extruders?

Also, as I can see, TIMSK1 register is used in timer-avr.c, and in heater-avr.c other TIMSK0, TIMSK2 are used, but atmega128 has only TIMSK, which I already use in timer-avr.c, and ETIMSK, which I don't know is useful or not. Is there any walkaround or direct solutions?

@thomaskilian
Copy link

I'm struggling with a similar issue. I partly figured it out. The timers are preset to run at the desired PWM (fast) speed. Down below in the part

  if (PWM_TYPE(pwm, pin) == HARDWARE_PWM) {               \

it will set the appropriate timer registers to take care of the PWM.

@Wurstnase
Copy link
Collaborator

Wurstnase commented Nov 25, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants