PaulStoffregen / Tlc5940

16 channel PWM LED driver based on the Texas Instruments TLC5940 chip.
https://github.com/PaulStoffregen/Tlc5940
81 stars 40 forks source link

Arduino Nano 33 IoT #19

Open 97Cweb opened 2 years ago

97Cweb commented 2 years ago

Description

Hello all, I am currently upgrading my project from an Arduino Nano to a Nano 33 IoT board, which is supposed to be just a drop in replacement. I am testing it currently, and this library throws an error regarding missing board type when compiling.

Hopefully there is enough information to resolve this, if I am missing anything pleas let me know. I finally have motivation to work on this project again, and it hinges on this still working for this new board. From what I read, both nanos should be drop in replacements of each other. Don't know if that helps you though.

Steps To Reproduce Problem

Create a new sketch, Target IoT board in board selector. Include this library, Hit checkmark.

Hardware & Software

Board: Arduino Nano 33 IoT Shields / modules used : none Arduino IDE version: 1.8.19 Teensyduino version (if using Teensy) Not used Version info & package name (from Tools > Boards > Board Manager) Arduino SAMD Boards (32-bits ARM Cortex-M0+) by Arduino version 1.8.13 Operating system & version Windows 10 Any other software or hardware? Dell laptop to run Arduino IDE in

Arduino Sketch

// libraries: just Tlc5940.h Freshly downloaded and unzipped into library folder of Arduino as of today. Only change is to make config take 3 chips instead of 1. 

#include "Tlc5940.h"

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Errors or Incorrect Output

