2023-01-25 (W) EWC_Box Encoder testing

I needed I2C communication, so the Mega could only utilize four interrupt-capable pins therefore, I could only spare one input for each encoder with two pins. I relied on reading the pins with regular code scanning in past projects, but they screwed up so often that I stopped including them. Encoders give two signals each time they spin one increment, and the order they connect tells their direction, but if the controller does not recognize the change in time, it may sense the rotation inaccurately. The easiest way would be to connect each pin where it can trigger an interrupt and see which goes high first. I plan to attach the second lead of each encoder to standard inputs and use the high-speed inputs to immediately check the state of its companion and determine direction.

I wrote a sketch for an Arduino Mega to read four encoders from scratch. I fixed the early bugs, like missing line-ends and duplicated variable names, and uploaded the first trial. The program worked surprisingly well, and the hardware seemed intact. I had two problems with the code. The first problem was that only one encoder could count down, while the other three only increased. The second problem was that the count skipped around, which suggested the system needed some debouncing.

I figured out that the three problematic encoders were looking at the wrong companion pins so they wouldn't decrement, and that was an easy fix. To solve the debouncing, I added a timer check to limit how soon to recognize a new event. I plotted the encoders, and they worked well, but the little jags in the middle of sloping lines indicate where they had a blip, but they ultimately remained accurate.
Encoder readings

The rest of the posts for this project have been arranged by date.
First time here?

Completed projects from year 1
Completed projects from year 2
Completed projects from year 3
Completed projects from year 4
Completed projects from year 5
Completed projects from year 6
Completed projects from year 7
Completed projects from year 8

Disclaimer for http://24hourengineer.blogspot.com and 24HourEngineer.com

This disclaimer must be intact and whole. This disclaimer must be included if a project is distributed.

All information on this blog, or linked by this blog, is not to be taken as advice or solicitation. Anyone attempting to replicate, in whole or in part, is responsible for the outcome and procedure. Any loss of functionality, money, property, or similar, is the responsibility of those involved in the replication.

All digital communication regarding the email address 24hourengineer@gmail.com becomes the intellectual property of Brian McEvoy. Any information contained within these messages may be distributed or retained at the discretion of Brian McEvoy. Any email sent to this address, or any email account owned by  Brian McEvoy, cannot be used to claim property or assets.

Comments to the blog may be utilized or erased at the discretion of the owner. No one posting may claim property or assets based on their post.

This blog, including pictures and text, is copyright to Brian McEvoy.
2022-01-23

Comments