In need of timer interrupts on Arduino Giga

Hi,

I have been searching for days trying to find a library or description of how to set up Timer Interrupts on the Arduino Giga. I have tried many libraries but they seem to not be compatible.

Can someone please post instructions of how to create for example a timer interrupt at 100Hz calling an ISR where you enter the ISR with CLI and SEI (as I understand it noInterrupts() and interrupts()). Either this or post a link to where this information is available.

Best regards

Since the Giga has the same micro as the Portenta, I guess it should do the trick for you

Regards

Thanks,

I will look into it.

Well, so I tried for some time now to get it to work with the Portenta library, I cannot manage.

Is it possible to have some guide describing how to do it and which interrupt is available not wrecking anything already setup?

I had a look at this: https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet

And it mentions interrupts, but ONLY on input pins, not used with timers.

If someone could post a working example with any available interrupt on the Giga it would be very kind and perhaps useful for more than me.

Thanks in advance!

I just started playing with the GIGA R1 boards, and was wondering about timers. I thought, i might try this library which is now archived. So I create a fork of it.

First thing I did was to update all of the #if to include the GIGA board and then tried a few examples.

I found the PWM_Multi which crashed. Figured maybe not all of the IO pins match so I updated to ones that I believe are PWM pins.
Like:

#if defined(ARDUINO_GIGA)
#define pin0    D2
#define pin1    D3
#define pin2    D4    //D2
#define pin3    D4
#define pin4    D5
#define pin5    D6
#define pin6    D7
#else
#define pin0    D0
...

And it now runs, and the 3 different colros of the LEDS do change. And it shows counters.

Not sure how well it is working yet. Will play more.

Current WIP is up at:
KurtE/Portenta_H7_TimerInterrupt at GIGA_R1 (github.com)

But first thing I wondered what IO pins might work, so created Excel document with the Pin Numbers mapped to the physical pin and then the functionality for each pin... I often do this on new boards, to help better understand them.

Here is the first part of it:

Arduino Function Port AF0 AF1 AF2 AF3 AF4 AF5 AF6 AF7 AF8 AF9 AF10 AF11 AF12 AF13 AF14 AF15
0 RX PB7 - TIM17_CH1
N
TIM4_CH2 HRTIM_EEV
9
I2C1_SDA - I2C4_SDA USART1_
RX
LPUART1_
RX
FDCAN2_
TXFD_
MODE
- DFSDM1_C
KIN5
FMC_NL DCMI_VSY
NC
- EVENT
OUT
1 TX PA9 - TIM1_CH2 HRTIM_
CHC1
LPUART1_
TX
I2C3_SMBA SPI2_SCK/
I2S2_CK
- USART1_
TX
- FDCAN1_
RXFD_
MODE
- ETH_TX_
ER
- DCMI_D0 LCD_R5 EVENT
OUT
2 PA3 TIM2_CH4 TIM5_CH4 LPTIM5_
OUT
TIM15_CH2 - - USART2_
RX
- LCD_B2 OTG_HS_
ULPI_D0
ETH_MII_
COL
- - LCD_B5 EVENT
OUT
3 PA2 TIM2_CH3 TIM5_CH3 LPTIM4_
OUT
TIM15_CH1 - - USART2_
TX
SAI2_SCK
_B
- - ETH_MDIO MDIOS_
MDIO
- LCD_R1 EVENT
OUT
4 PJ8 - TIM1_CH3N - TIM8_CH1 - - - - UART8_TX - - - - - LCD_G1 EVENT
OUT
5 PA7 - TIM1_CH1N TIM3_CH2 TIM8_CH1N - SPI1_MOSI
/I2S1_SDO
- - SPI6_MOSI TIM14_
CH1
ETH_MII_R
X_DV/ETH_
RMII_CRS_
DV
FMC_
SDNWE
- - EVENT
OUT
6 PD13 - LPTIM1_
OUT
TIM4_CH2 I2C4_SDA - - QUADSPI_
BK1_IO3
SAI2_SCK_
A
- FMC_A18 - - EVENT
OUT
7 PB4 NJTRST TIM16_BKIN TIM3_CH1 HRTIM_EEV
6
- SPI1_MISO
/I2S1_SDI
SPI3_MISO/
I2S3_SDI
SPI2_NSS/
I2S2_WS
SPI6_MISO SDMMC2_
D3
- UART7_TX - - - EVENT
OUT
8 PB8 - TIM16_CH1 TIM4_CH3 DFSDM1_C
KIN7
I2C1_SCL - I2C4_SCL SDMMC1_
CKIN
UART4_RX FDCAN1_
RX
SDMMC2_
D4
ETH_MII_
TXD3
SDMMC1_
D4
DCMI_D6 LCD_B6 EVENT
OUT
9 PB9 - TIM17_CH1 TIM4_CH4 DFSDM1_
DATIN7
I2C1_SDA SPI2_NSS/
I2S2_WS
I2C4_SDA SDMMC1_
CDIR
UART4_TX FDCAN1_
TX
SDMMC2_
D5
I2C4_SMBA SDMMC1_
D5
DCMI_D7 LCD_B7 EVENT
OUT
10 PK1 - TIM1_CH1 - TIM8_CH3N - SPI5_NSS - - - - - - - - LCD_G6 EVENT
OUT
11 PJ10 - TIM1_CH2N - TIM8_CH2 - SPI5_MOSI - - - - - - - - LCD_G3 EVENT
OUT
12 PJ11 - TIM1_CH2 - TIM8_CH2N - SPI5_MISO - - - - - - - - LCD_G4 EVENT
OUT
13 PH6 - - - - I2C2_SMBA SPI5_SCK - - - - - ETH_MII_R
XD2
FMC_SDNE
1
DCMI_D8 - EVENT
OUT