`Arduino: 1.8.19 (Windows 10), Board: "Arduino NANO 33 IoT"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\97cwe\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\97cwe\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\97cwe\Documents\Arduino\libraries -fqbn=arduino:samd:nano_33_iot -vid-pid=2341_8057 -ide-version=10819 -build-path C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725 -warnings=none -build-cache C:\Users\97cwe\AppData\Local\Temp\arduino_cache_389484 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.2.1 -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.2.1 -prefs=runtime.tools.CMSIS-Atmel.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0 -prefs=runtime.tools.CMSIS-Atmel-1.2.0.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0 -prefs=runtime.tools.CMSIS.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.CMSIS-4.5.0.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.bossac.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3 -prefs=runtime.tools.bossac-1.7.0-arduino3.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3 -prefs=runtime.tools.openocd.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7 -prefs=runtime.tools.openocd-0.10.0-arduino7.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4 -prefs=runtime.tools.arm-none-eabi-gcc-7-2017q4.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4 -verbose C:\Users\97cwe\Documents\Computer Stuff\Arduino\Projects\LED Cube\fix_TLC5940_library\fix_TLC5940_library.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\97cwe\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\97cwe\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\97cwe\Documents\Arduino\libraries -fqbn=arduino:samd:nano_33_iot -vid-pid=2341_8057 -ide-version=10819 -build-path C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725 -warnings=none -build-cache C:\Users\97cwe\AppData\Local\Temp\arduino_cache_389484 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.2.1 -prefs=runtime.tools.arduinoOTA-1.2.1.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.2.1 -prefs=runtime.tools.CMSIS-Atmel.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0 -prefs=runtime.tools.CMSIS-Atmel-1.2.0.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0 -prefs=runtime.tools.CMSIS.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.CMSIS-4.5.0.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0 -prefs=runtime.tools.bossac.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3 -prefs=runtime.tools.bossac-1.7.0-arduino3.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.7.0-arduino3 -prefs=runtime.tools.openocd.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7 -prefs=runtime.tools.openocd-0.10.0-arduino7.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\openocd\0.10.0-arduino7 -prefs=runtime.tools.arm-none-eabi-gcc.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4 -prefs=runtime.tools.arm-none-eabi-gcc-7-2017q4.path=C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4 -verbose C:\Users\97cwe\Documents\Computer Stuff\Arduino\Projects\LED Cube\fix_TLC5940_library\fix_TLC5940_library.ino

Using board 'nano_33_iot' from platform in folder: C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13

Using core 'arduino' from platform in folder: C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13

Detecting libraries used...

"C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10819 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -DSAMD21G18A -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino NANO 33 IoT\"" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated-avr-comp" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\variants\nano_33_iot" "C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725\sketch\fix_TLC5940_library.ino.cpp" -o nul

Alternatives for Tlc5940.h: [Tlc5940@0.15]

ResolveLibrary(Tlc5940.h)

-> candidates: [Tlc5940@0.15]

"C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10819 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -DSAMD21G18A -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino NANO 33 IoT\"" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated-avr-comp" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\variants\nano_33_iot" "-IC:\Users\97cwe\Documents\Arduino\libraries\Tlc5940" "C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725\sketch\fix_TLC5940_library.ino.cpp" -o nul

Error while detecting libraries included by C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725\sketch\fix_TLC5940_library.ino.cpp

"C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10819 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -DSAMD21G18A -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino NANO 33 IoT\"" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated-avr-comp" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\variants\nano_33_iot" "-IC:\Users\97cwe\Documents\Arduino\libraries\Tlc5940" "C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940\Tlc5940.cpp" -o nul

Error while detecting libraries included by C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940\Tlc5940.cpp

Generating function prototypes...

"C:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10819 -DARDUINO_SAMD_NANO_33_IOT -DARDUINO_ARCH_SAMD -DCRYSTALLESS -DSAMD21G18A -DUSB_VID=0x2341 -DUSB_PID=0x8057 -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino NANO 33 IoT\"" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino/api/deprecated-avr-comp" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\cores\arduino" "-IC:\Users\97cwe\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.13\variants\nano_33_iot" "-IC:\Users\97cwe\Documents\Arduino\libraries\Tlc5940" "C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725\sketch\fix_TLC5940_library.ino.cpp" -o "C:\Users\97cwe\AppData\Local\Temp\arduino_build_582725\preproc\ctags_target_for_gcc_minus_e.cpp"

In file included from C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940/tlc_config.h:67:0,

             from C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940/Tlc5940.h:26,

             from C:\Users\97cwe\Documents\Computer Stuff\Arduino\Projects\LED Cube\fix_TLC5940_library\fix_TLC5940_library.ino:1:

C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940/pinouts/chip_includes.h:129:2: error: #error "Unknown Chip!"

error "Unknown Chip!"

^~~~~

Using library Tlc5940 at version 0.15 in folder: C:\Users\97cwe\Documents\Arduino\libraries\Tlc5940

exit status 1

Error compiling for board Arduino NANO 33 IoT.

`

PaulStoffregen commented 2 years ago

Nano 33 is a completely different processor with different timer hardware than regular Nano.

97Cweb commented 2 years ago

Hello Paul. Thank you for your reply. Does this mean, it will take a while, or that you will not be upgrading this system for this newer Arduino board?

PaulStoffregen commented 2 years ago

It will only happen if someone who uses Nano 33 and knows its timers well enough contributes the code. I will not do it. Depending on the open source community for those sorts of contributions.

97Cweb commented 2 years ago

Ok, thank you for being open and honest about this. Hopefully someone eventually adds it.

97Cweb commented 2 years ago

Hi Paul I did manage to sort it out partly. It is no good enough to go into the library, but I did manage to get it to work for my system. I am giving it to you so whoever wants to take a crack at it can, as you are the main contact for this library. https://drive.google.com/file/d/1FIm5III9k6nUCRf4pHXzgGrBw8DfuRJw/view?usp=sharing

PaulStoffregen commented 2 years ago

Any chance you could upload the changed code here on Github?

Long-term, odds are someone else will find this message, but Google Drive tends to not keep files for long term storage.

PaulStoffregen commented 2 years ago

