Help for a beginner

Status
Not open for further replies.

adi1893

Member
Hi,

I have just made the switch from an Arduino Uno to a Teensy 4.1. However, I am finding it hard to get resources for the Teensy 4.1 like:

1. How many hardware timers are on the i.MX RT1062 chip (the 328p had Timer0, Timer1 and Timer2).
2. Which of these timers are used for the default functions of elapsedMillis/millis/elapsedMicros
3. Tutorial on how to setup/configure and use the GPT, PIT, TMR, ENC
4. How many GPTs, PITs, TMRs and ENCs can I setup in a project
5. The relationship between GPT, PIT, TMR, ENC and the hardware timers such as Timer0/1/2

I have read through the PJRC tutorials and whatever I could on here but some direction to good resources, tutorials or anyone willing to help would really be helpful. I am currently using Teensyduino but upgrading to Visual Micro soon.

I just finished making a table that balances a metal ball at the center using 2 rc servo motors. In that I hard coded the PWM generation of both servo control signals using Timer0 as well as the 4-wire touch screen position sensing code without using the Servo Library or the 4-wire touchscreen library.

I would like to be able to setup and use the hardware timers and GPT, PIT, TMR and ENC timers for PWM/Input Capture/Timer Compare Interrupts etc without depending on libraries for the same for good flexibility for my projects.

I have two projects that I wish to make using the 4.1. One being a Motion controller that syncs a slave Servo motor to a master encoder using a pulse train and another project which detects missing labels on a continuous web of labels using a label sensor with reference to an encoder that picks up the web speed and the required time that the sensor should be on/off in normal circumstances. I'll post on the Projects area later for these if I run into any issues but at the moment I need help getting to using the 4.1 well

Thanks for reading and I hope to be able to enjoy coding and using the 4.1 as much as I enjoy using the 328p
 
Quick answers.....


1. How many hardware timers are on the i.MX RT1062 chip (the 328p had Timer0, Timer1 and Timer2).

The Teensy 4.1 page has recently been updated with a lists of the timers.

https://www.pjrc.com/store/teensy41.html#timing

This hardware is loaded with advanced features. FlexIO, Ethernet, USB have even more timers, generally meant to be used with those peripherals but also possible to use in generic ways. I do not believe anyone has made a completely comprehensive list of every single timer.


2. Which of these timers are used for the default functions of elapsedMillis/millis/elapsedMicros

Those functions use SysTick and the ARM cycle counter.

The good news is none of the PWM / input capture / output compare style timers are used up by these normal timing functions (as timer0 on AVR gets consumed).


3. Tutorial on how to setup/configure and use the GPT, PIT, TMR, ENC

There isn't much tutorial material written yet. Most of the work which has been done is libraries, which you've said you don't want to use. I hope you can understand Teensy 4.x is relatively new. Libraries and documentation are an ongoing effort, and sadly the pandemic has slowed that work in some ways.

If you want to play with direct hardware access, you certainly can, but the main resources are NXP's reference manual and the code which already exists in libraries.

However, you might check out Luni's TeensyTimerTool library and wiki.

https://github.com/luni64/TeensyTimerTool/wiki

Again, the focus is mostly on a library to actually use rather than tutorial material to create your own from scratch. But there is plenty of working code there to use if you're trying to learn how the hardware really works at the lowest level.


4. How many GPTs, PITs, TMRs and ENCs can I setup in a project

Theoretically, all of them, if you have enough time & skill to do so.

Realistically, it's hard to imagine any project which could really make use of absolutely every last timer in the whole chip.


5. The relationship between GPT, PIT, TMR, ENC and the hardware timers such as Timer0/1/2

The FlexPWM timers are the type most similar to Timer0, 1, 2 in AVR chips.


I just finished making a table that balances a metal ball at the center using 2 rc servo motors. In that I hard coded the PWM generation of both servo control signals using Timer0 as well as the 4-wire touch screen position sensing code without using the Servo Library or the 4-wire touchscreen library.

Sounds like an impressive project. Indeed you can sometimes get more capability of the hardware if you code directly to the registers. But avoiding libraries like Servo or PWMServo also means you code gets tightly tied to a specific chip. Maybe that's a worthwhile trade-off? Maybe not?


I have two projects that I wish to make using the 4.1. One being a Motion controller that syncs a slave Servo motor to a master encoder using a pulse train and another project which detects missing labels on a continuous web of labels using a label sensor with reference to an encoder that picks up the web speed and the required time that the sensor should be on/off in normal circumstances. I'll post on the Projects area later for these if I run into any issues but at the moment I need help getting to using the 4.1 well

If you've ruled out using the Servo or PWMServo libraries (which in turn use IntervalTimer and analogWrite), maybe at least look at their source code, and the source code of the core library functions they use. It's not a nicely written tutorial, but at least it is known-good code. Hopefully that can give you an easier starting point than just reading the 3437 page reference manual.
 
Status
Not open for further replies.
Back
Top