Coder Social home page Coder Social logo

thomasonw / atmegaxxm1-c1 Goto Github PK

View Code? Open in Web Editor NEW
30.0 9.0 18.0 2.19 MB

Arduino IDE support files for CAN enabled Atmel AVR chips: ATmega64M1, ATmega32M1, ...

License: GNU Lesser General Public License v2.1

C++ 60.37% C 37.92% Assembly 1.71%

atmegaxxm1-c1's Introduction

ATmegaxxM1-C1: Arduino Core for ATmegaxxM1/C1 CPUs

Atmel offers a line of CPUs compatible with the CPUs commonly used in Arduino boards. Some have additional features, such as the ATmega32M1 which includes built in CAN (Control Area Network) hardware.

ATmegaxxM1-C1 is an extension to the Arduino IDE environment enabling several of these CAN containing CPUs.

  • Currently supported CPUs include:
  • ATmega64M1
  • ATmega32M1
  • ATmega16M1

Future:

  • Inclusion of ATmega32C1, ATmega64C1

Enhancements

The ATmegaxxM1/C1 CPUs have some additional features which have allowed for the API to be extended. Additions over the 'standard' Arduino are:

  • Enhancement to ANALOG-READ() --> Additional ADC inputs

  • A9 will return the internal AVR temperature sensor. Caution: The ADC reference MUST first be set to 2.56v via: analogReference(INTERNAL);

  • A10 will return Vcc/4

  • ADO will return results of built in differential amp AMP0 using: (D9 - D8) * GAIN

  • AD1 will return results of built in differential amp AMP1 using: (A4 - A3) * GAIN

  • AD2 will return results of built in differential amp AMP2 using: (D10 - A6) * GAIN

  • analogRead() of Differential amps returns a SIGNED + or - (+511 .. - 511) value depending on the relative voltages of the +&- inputs.

  • When the internal differential amps have been enabled, the existing analog port can still be read individually, however the Digital ports are disables to reduce noise.

  • Enhancement to PIN-MODE() --> Setting up of built in differential amps AMP0..AMP2

  • 1st parameter selected the differential amp to enable. Use: AD0, AD1, or AD2

  • 2nd parameter specific gain to use. Use: GAIN5, GAIN10, GAIN20, GAIN40

  • Example to use ADO (Ports D9 - D8): pinMode(AD0, GAIN20);

  • To disable a differential amp and restore ports to their original use, call pinMode() with the port you wish to use normally

  • Example to restore D9 (and D8), AD0 will be turned off: pinMode(D9, INPUT);

  • Enhancement to ANALOG-WRITE() --> Access to DAC (Digital to Analog Converter)

  • A DAC is optional routed to port 10, use predefined DAC_PORT

  • writing an along value to DAC_PORT will cause the DAC to be enabled and the value used to create a analog voltage

  • DC is 10bits (just like the ADCs). Valid values are from 0..1023

  • the DAC uses the same reference as the ADCs. See analogReferance();

  • Example to set the DAC to 1/2 voltage: analogWrite(DAC_PORT, 512);

  • Change in ANALOG-REFERENCE()

  • When called using INTERNAL, a 2.56v reference is selected vs. the 1.1v on the ATmega328p

  • This is due to the hardware.

  • CAN - See: https://github.com/thomasonw/avr_can for Arduino compatible library

Summary of new Keywords: GAIN5, GAIN10, GAIN20, GAIN40, DAC_PORT

Notes

There are some small hardware differences between the ATmegaxxM1/C1 CPUs and the ATmega328 (used in the Uno). Mostly this will not be an issue, but one should be aware of them, including:

  • The ATmegaxxM1/C1 CPUs only have two timers, TIMER0 and TIMER1. The function TONE uses the 'last timer', in this case TIMER1 (as opposed to TIMER2 in the ATmega328 / Uno)
  • The internal reference voltage is 2.56v, as opposed to 1.1v

Special note concerning PSC ports at power-on. The ATmegaxxM1 CPUs contains a high speed PSC (Power Stage Controller) subsystem. Targeted for high-speed PWM, most commonly in a push-pull configuration. There are three channels for a total of 6 ports. A special feature of the ATmegaxxM1 CPU is the ability to hold those ports at a pre-determined value at initial power-on and/or reset, to prevent unintended actions until such time as the startup code is able to execute.