Looked at this briefly. Seems you probably stated with the stable release (from 2015) rather than latest from github.

Here's my best attempt to capture the changes relative to that version, in diff format.... for future reference.

diff -r -u -N -w -B Tlc5940_old/pinouts/Arduino_Nano_33_IOT.h Tlc5940/pinouts/Arduino_Nano_33_IOT.h
--- Tlc5940_old/pinouts/Arduino_Nano_33_IOT.h   1969-12-31 16:00:00.000000000 -0800
+++ Tlc5940/pinouts/Arduino_Nano_33_IOT.h   2022-06-11 22:01:36.000000000 -0700
@@ -0,0 +1,86 @@
+/*  Copyright (c) 2009 by Alex Leone <acleone ~AT~ gmail.com>
+
+    This file is part of the Arduino TLC5940 Library.
+
+    The Arduino TLC5940 Library is free software: you can redistribute it
+    and/or modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    The Arduino TLC5940 Library is distributed in the hope that it will be
+    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with The Arduino TLC5940 Library.  If not, see
+    <http://www.gnu.org/licenses/>. */
+
+#ifndef TLC_Arduino_Nano_33_IOT_H
+#define TLC_Arduino_Nano_33_IOT_H
+
+// bitbang I/O is plenty fast on Nano 33
+#ifdef DATA_TRANSFER_MODE
+#undef DATA_TRANSFER_MODE
+#endif
+#define DATA_TRANSFER_MODE TLC_BITBANG
+
+/** \file
+    SPI and timer pins for the ATmega168/48/88.  Don't edit these.  All
+    changeable pins are defined in tlc_config.h */
+
+/** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */
+#define DEFAULT_VPRG_PIN    8
+#define DEFAULT_VPRG_PORT   REG_PORT_OUT0 
+#define DEFAULT_VPRG_DDR    REG_PORT_DIR0 
+
+/** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */
+#define DEFAULT_XERR_PIN    12
+#define DEFAULT_XERR_PORT   REG_PORT_OUT0 
+#define DEFAULT_XERR_DDR    REG_PORT_DIR0 
+#define DEFAULT_XERR_PINS   12
+
+/** SIN (Arduino digital pin 11) -> SIN (TLC pin 26) */
+#define DEFAULT_BB_SIN_PIN      11
+#define DEFAULT_BB_SIN_PORT     REG_PORT_OUT0 
+#define DEFAULT_BB_SIN_DDR      REG_PORT_DIR0 
+/** SCLK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
+#define DEFAULT_BB_SCLK_PIN     13
+#define DEFAULT_BB_SCLK_PORT    REG_PORT_OUT0 
+#define DEFAULT_BB_SCLK_DDR     REG_PORT_DIR0 
+
+/** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */
+#define TLC_MOSI_PIN     11
+#define TLC_MOSI_PORT    REG_PORT_OUT0 
+#define TLC_MOSI_DDR     REG_PORT_DIR0 
+
+/** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
+#define TLC_SCK_PIN      13
+#define TLC_SCK_PORT     REG_PORT_OUT0 
+#define TLC_SCK_DDR      REG_PORT_DIR0 
+
+/** SS will be set to output as to not interfere with SPI master operation.
+    If you have changed the pin-outs and the library doesn't seem to work
+    or works intermittently, make sure this pin is set correctly.  This pin
+    will not be used by the library other than setting its direction to
+    output. */
+#define TLC_SS_PIN       11
+#define TLC_SS_DDR       REG_PORT_DIR0 
+
+/** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */
+#define XLAT_PIN     9
+#define XLAT_PORT    REG_PORT_OUT0 
+#define XLAT_DDR     REG_PORT_DIR0 
+
+/** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */
+#define BLANK_PIN    10
+#define BLANK_PORT   REG_PORT_OUT0 
+#define BLANK_DDR    REG_PORT_DIR0 
+
+/** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */
+#define GSCLK_PIN    3
+#define GSCLK_PORT   REG_PORT_OUT0 
+#define GSCLK_DDR    REG_PORT_DIR0 
+
+#endif
+
diff -r -u -N -w -B Tlc5940_old/pinouts/chip_includes.h Tlc5940/pinouts/chip_includes.h
--- Tlc5940_old/pinouts/chip_includes.h 2022-06-16 04:30:45.479383485 -0700
+++ Tlc5940/pinouts/chip_includes.h 2022-05-26 10:47:42.000000000 -0700
@@ -26,6 +26,8 @@
 #include <avr/io.h>
 #endif

