Skip to main content
Explorer II
February 19, 2024
Question

Find STM32 with 5 encoders input timers,

  • February 19, 2024
  • 7 replies
  • 4521 views

For a project, I need to find a stm32 that has a minimum of 5 timers that can read encoders, and it has to have a CAN-bus peripheral.

Is there a way to do this in the part selectors? I can select the minimum number of 16bit timers, but not all 16bit counters seem to support encoder input. Any way to do this without manually reading all the datasheets?

I did try to automate this using the XML files in the data folder of stm32cube, but I did not really find a way to detect if a 16bit counter support encoder input.

    This topic has been closed for replies.

    7 replies

    Super User
    February 19, 2024
    VidiconAuthor
    Explorer II
    February 19, 2024

    I know these tools, but as mentioned in my question, I don't see a way to do a parametric select on timers with encoder input.

    Super User
    February 19, 2024

    @Vidicon wrote:

    I know these tools


    Oh well - you didn't mention that.

    Have you tried any distributors  parametric searches?

     

    EDIT:

    AN4013 seems to suggest that any 'General-Purpose' or 'Advanced' Timer can do it:

    AndrewNeil_0-1708338583582.png

     

    Graduate II
    February 19, 2024

    Well, F407 is not a recent family. Encoder mode need a time with two channels.WhatsApp Image 2024-02-19 at 12.08.52.jpegAt least there are timers 1/2/4/5/8/9/12 with two channels. If all channel gpios are available is another question.

    Super User
    February 19, 2024

    > At least there are timers 1/2/4/5/8/9/12 with two channels.

    Two channels is not a sufficient precondition. TIM9 and TIM12 don't have Encoder mode.

    Only TIM1/8/20 and TIM2/3/4/5 have Encoder mode, across all STM32 families, as far as I know. Probably most if not all 'F1/'F2/'F3/'F4/'F7/'G4 and higher-end 'L4 (i.e. 'L47x and up) will have 5 timers with encoders; maybe also some of the 'G0/'F0, I did not check (I recommend against using the ancient 'F1 family, though).

    Then, you have to choose a model which has enough pins so that all those timers do have CH1 and CH2 brought out on non-overlapping pins. I'd expect a 64-pin (xR) package, although the selection of higher families usually does not have lower pin-count packages anyway.

    JW

     

    Super User
    February 19, 2024

    I don't know where cube gets this information from,

    In the timer xmls in IP subdirectory you'll find something like:

    <Mode Name="Encoder_Interface" UserName="Encoder Mode" RemoveCondition="($IpNumber=6)|($IpNumber=7)|($IpNumber=18)|($IpNumber=9)|($IpNumber=10)|($IpNumber=11)|($IpNumber=12)|($IpNumber=13)|($IpNumber=14)|($IpNumber=15)|($IpNumber=16)|($IpNumber=17)">

    note the RemoveCondition tag, i.e. this is list of timers (timers' numbers) which don't have encoder mode. Others do.

     

    otherwise I could write a script to list all devices with 5 or more timers with the encoder mode.

    If you do, please publish.

    JW

    VidiconAuthor
    Explorer II
    February 19, 2024

    Ow this is useful to know, I don't have time to write a full script to parse this today, but definitely something i want to do that in the future. 

    VidiconAuthor
    Explorer II
    February 19, 2024

    I did create this simple script:

     

    import os
    import xml.etree.ElementTree as ET
    from pprint import pprint
    
    def list_timers_in_mcu_files(directory):
     instance_names = {}
     for filename in os.listdir(directory):
     if filename.endswith('.xml') and filename.startswith('STM32'):
     tree = ET.parse(os.path.join(directory, filename))
     root = tree.getroot()
     instance_names.update({filename: []})
     timers = []
     for element in root:
     instance_name = element.attrib.get('InstanceName')
     if instance_name is not None and 'TIM' in instance_name:
     timers.append(instance_name)
     instance_names[filename] = timers
    
     return instance_names
    
    directory = 'mcu'
    instance_names = list_timers_in_mcu_files(directory)
    pprint(instance_names)

     

     It lists the timers per MCU (file), Now I have to look for an MCU that has the Timers that I need. 
    There are some nice tables in AN4013.

    Graduate II
    February 19, 2024

    Nice script! IRTIM should get excluded. As suspected, U5 devices offer a lot of possible usefull devices.

    Super User
    February 19, 2024

    Some LPTIM in some STM32 have encoder mode, too, IIRC. I have no personal experience.

    JW