Fuse PSCRB has been set by default causing all 6 PSC ports to be held LOW until such time as when they are used or reconfigured to a different purpose. **Care should be taken in hardware design NOT to tie these pins to a value other then GND. If there is a need to do so, make sure to use a current limiting resistor. ** The ports affected are: PB0, PB1, PB6, PB7, PC0, PD0 (Arduino ports: D5, D6, A7, A8, D12 & D11)

Though the ATmegaxxC1 does not contain a PSC subsystem, fuse PSCRB is still set - refer to Atmel users document to confirm the behavior of the ATmegaxxC1 CPU with this fuse set.

Port Mapping

alt text

Installation

This is designed for Arduino 1.6.7+

Option 1) Arduino Board Package Manager:

  1. Start Arduino
  2. Open menu File/Preferences
  3. Click the 'window box' to the right of the 'Additional Boards manager URLs:' entry window.
    • This will allow you to add more than one entry
  4. Copy the following URL into the box.
  5. Press OK button to close the data entry window
  6. Press OK button to close the Preferences menu.
  7. Open the Tools/Boards menu and select Boards Manager
  8. Scroll down and click on the 'ATmegaxxM1-C1 by thomasonw version x.x.x' entry
  9. press the Install button

Option 2) Manual Install:

  1. Copy down the ZIP file to your local computer.
  2. Open the Zip File, and copy the entire content to your users local hardware subdirectory. * in Windows, this is: "Libraries/Documents/Arduno/Hardware"
  3. Restart the Arduino IDE

After either is used to install the support files, you can select the new CPUs from the tools/boards menu.

Support for IDE versions released prior to 1.6.7 may be found at: http://smartmppt.blogspot.com/search/label/xxM1-IDE

Versions

v1.0.3 --> Original porting using rather old CORE files. Does NOT implement analogWrite() for DAC. analogRead() of differential ports are not corrected for +/- values (raw ADC count is returned)

v1.0.4 --> Reported to new CORE files from Arduino 1.6.8. Added DAC support. analogRead() of differential ports are not corrected for +/- values (raw ADC count is returned)

v1.0.5 --> pinMode(DAC_PORT,xxx) disconnects DAC from port (is connected by analogWrite(DAC_PORT, xx). analogRead() differential ports corrected for +/- values.

v1.0.6 --> Enabled TONE capability (note, interfers with PWM as it uses the same timer..), corrected SerialWrite IRQ race bug.

v1.0.7 --> Initialize VREF at 1st usage of DAC, restructured to Arduino menu selections, added menu options for PWM initial state (Thank you Geraldjust).

V1.0.8 --> Added support for dedicated 64m1 with Arduino footprint https://www.tindie.com/products/15615/ (By GeraldJust)

V1.0.9 --> Added support for ATmega16M1

CORE files

A major effort for this porting effort is the modification of the CORE include files used by Arduino. There is a separate GitHib repository which contains the edits I have made to enable the ATmegaM1/C1 CPUs: https://github.com/thomasonw/Arduino---CORE-files-for-ATmegaM1-C1-port/tree/master/hardware/arduino/avr/cores/arduino

It is forked from the master Arduino files to allow updating from them as well.

atmegaxxm1-c1's People

Contributors

christophjurczyk avatar falconfour avatar geraldjust avatar per1234 avatar thomasonw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atmegaxxm1-c1's Issues

32m1 Compatibility

Hi, Love the support you brought these uC. But ive been having some issues with the 32m1 uC.

i get the following error trying to burn the bootloader:

avrdude: verification error, first mismatch at byte 0x7e00
         0x00 != 0x11
avrdude: verification error; content mismatch
Error while burning bootloader.

Ive used the 64m1 just fine. ive ran the 64m1 with the int osc. then a external 8mhz and a 16mhz and all those seem fine. But i keep getting this error for the 32m1. Not sure if there is something wrong with the verification for the bits or a fuse is not burn the right way.

Thanks for all your hard work!

Gerald R.

Install Compatibility with Arduino IDE 2.0

Hi there, just wondering if this package is compatible with Arduino IDE 2.0? When I try to install, I'm hit with:

Tool arduino:[email protected] already installed
Tool arduino:[email protected] already installed
Downloading packages
ATmegaM1-C1:[email protected]
Installing platform ATmegaM1-C1:[email protected]
Failed to install platform: 'ATmegaM1-C1:avr:1.0.8'.
Error: 13 INTERNAL: Cannot install platform: installing platform ATmegaM1-C1:[email protected]: extracting archive: open C:\Users\Admin\AppData\Local\Arduino15\tmp\package-1226863038: is a directory

Thanks :)