+#if !defined (__SAMD21G18A__)
+
 #ifndef PB0
 #define PB0     PORTB0
 #define PB1     PORTB1
@@ -67,6 +69,7 @@
 #define PH7     PORTH7
 #endif

+#endif
 /* Chip Specific Pinouts */
 #if defined (__AVR_ATmega168__)  \
  || defined (__AVR_ATmega168P__) \
@@ -118,6 +121,9 @@
 /* Teensy 3.0 & 3.1 */
 #include "Teensy_KinetisK20.h"

+/* IOT 33 NANO */
+#elif defined (__SAMD21G18A__)
+#include "Arduino_Nano_33_IOT.h"

 #else
 #error "Unknown Chip!"
diff -r -u -N -w -B Tlc5940_old/Tlc5940.cpp Tlc5940/Tlc5940.cpp
--- Tlc5940_old/Tlc5940.cpp 2022-06-16 04:30:45.483383478 -0700
+++ Tlc5940/Tlc5940.cpp 2022-06-15 20:34:28.000000000 -0700
@@ -55,11 +59,14 @@
 /** Interrupt called after an XLAT pulse to prevent more XLAT pulses. */
 static inline void Tlc5940_interrupt(void)
 {
+   
     disable_XLAT_pulses();
     clear_XLAT_interrupt();
     tlc_needXLAT = 0;
     if (tlc_onUpdateFinished) {
+        #if !defined(__SAMD21G18A__)
         sei();
+       #endif
         tlc_onUpdateFinished();
     }
 }
@@ -78,6 +85,41 @@
     Tlc5940_interrupt();
 }

