2023-01-04 05:02 PM
I have a project with a rotary encoder and I'm trying to use one of the timers in encoder mode to keep it's position but I can't seem to get it working and I don't know what I doing wrong. Any help would be much appreciated, if any more information is needed I will do my best to provide it.
The chip I am working with is an STM32G0B1CET6N. I am trying to use TIM1 to interface with the encoder. I have attached a screenshot of the code configurator of the pin assignments.
The encoder I am using is from CUI part number ACZ11BR1E-15FD1-20C. I connected it using the recommended filter which is a 10k pull up and an RC filter with a 10k resistor and 0.01uF capacitor on both A & B encoder lines. I did notice while going back to gather information for this post that I actually got my parts wrong on my board and used 0.1uF capacitors instead. While this does probably explain rounded corners of the square wave I was seeing on the scope, I don't really think it is the cause of my issue. I didn't think to get a screen capture of the A and B line waveforms but can get one if necessary of course. I have attached a screenshot of this portion of my board. I mounted the encoder's shaft directly to the PCB so that's why they're going to a header, I just hand wired the pins to those holes.
I used the code configurator to do the initialization setup and I have attached the main.c file. I then just started the encoder and saved the timer counter to a variable, just to make finding it in the debugger a touch easier and give the micro something to do. Running the debugger no amount of turning the encoder could get the counter to increment, neither the counter variable I made nor the SFR for the counter. I even double checked that I was retrieving the count correctly by manually changing the timer counter SFR and it populated my variable with the same value.
I have been up and down the code and can't seem to find anything that could be causing this or that I'm doing wrong. I used an oscilliscope to check the output wave forms for the A and B lines and they both looked as expected for a quadrature encoder. The only thing I found was that the A line was lower than the B line, measured on the encoder pins to ground. Channel B was 3.3v as expected but channel A was just 2v. After removing parts systematically to find the issue I found that none of the resistors or capacitors were faulty but that the fault appears to be within the micro. After completely lifting that pin (PA8) from the circuit, I could measure a resistence of 5k ohms from that pin to ground when the micro was running. This makes sense with the voltage measurements I was getting; ~.6v at the micro pin and ~2v at the encoder.
So it seems my micro is pulling the pin down with a 5k resistor or something and I can't figure out why. As far as I can tell the pull ups and downs are 40k anyway so it can't just be that. It is only affecting the one pin, not the other timer pin. I don't even know if this is what my issue actually is or if I'm just chasing my tail but it's the only thing standing out that I don't understand.
Any insight is appreciated. Thanks in advance!
Solved! Go to Solution.
2023-01-05 12:06 AM
This is the infamous USB-C PD Dead-battery gotcha.
After you disabled the pulldown, if the encoder still does not work, read out and post the TIM and relevant GPIO registers' content.
JW
2023-01-05 12:06 AM
This is the infamous USB-C PD Dead-battery gotcha.
After you disabled the pulldown, if the encoder still does not work, read out and post the TIM and relevant GPIO registers' content.
JW
2023-01-05 12:15 AM
2023-01-05 07:28 AM
This was it, thank you! That's what I get for not reading the note, lesson learned!