Typo in project description

Was just telling a friend about this repo & the awesome power of the ATmegaxxM1-C1 series chips... and I noticed a typo in the repo description:

CAN enabled Amtel AVR chips

Tiny little thing, but Atmel** ๐Ÿ˜„

Easy issues are the best, aren't they?

Bootloader source code

Hi!

Could you please upload the actual source code you used when you compiled Optiboot for these AVRs? I'd like to add ATmega16/32/64M1 and ATmega32C1/64C1 to my Optiboot flash repo and was hoping to use the source code (particularly the contents of pin_defs.h) as a template when adding these chips.

Pin change interrupt on D10

The datasheet is wrong on page 88, PCICR, Bit PCIE1 states PCINT[14:8], but this should be PCINT[15:8], because D10 (PC7) corresponds to PCINT15 and this pin does generate an interrupt.

I added pin D10 to the header file like this:

#define digitalPinToPCICRbit(p) ( ((p) == 5  || (p) == 6) || \
                                  ((p) == 8  || (p) == 9) || \
                                  ((p) == 17)             || \
                                  ((p) >= 21 && (p) <=23) ? 0 : \
                                ( ((p) >=  2 && (p) <= 4) || \
                                  ((p) == 12 || (p) ==10) || \
                                  ((p) >= 18 && (p) <=20) ? 1 : \
                                2))


#define digitalPinToPCMSK(p)    ( ((p) == 5  || (p) == 6) || \
                                  ((p) == 8  || (p) == 9) || \
                                  ((p) == 17)             || \
                                  ((p) >= 21 && (p) <=23) ? (&PCMSK0) : \
                                ( ((p) >=  2 && (p) <= 4) || \
                                  ((p) == 12 || (p) ==10) || \
                                  ((p) >= 18 && (p) <=20) ? (&PCMSK1) : \
                                (&PCMSK2)))

and the interrupt works fine.
Is this remark:

// Port D10 does not support Soft Serial

only due to the flaw in data sheet? With this patch it could then be removed.

Problems getting project running under platformio

I created a new project in platformio and did as suggested

command: pio pkg install --library "thomasonw/ATmegaxxM1-C1@^1.0.4"

