Preamp Control - Volume, input, mute, remote

and also look at using the other interrupt pin of the Nano for one pin of the encoder, which requires a couple cuts and jumps
Currently you are using the other interrupt pin (D3) for the LSB of the volume output. I suppose for the purposes of investigation you can ignore the LSB of the volume (tie it down?), comment out the existing code for that pin and temporarily settle for only 128 volume levels.

Geoff
 
Yeah, that is why I would have to do two cuts then two jumper wires to change the LSB another pin as it controls the volume display decoding also, while moving encoder pin A to D3 to use the interrupt, and some code changes.
But if PinChange interrupts work on A0 and A1, the current encoder pins, it would work with just code changes which is preferable to cuts and jumps.
 
Hi Stratus46,

For those scope readings were there caps across the pins to ground. It is recommended to use a .01uf cap on each pin to absorb the noise, and I find this to work.

Finding good rotary encoders that don't have shaft wobble and are not expensive is the hard part. The Optical units are nice but too expensive, though I might take another look at them.
___________________
For the code, an interrupt is the best way to get the instant of the pin falling, polling can take too long and can miss a state as it is doing now, if at the interrupt you then immediately read the other pin you can determine the direction. I will learn more of the Pin Change Interrupt, which works with the current PCB layout, and also look at using the other interrupt pin of the Nano for one pin of the encoder, which requires a couple cuts and jumps, then in an ISR immediately read the other pin then return to the main loop to determine up or down.

Anyways, more stuff to try and investigating Geoff's code. Just need more time from my regular job to play.
Hi John,
I have no capacitors to reduce noise. There are simply 10K pullup resistors
on all outputs of the encoder. The caps just slow the rise/fall times and would
be better though I only use the local control very rarely. The vast usage is via
IR remote with ramp up/down for MUTE. I've attached another rev of the HT
electronics sketch. With this one you can change the value of "slow" to change
the update rate. It also reports "FWD" or "rev" rather than same text and the
value. It's much easier to see hiccups in the list. I was looking at shaft encoders
both optical and machanical. One model of Grayhill mechanical claims 25000
cycles where a cycle is 1 full turn forward amd backward. The optical is rated
1 million cycles with some parts in hundreds of million cycles. I get to cheat with
this since I retired at the end of January and can waste a little extra time.

 

Attachments

  • HT_rotary_nolib.txt
    2.6 KB · Views: 97
John,

What you have put together sounds great; one can argue about technical approaches to the issue of volume attenuation, but I don't know of another product that sounds significantly better with your design philosophy. Hopefully, the solution is just getting the final glitches out of the encoder code (I'm not enthusiastic about another board parts swap) that will turn this into something that will meet the demands of commercial users.

If you do end up making hardware changes, it may be time to consider separating the switching and volume functionality. It currently defaults well to an installation in front of the preamp. While possible, implementation after the preamp is difficult. Putting that functionality onto different boards could resolve this issue and better address users who only switch digitally. For DIY users, putting together a preamp solution that can fit in a readily available case appears to be a major issue with the size of your analog board. Given the size of the resistors you are using, a three-stack solution would be better. Putting the switching on one board and each channel on a separate board could provide a solution that has a better chance of fitting in the cases available to DIY users.

Don't get me wrong, I very much like your attenuation approach, but getting it in a format that is flexible enough to fit in "standard" cases will go a long way towards providing a more universal product.

Regards,

Roy
 
I got tired of testing company code and ran into a bug that was a show stopper so documented it and sent an email to the project people, work on that project is on hold giving me time to work on the preamp. I was able to read more about Pin Change Interrupts and reworked the code to use it. Tomorrow I will test it and see if it works any better. Some of the code doesn't make 100% sense yet but I will find out if it is better, worse, or doesn't work at all. :)

Hi Roy,
As to breaking the board up into sections I am kind of already moving that way. I already have a display board at 2"x 2 1/2", the encoder board is a 1"x1" board, and the attenuator board is a 3"x 10" board, so it can be mounted stacked over another board or mounted on the side wall of the preamp. The attenuator board could be split in two, left and right channel, for two 3"x5" boards, but if I turn another board I will use a different Arduino with more pins so I can control left and right channel together with some independence for balance control. The switching will have to be a separate board for input and relays and a small board for the input select button and maybe mute button. It currently has a rotary encoder for volume control, and an IR receiver to do volume and mute from an Apple type remote. It has the same encoder issue, so solve one and have solved both. I can send you a set of boards if you want to play with it.
 