+#elif defined(__SAMD21G18A__) //overflow handler for XLAT PWM
+#include <sam.h>
+/** Interrupt called after an XLAT pulse to prevent more XLAT pulses. */
+//Datasheet page 684
+void TCC1_Handler()
+{
+   
+   if (TCC1->INTFLAG.bit.MC0 && TCC1->INTENSET.bit.MC0)             
+   {
+       REG_TCC1_INTFLAG = TCC_INTFLAG_MC0;  //clear TCC1 interrupt
+
+       //BLANK_PORT |= (1 << BLANK_PIN); //Bring BLANK high until XLAT pulses
+       set_pin(BLANK_PORT, BLANK_PIN); // Bring BLANK high until XLAT pulses
+       //set_pin(XLAT_PORT, XLAT_PIN); // Bring XLAT high until XLAT pulses
+
+   }
+   if (TCC1->INTFLAG.bit.OVF && TCC1->INTENSET.bit.OVF){
+
+       //BLANK_PORT &=~ (1 << BLANK_PIN);  // Bring BLANK low after XLAT pulses
+       clear_pin(BLANK_PORT,BLANK_PIN);   // Bring BLANK low after XLAT pulses
+       //clear_pin(XLAT_PORT,XLAT_PIN);   // Bring XLAT low after XLAT pulses
+       disable_XLAT_pulses();
+     
+   if(tlc_needXLAT){
+       pulse_pin(XLAT_PORT,XLAT_PIN); //xlat only triggered if xlat needed, set by the update and init fns
+   }
+     
+     clear_XLAT_interrupt();
+     tlc_needXLAT = 0;
+     //if (tlc_onUpdateFinished) {
+       //set_XLAT_interrupt();
+       //tlc_onUpdateFinished();
+     //}
+    }
+}
 #endif

 /** \defgroup ReqVPRG_ENABLED Functions that Require VPRG_ENABLED
@@ -102,6 +144,29 @@
            value */
 void Tlc5940::init(uint16_t initialValue)
 {
+   REG_TCC1_INTENSET |=  TCC_INTENSET_MC0; // set PWM interrupts
+   
+   //Datasheet page 95
+   // Initialize GCLK 
+   REG_GCLK_GENDIV = GCLK_GENDIV_DIV(3) |  // Divide the 48MHz clock source by divisor 3: 48MHz/3=16MHz
+   GCLK_GENDIV_ID(4);                    // Select Generic Clock (GCLK) 4
+   while (GCLK->STATUS.bit.SYNCBUSY);      // Wait for synchronization
+
+   REG_GCLK_GENCTRL = GCLK_GENCTRL_IDC |   // Set the duty cycle to 50/50 HIGH/LOW
+   GCLK_GENCTRL_GENEN |                  // Enable GCLK4
+   GCLK_GENCTRL_SRC_DFLL48M |            // Set the 48MHz clock source
+   GCLK_GENCTRL_ID(4);                   // Select GCLK4
+   while (GCLK->STATUS.bit.SYNCBUSY);      // Wait for synchronization
+
+   // Feed GCLK4 to TCC0 and TCC1
+   REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN | // Enable GCLK4 to TCC0 and TCC1
+   GCLK_CLKCTRL_GEN_GCLK4 |              // Select GCLK4
+   GCLK_CLKCTRL_ID_TCC0_TCC1 ;           // Feed GCLK4 to TCC0 and TCC1
+   while (GCLK->STATUS.bit.SYNCBUSY);      // Wait for synchronization
+
+   NVIC_SetPriority(TCC1_IRQn, 0);         // Set the Nested Vector Interrupt Controller (NVIC) priority for TC1 to 0 (highest)
+   NVIC_EnableIRQ(TCC1_IRQn);              // Connect TCC1 to Nested Vector Interrupt Controller (NVIC)
+   
     /* Pin Setup */
     output_pin(XLAT_DDR, XLAT_PIN);
     output_pin(BLANK_DDR, BLANK_PIN);
@@ -185,6 +251,55 @@
     FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS;
     NVIC_ENABLE_IRQ(IRQ_FTM1);
     CORE_PIN4_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE;
+   
+#elif defined(__SAMD21G18A__)
+   /* Timer Setup */
+
+   /* Timer 1 -  XLAT */
+   //Datasheet page 726
+   REG_TCC1_WAVE |= TCC_WAVE_WAVEGEN_NPWM;    // Setup normal PWM on TCC1
+   while (TCC1->SYNCBUSY.bit.WAVE);           // Wait for synchronization
+
+   //Datasheet page 729
+   REG_TCC1_PER = TLC_PWM_PERIOD;             // see tlc_config.h
+   while (TCC1->SYNCBUSY.bit.PER);            // Wait for synchronization
+   
+   disable_XLAT_pulses();                 // non inverting, output on TCC1:3, XLAT 
+   /* Timer 2 - GSCLK */
+   enable_GSCLK();                        // output on TCC0:4 
+   
+   REG_TCC1_CC0 = TLC_PWM_PERIOD;                      //set TCC1 interrupt timing
+   
+   
+   while (TCC1->SYNCBUSY.bit.CC0);            // Wait for synchronization
+
+   //Datasheet page 703
+   //REG_TCC0_WEXCTRL |= TCC_WEXCTRL_OTMX(0x2); //Output TCC0 to all pins instead of their default
+
+   //REG_TCC0_WAVE |= TCC_WAVE_WAVEGEN_NPWM;    // Setup normal PWM on TCC0
+   REG_TCC0_WAVE |= TCC_WAVE_WAVEGEN_DSBOTH;    // Setup dual slope PWM on TCC0
+   while (TCC0->SYNCBUSY.bit.WAVE);    
+   
+   
+   //Datsheet page 732
+   REG_TCC0_PER = TLC_GSCLK_PERIOD;           // see tlc_config.h
+   while (TCC0->SYNCBUSY.bit.PER);            // Wait for synchronization
+   // The CCBx register value corresponds to the pulsewidth in microseconds (us)
+    REG_TCC0_CCB0 = TLC_GSCLK_PERIOD/2;       
+    while(TCC0->SYNCBUSY.bit.CCB0);
+    REG_TCC0_CCB1 = TLC_GSCLK_PERIOD/2;       
+    while(TCC0->SYNCBUSY.bit.CCB1);
+   
+
+   //Datasheet page 688
+   REG_TCC0_CTRLA |= TCC_CTRLA_ENABLE |
+   TCC_CTRLA_PRESCALER_DIV8;                // no prescale, (start pwm output)
+   while (TCC0->SYNCBUSY.bit.ENABLE);         // Wait for synchronization
+   REG_TCC1_CTRLA |= TCC_CTRLA_ENABLE |
+   TCC_CTRLA_PRESCALER_DIV1;                // no prescale, (start pwm output)
+   while (TCC1->SYNCBUSY.bit.ENABLE);         // Wait for synchronization
+   enable_XLAT_pulses();
+   
 #endif
     update();
 }