Resolving megaatmega1280 dependencies...
Library Manager: Installing thomasonw/ATmegaxxM1-C1 @ ^1.0.4
Downloading [####################################] 100%
Unpacking [####################################] 100%
Library Manager: [email protected] has been installed

The resulting platformio.ini

[env:test]
platform = atmelavr
board = ATmegaxxM1-C1
framework = arduino
lib_deps = thomasonw/ATmegaxxM1-C1@^1.0.4

When building I get the error:
UnknownBoard: Unknown board ID 'ATmegaxxM1-C1'

I also tried as board: "ATmegaxxM1", "atmega64m1_16Mhz_xtl"

analogWrite on digital Pins and digitalWrite on analog pins

Hello, I have a problem with the DAC. When I try to write on the D10 with an analogWrite it seems to ignore it.

Example:

#define DAC 10

void setup() {
    pinMode(DAC, OUTPUT); 
}
void loop(){
    analogWrite(DAC, 512);
}

When I physically read the voltage with the multipler the voltage stays fixed at 0.21 volts. I also tried to change the value (ranging from 0 to 1023) and remove pinMode(DAC, OUTPUT) but it doesn't change.

When I instead use digitalWrite(DAC, HIGH) it works.

Moreover I need to set the SLEEP and RESET pins to HIGH but seems like I am missing something, because the voltage stays fixed at 0

#define SLEEP A3
#define RESET A4

void setup() {
    pinMode(SLEEP, OUTPUT); 
    pinMode(RESET, OUTPUT); 
}
void loop(){
    digitalWrite(RESET, HIGH);
    digitalWrite(SLEEP, HIGH);
}

Do you have any ideas if I am missing something?

boards.txt updating

Hey! sorry to bug again. I have been working on a updated board.txt file. So i have made it compatible with the file name you have. Its been compiling just fine. I even added a menu on the board option for the PSC to be OFF, LOW, HIGH.

But when uploading it, ive noticed that its using the arduino avrdude.conf rather then the custom one in the core hardware folder. so i get a error saying the 64m1 is not available.

Here is the new code for the boards.txt:

`
############################################################

menu.clock=Clock
menu.PSC=PSC
menu.variant=Variant

############################################################

AtmegaX1.name=ATmegaX1
AtmegaX1.upload.tool=arduino:avrdude
AtmegaX1.upload.protocol=arduino
AtmegaX1.build.variant=ATmegaxxM1

AtmegaX1.bootloader.tool=arduino:avrdude
AtmegaX1.bootloader.unlock_bits=0x3F
AtmegaX1.bootloader.lock_bits=0x0F

AtmegaX1.menu.variant.64m1=ATmega64m1
AtmegaX1.menu.variant.64m1.build.mcu=atmega64m1
AtmegaX1.menu.variant.64m1.build.board=ATmega64M1
AtmegaX1.menu.variant.64m1.build.name2=atmega64M1
AtmegaX1.menu.variant.64m1.upload.maximum_size=64512
AtmegaX1.menu.variant.64m1.upload.maximum_data_size=4096

AtmegaX1.menu.variant.32m1=ATmega32m1
AtmegaX1.menu.variant.32m1.build.mcu=atmega32m1
AtmegaX1.menu.variant.32m1.build.board=ATmega32M1_16xtl
AtmegaX1.menu.variant.32m1.build.name2=atmega32M1
AtmegaX1.menu.variant.32m1.upload.maximum_size=32256
AtmegaX1.menu.variant.32m1.upload.maximum_data_size=2048

AtmegaX1.menu.PSC.OFF=OFF
AtmegaX1.menu.PSC.OFF.bootloader.extended_fuses=0x3D
AtmegaX1.menu.PSC.LOW=LOW
AtmegaX1.menu.PSC.LOW.bootloader.extended_fuses=0x1D
AtmegaX1.menu.PSC.HGH=HIGH
AtmegaX1.menu.PSC.HIGH.bootloader.extended_fuses=0x05

##############################################################

#make atmegaXXm1 AVR_FREQ=16000000L BAUD_RATE=57600
AtmegaX1.menu.clock.16MHz_external.build.core=arduino
AtmegaX1.menu.clock.16MHz_external.build.f_cpu=16000000L
AtmegaX1.menu.clock.16MHz_external=16MHz External
AtmegaX1.menu.clock.16MHz_external.upload.speed=57600
AtmegaX1.menu.clock.16MHz_external.bootloader.low_fuses=0xFF
AtmegaX1.menu.clock.16MHz_external.bootloader.high_fuses=0xDE
AtmegaX1.menu.clock.16MHz_external.bootloader.file=optiboot/optiboot_{build.name2}_16Mhz.hex

#make atmegaXXm1 AVR_FREQ=16000000L BAUD_RATE=57600
AtmegaX1.menu.clock.8MHz_external.build.core=arduino
AtmegaX1.menu.clock.8MHz_external.build.f_cpu=8000000L
AtmegaX1.menu.clock.8MHz_external=8MHz External
AtmegaX1.menu.clock.8MHz_external.upload.speed=57600
AtmegaX1.menu.clock.8MHz_external.bootloader.low_fuses=0xFF
AtmegaX1.menu.clock.8MHz_external.bootloader.high_fuses=0xDE
AtmegaX1.menu.clock.8MHz_external.bootloader.file=optiboot/optiboot_{build.name2}_8Mhz.hex

#make atmegaXXm1 AVR_FREQ=8000000L BAUD_RATE=57600
AtmegaX1.menu.clock.8MHz_internal.build.core=arduino
AtmegaX1.menu.clock.8MHz_internal.build.f_cpu=8000000L
AtmegaX1.menu.clock.8MHz_internal=8MHz Internal
AtmegaX1.menu.clock.8MHz_internal.upload.speed=57600
AtmegaX1.menu.clock.8MHz_internal.bootloader.low_fuses=0xF2
AtmegaX1.menu.clock.8MHz_internal.bootloader.high_fuses=0xDE
AtmegaX1.menu.clock.8MHz_internal.bootloader.file=optiboot/optiboot_{build.name2}_8MHz.hex

############################################################
`

do you know what links , or makes it use the avrdude.conf from the custom file?

ATmega64m1-MZ

By any chance do you know if there is a difference between the regular AU and the MZ version of the chip? I made a board with both types. They Both seem to work just fine when i try to burn the bootloader and the fuse bytes. but as soon as it does that. All the pins are pulled High. Checked and it has the same device signature and everything. The only thing digging around i found this 1611-ATMEGA64M1-15MZCT-ND digikey part number and the following pdf.

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7647s-Automotive-Microcontrollers-ATmega16M1-32M1-64M1-32C1-64C1_Datasheet.pdf

Thank you!

Warning: Board ATmegaM1-C1:avr:CanDuino doesn't define a 'build.board' preference

Hi I'm trying to use these board files to upload a blank sketch to the ATmega32M1 but I'm getting the following error:

Warning: Board ATmegaM1-C1:avr:CanDuino doesn't define a 'build.board' preference. Auto-set to: AVR_CANDUINO
fork/exec ~/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino5/bin/avr-g++: bad CPU type in executable
Error compiling for board ATmegaxxM1/C1.

Arduino IDE Version: 1.8.12
macOS Version: 10.15.4

This is my board configuration:
image

And finally programmer is a Polulu USB AVR Programmer V2.

Board clock mismatch

Dear thomasonw I'm encountering some problem with the clock of the board using your code.
I noticed it because the serial comunication wich I set to 9600 instead is actualy at 600.
My board has a 16MHz xtal and I'm using the right bootlader version ATmega64M1 (16MHz - xtal - Arduino). Can you tell me more about it ?
Many thanks.

Turn off the timer0

I've found an issue on using this platform.
If I turn off the timer0 with the instruction Turn off the TCCR0B = 0 nothing works.

Any suggestion?

Sleep Mode

Hi! sorry to bug again. But ive been trying to get the 64m1 to work with the low power library from here: https://github.com/rocketscream/Low-Power
from the datasheets it seems like the 328p and the 64m1 are very similar. But i know there are a phew changed compared to the 328p. does not have a timer2, it only has 4 sleep modes rather then 6. And there are a couple of registers that are different as it doesn't have a i2c bus. But it does have LIN controller, and CAN.
My question if it would be easy to port the low power library for this Micro. As one of the few reasons why this uC is interesting is that it also has a good low power way to manage it.

Vcc reading

Hi,
When I use analogRead(A9) to get the Vcc/4 value, it returns a value around 153 for a 5V supply. If I decrease the supply voltage, this value increases. I can't find any information in the datasheet on what reference voltage is used when the ADC selects the Vcc/4 channel either, so I'm clueless on what the returned value means.
Has anyone here used this feature before?

Thank you in advance!
Regards.

I2C and SPI protocoles

Hi Thomas!
First of all, congratulations for your API, it is a great job.
But, I would like to know if I can use SPI or I2C libraries using the ATMegaxxM1 with arduino IDE.
Thanks in advance.

ATmega16u2 USB-to-serial support

Dear thomasonw, first of all thanks for your great work: it has been of extreme help in one of my recent project!
I don't know if this is the right place to open this issue but otherwise I wouldn't know who to ask to.
I'm trying to build a custom Arduino-style board developed around the ATmega32M1 which I managed to program with your bootloader effortlessy: to be able to use it exactly as an Arduino I've integrated in my pcb also a ATmega16u2 with the exact same connections used in an Arduino (TXD, RXD, CTS) to be able to program the 32M1 via USB taking advantage of the USB-to-serial firmware available for the 16u2. My problem is that although I'm able to load this firmware without any problem (using a USBasp programmer and avrdude) I cannot make the 16u2 communicate with the 32M1: when I try to upload a sketch in the same way that you would do it for an Arduino I receive the avrdude device not in synch resp=0x00 error that usually occurs when you try to program the wrong Arduino board. Are you aware of any change that has to be made to that firmware to make the 2 chips talk (e.g. Product ID, communication frequency...)
If you feel like this is the wrong place to ask can you suggest me where to find an answer?

Using the PSC in M1 variants

Does this allow for use of the power stage controller in M1 versions of these chips?

Say, to drive an H-bridge with ultrasonic PWM without touching TIMER 0 & 1?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.