Rerouting all the signals

A project log for Tiny CAN Positioning Motor Controller

A 12A/28V DC brush motor controller with position feedback that speaks CAN-BUS... in one square inch.

Pierce NicholsPierce Nichols 08/15/2018 at 04:550 Comments

So, it appears that I stuffed up the routing of the signals into the ATTiny816 on my initial design... time to re-do it, right this time. Here's a quick overview of what I need to connect

Forced Allocations

Three of these can only go to particular pins.

Timer/Counter Allocations

There are three functions in this design that require timer/counter services (timer interrupts, PWM, and encoder input), and only three timer/counters on the chip. These timer/counters are connected to a fairly limited set of pins. 

Allocating the PWM is simple, because Timer/Counter D has specific functions for generating complementary PWM signals with configurable deadband and other features particularly useful for controlling motors. It has four output pins -- PA4, PA5, PC0, and PC1. Since PC0 and PC1 are already allocated to the SPI, PA4 & PA5 are allocated to PWM.

The encoder is a bit trickier, because I want to count both the rising and falling edges of phases A & B of the encoder in order to quadruple the number of counts per revolution. The timer/counter peripherals are only able to count on a single channel. Luckily, the ATTiny816 provides configurable custom logic (CCL) to enable me to get around this limitation. The XOR of phase A & B will transition on every edge, and the CCL provides the ability to do this. Unfortunately, there are only two available CCL input pins still available, PA1 & PA2, so they are allocated to encoder phases A & B. Since only Timer/Counter B offers a frequency measurement mode, the encoder is allocated to Timer/Counter B.

This leaves Timer/Counter A to generate the timer interrupts that drive the control loops

Other Allocations

The analog input from the motor must go into one of the analog pins, which are PA0-7, PB0-1, and PB4-5 on the '816. In order to limit the amount of re-routing, we'll allocate PA6 to motor current feedback.

Phase Z of the encoder fires once per revolution to provide a more absolute position signal. One of the nice features of the '816 is that any pin can be used as an interrupt, so we'll leave it where it is (PB3)

The motor enable line can go anywhere, so we'll move it the shortest distance available, to PA7.

The CAN reset and interrupt lines can go anywhere, so we'll allocate them to PB0 and PB1.

All of these allocations are subject to change for routing convenience. Here's a handy table:

Pin NamePin (QFN)Function
Encoder Phase A
PA21Encoder Phase 2
PA32Clock Input
PA45Motor PWM 1
PA56Motor PWM 2
PA67Motor Current Sense
PA78Motor Enable
PB014CAN reset
PB113CAN interrupt
PB311Encoder Phase Z