@@ -340,9 +455,16 @@
 /** Sets all the bit-bang pins to output */
 void tlc_shift8_init(void)
 {
+   
     output_pin(SIN_DDR, SIN_PIN);   // SIN as output
     output_pin(SCLK_DDR, SCLK_PIN); // SCLK as output
     clear_pin(SCLK_PORT, SCLK_PIN);
+   
+   /**
+   SIN_DDR |= (1 << SIN_PIN);     // SIN as output
+    SCLK_DDR |= (1 << SCLK_PIN);   // SCLK as output
+    SCLK_PORT &=~ (1 << SCLK_PIN); // start SCLK low
+   **/
 }

 /** Shifts a byte out, MSB first */
diff -r -u -N -w -B Tlc5940_old/Tlc5940.h Tlc5940/Tlc5940.h
--- Tlc5940_old/Tlc5940.h   2022-06-16 04:30:45.479383485 -0700
+++ Tlc5940/Tlc5940.h   2022-06-12 16:36:46.000000000 -0700
@@ -55,6 +55,22 @@
 #define enable_XLAT_pulses()    CORE_PIN3_CONFIG = PORT_PCR_MUX(3)|PORT_PCR_DSE|PORT_PCR_SRE
 #define disable_XLAT_pulses()   CORE_PIN3_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE

+#elif defined(__SAMD21G18A__)
+/** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
+    pulse */
+#define set_XLAT_interrupt()    REG_TCC1_INTENSET |= TCC_INTENSET_OVF
+/** Disables any Timer1 interrupts */
+#define clear_XLAT_interrupt()  REG_TCC1_INTFLAG |= TCC_INTFLAG_OVF // Clear the OVF interrupt flag 
+
+/** Enables the output of XLAT pulses */
+#define enable_XLAT_pulses()     PORT->Group[g_APinDescription[XLAT_PIN].ulPort].PINCFG[g_APinDescription[XLAT_PIN].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[SCLK_PIN].ulPort].PMUX[g_APinDescription[SCLK_PIN].ulPin >> 1].reg = PORT_PMUX_PMUXO_F; REG_TCC1_CC1 = 1; while (TCC1->SYNCBUSY.bit.CC1)
+/** Disables the output of XLAT pulses */
+#define disable_XLAT_pulses()   PORT->Group[g_APinDescription[XLAT_PIN].ulPort].PINCFG[g_APinDescription[XLAT_PIN].ulPin].bit.PMUXEN = 0; REG_TCC1_CC1 = 0; while (TCC1->SYNCBUSY.bit.CC1) 
+
+//Check if GSCLK behaving. ChangedPORT_PMUX_PMUXO_F from PORT_PMUX_PMUXE_F
+#define enable_GSCLK()             PORT->Group[g_APinDescription[GSCLK_PIN].ulPort].PINCFG[g_APinDescription[GSCLK_PIN].ulPin].bit.PMUXEN = 1; PORT->Group[g_APinDescription[GSCLK_PIN].ulPort].PMUX[g_APinDescription[GSCLK_PIN].ulPin >> 1].reg = PORT_PMUX_PMUXO_F
+
+
 #endif

