Encoder Phase Difference and Custom PCB problems - Page 1
Forum section: electronics / beginners

author: omiks3
author_rank: Newbie
timestamp: February 19, 2021, 11:13:57 pm
content: Hi,This will probably be the first of many questions relating to this project so bear with me.I decided I wanted to learn about STM32 uC's and PCB design. I thought making a macro keyboard would be an easy place to start so put everything together on a breadboard using a STM32F103C6 breakout board. I got all the software working how I wanted then moved on to the PCB design, I think I did a reasonable job for my first time (Only two bodge wires were needed). I ordered the boards and they were delivered after new years, unfortunately all STM32 uC's are out of stock everywhere so I desoldered a STM32F103 off a breakout board and soldered it onto my PCB. When I first powered the board everything seemed to work alright, I could control the volume with the encoder and the buttons were working. Then the USB stopped working.I'm slowly going through and troubleshooting the board and am learning about correctly bringing up a board. The way I am tackling it is to debug each component individually, I have the PWM LEDs working as I would like, and have moved onto the encoder. I am using Timer 1 in encoder mode to count pulses and direction of the encoder, as I've said everything is working great on the breadboard. The problem I am having with the encoder is it will not consistently increment/decrement the counter by 1 usually jumping by 2 or 3. I have tried using different filter values which hasn't worked.I have now checked the encoder using the oscilloscope and compared it to the one on the breadboard (They are 2 different encoder models). As shown in the first two pictures the encoder on the PCB is on channel 1 and 2, the encoder on the breadboard is on channel 3 and 4. The phase difference of the PCB encoder is a maximum of 2.2ms while the datasheet (http://cdn.sparkfun.com/datasheets/Components/Switches/EC12PLRGBSDVBF-D-25K-24-24C-6108-6HSPEC.pdf) states that it should be >=3.5ms. The encoder on the breadboard has a phase difference of about 5.6ms.Would this be causing the Timer counter to increase/decrease by 2 or 3 steps instead of 1? If the uC is operating at 48MHz I would think that it wouldn't be a problem but my experience is lacking. I've also attached a picture of the testing setup if that helps.Thank you for your help.

author: drvtech
author_rank: Regular Contributor
timestamp: February 20, 2021, 12:51:55 am
content: I think you've just got some contact bounce. Look at the leading edge of the first and second yellow pulses and the first green pulse. It's difficult to be certain at that resolution but the yellow ones look like multiple edges and the green one definitely has a glitch. You need a small RC filter to get rid of the glitches. I think you got lucky with the first encoder as it seems to have very little bounce.

author: omiks3
author_rank: Newbie
timestamp: February 20, 2021, 05:54:24 am
content: You're right there does seem to be some bounce, it's just not consistent. I thought the filtering within the controller would have sorted it out. I might try to debounce it more in software as I don't want to solder on more components to the board.