Again just playing around. The XLS file is up in my UNO R4 github project

Edit: Wondering if this should be in the Hardware GIGA forum.?

2 Likes

I tried your fork and it's working great with no problems so far!
Thanks for your work. :blush:

1 Like

Hello!
Could you confirm is it actually working?
I just got a Giga R1 Wifi today, but the compiler said that the library is not compatible with the mbed_giga.

I know your WIP is just an experiment, but I'm seeing the same problem as user jmwinding above. I suspect it is just a cockpit error on my part, not being 100% clear on how to install it.

I am an experienced embedded programmer but a novice at Arduino. Working on porting a small program from Uno to Giga. The original Uno code set up an ATMega328P peripheral timer to trigger an interrupt. That is how I found this repository, since it seems the support for doing this within the Ardino system is lacking.

I am not certain I need to configure a hardware timer interrupt -- there may be a native Arduino solution that is good enough for my application. Alternatively, I could hard code the STM32H7 configuration code myself ( I have written C++ projects on the H7 recently in non-Arduino land).

-Chris

Sorry, I have not been playing much with the GIGA for a while. Been back mostly doing coding for Teensy boards...

And I have not done anything on this probably this year.

But for example when I was playing with their USB Host code base and attempting to port some of the different devices we support on a Teensy USB Host, I needed a latency timeout. On the Teensy USB host code, there was already an Millisecond timer for USB Start of Frame... That we hooked into to then flush out any stuff still in our output buffer...

Was not sure of how to easily do this on GIGA. I ended up doing it using some of the MBED timer class code:
RTC - API references and tutorials | Mbed OS 6 Documentation
(Note I think we are MBED 5.x so might be some differences)

When new characters are put into output queue, I setup a callback:

  inline void startWriteTimeout() { 
    writeTO_.attach(mbed::callback(this, &USBHostSerialDevice::processTXTimerCB), std::chrono::microseconds(write_timeout_));}

The code where I am doing this is up in the github project:
GIGA_USBHostMBed5_devices/src/USBHostSerialDevice.h at main · KurtE/GIGA_USBHostMBed5_devices (github.com)

in the USBHostSerialDevice files...

Not sure if that help you or not.

Good luck

1 Like

Okay, I fixed it and I was operator error. Somehow in my various attempts to install your forked library, I had accidentally installed the original version by mistake. Once I realized that, I wiped out the folder in the Documents/Arduino/libraries directory and replaced with the clone of your fork.

Now a simple test sketch compiles and runs correctly. There is still a warning being emitted somewhere saying

WARNING: library Portenta_H7_TimerInterrupt claims to run on mbed, mbed_portenta, ArduinoCore-mbed architecture(s) and may be incompatible with your current board which runs on mbed_giga architecture(s).

But it's just a warning. Later on when it annoys me too much, I'll track down the source of that warning and fix it.

-Chris

1 Like

If you add mbed_giga to the architectures line in the file library.properties, the warning goes away.

1 Like

I pushed up change to library properties.

Warning: I combined the three commits into one (git squash)...

Might submit it as a PR back to owner to see if they are interested.

EDIT: never mind, I forgot that github project was archived.

1 Like

Hello!
I've been trying to run the PWM program that u made in Giga R1, but there's some error that said

error: #error This code is intended to run on the MBED ARDUINO_PORTENTA_H7 platform! Please check your Tools->Board setting.
#error This code is intended to run on the MBED ARDUINO_PORTENTA_H7 platform! Please check your Tools->Board setting.
^~~~~
exit status 1

do u have any solution to solve this error? Thank you ^^

Which sketch?

Did you install my fork/branch of the library? I believe I have set the GIGA_R1 branch as my default.

Hi, did you try to measure frequency/period with your fork?
I don´t get a timer configured accordingly...

100Hz is every 10ms... how precisely do you need to hit that mark? What's your tolerance since you could be within 50 micros almost always without using interrupts at all on a 16MHz Uno just using non-blocking code. I'm not kidding! Usually we say "within a millisecond" for extra margin, it was the lesson du jour here since before 2011 when I arrived but with care, you can hold 20usecs on average with many soft-timers at once.

I use one of my Logic Analyzers and look at the signals.

1 Like

That's one skill I never developed.
I was a programmer who dabbled with hardware... still do, just a hobbyist!

Old joke I learned in 85, was old then:
Q; How many programmers does it take to change a lightbulb?
A; Can't be done, it's a hardware problem!

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.