@@ -87,6 +105,7 @@

 void tlc_shift8_init(void);
 void tlc_shift8(uint8_t byte);
+void tlc_shift8(uint8_t pwm_val, uint8_t byte);

 #if VPRG_ENABLED
 void tlc_dcModeStart(void);
diff -r -u -N -w -B Tlc5940_old/tlc_config.h Tlc5940/tlc_config.h
--- Tlc5940_old/tlc_config.h    2022-06-16 04:30:45.483383478 -0700
+++ Tlc5940/tlc_config.h    2022-06-13 19:39:02.000000000 -0700
@@ -52,7 +52,7 @@
     of the first TLC to the SIN (TLC pin 26) of the next.  The rest of the pins
     are attached normally.
     \note Each TLC needs it's own IREF resistor */
-#define NUM_TLCS    1
+#define NUM_TLCS    3

 /** Determines how data should be transfered to the TLCs.  Bit-banging can use
     any two i/o pins, but the hardware SPI is faster.
@@ -91,15 +91,17 @@
     \f$\displaystyle TLC\_PWM\_PERIOD =
        \frac{(TLC\_GSCLK\_PERIOD + 1) * 4096}{2} \f$
     \note The default of 8192 means the PWM frequency is 976.5625Hz */
-#define TLC_PWM_PERIOD    8192
-
+//#define TLC_PWM_PERIOD    8192
+#define TLC_PWM_PERIOD   16384 
+//#define TLC_PWM_PERIOD   14336 
 /** Determines how long each period GSCLK is.
     This is related to TLC_PWM_PERIOD:
     \f$\displaystyle TLC\_GSCLK\_PERIOD =
        \frac{2 * TLC\_PWM\_PERIOD}{4096} - 1 \f$
     \note Default is 3 */
-#define TLC_GSCLK_PERIOD    3
-
+//#define TLC_GSCLK_PERIOD    3
+#define TLC_GSCLK_PERIOD    7
+//#define TLC_GSCLK_PERIOD    6
 /** Enables/disables VPRG (TLC pin 27) functionality.  If you need to set dot
     correction data, this needs to be enabled.
     - 0 VPRG is not connected.  <em>TLC pin 27 must be grounded!</em> (default)
97Cweb commented 2 years ago

https://github.com/97Cweb/TLC5940-Nano-33 Here is the Github copy of it for others

97Cweb commented 2 years ago

I can upload it. Do I make it in my own, or is there a way to tie it to yours?

On Wed., Jun. 15, 2022, 8:47 p.m. Paul Stoffregen, @.***> wrote:

Any chance you could upload the changed code here on Github?

Long-term, odds are someone else will find this message, but Google Drive tends to not keep files for long term storage.

— Reply to this email directly, view it on GitHub https://github.com/PaulStoffregen/Tlc5940/issues/19#issuecomment-1157108032, or unsubscribe https://github.com/notifications/unsubscribe-auth/APFMQO2LX6G772BIZSJVA5TVPJ2QTANCNFSM5WRIP6DQ . You are receiving this because you authored the thread.Message ID: @.***>