Hi All,
Well today I test the updated code and of course it didn't work at first. After a little experimenting I found the ISR worked but I wasn't resetting the variable for when the knob moved in the main loop, after correcting that it works as you would expect it to work, without glitches.

So attached is the new code. Download it to the Nano with the Arduino IDE and you're golden.

BTW is you rename the file with .ino the IDE will recognize it easier.
 

Attachments

  • Volume_Control9pci.txt
    15.4 KB · Views: 93
Just one note, I am using a stripped down version of the irremote program, I pulled out all the send stuff so it is only receive, but for you to use the ir library from the Arduino.cc site remove the 2 from #include <IRremote2.hpp> so it reads #include <IRremote.hpp>.

So a little retrospective on the software. The revision number you can see for the code tells you this is the ninth version of the code. Each version used different schemes for the IR remote and the encoder. I know the rotary encoder goes through four transitions per tick, or detent if you have them. I tried multiple schemes on the encoder, I had elaborate code for the four states, but with polling and the Encoder library without interrupts I found that it gave poor to fair performance. I was ok using it with the fair performance for my own system as I use the Remote half the time and only using the knob to start up but others, like Roy, had issues with it so I kept working on it. You really need interrupts to make the rotary encoder work properly if you are doing anything else in the code that takes time away from the polling. So I have previously used external interrupts that pins 2 and 3 of the Nano supports but this was the first time to learn about Pin Change Interrupts, and thanks to all for the ideas and the support. A day of searching the info., an evening of reading about the info., an evening writing a little code, an afternoon debugging and testing. Best fix so far.
 
So I have previously used external interrupts that pins 2 and 3 of the Nano supports but this was the first time to learn about Pin Change Interrupts, and thanks to all for the ideas and the support. A day of searching the info., an evening of reading about the info., an evening writing a little code, an afternoon debugging and test
Nice to see you directly writing to the AVR PCI control and mask (PCICR and PCMSK2) registers in the last few lines of the Setup() routine to enable Pin Change Interrupt for the A0 and A1 pins being used by the encoder.

In the ISR, can I suggest you do a direct read of the input port (get a snapshot of all pins for that port in one go) followed by similar bit manipulation to what you're doing now ,e.g.

//When Interrupt triggered read encoder pins
someNewVariable = PINC;
boolean A_val = (someNewVariable & 0x01);
boolean B_val = (someNewVariable & 0x02);
 
John,

I finely had a chance to get all three sets of boards up and running with your old Nano code. I wanted to do that before I tried updating to the latest version to eliminate variables. I set up Anduino version 1.8.13, changed IRremote2 to IRremote in the code and used Library Manager to install version 3.61 of the IRremote.

When I try to compile the code I get the following error message:
WARNING: library IRremote claims to run on avr, megaavr, samd, esp8266, esp32, stm32, STM32F1, mbed, mbed_nano, rp2040 architecture(s) and may be incompatible with your current board which runs on sam architecture(s).

In file included from C:\Users\roy\OneDrive\Documents\Arduino\libraries\IRremote\src/IRremote.hpp:265:0,

from C:\Users\roy\OneDrive\Documents\Arduino\Balanced Preamp Switching\Volume_Control9pci\Volume_Control9pci.ino:17:

C:\Users\roy\OneDrive\Documents\Arduino\libraries\IRremote\src/private/IRTimer.hpp:1561:2: error: #error Internal code configuration error, no timer functions implemented for this CPU / board

#error Internal code configuration error, no timer functions implemented for this CPU / board
^
Volume_Control9pci:79:18: error: macro "ISR" passed 1 arguments, but takes just 0
ISR (PCINT1_vect){
^
exit status 1
macro "ISR" passed 1 arguments, but takes just 0

Looks like some kind of hardware incompatibility but this is on your Nano that is already running a previous version of your code. Should I be using a different version of arduino or the IRremote library?

Regards,

Roy