Close

Adjustable Effects, reading Analog

A project log for Supercon2017 Enhanced imagefx

I added a few fx, enhanced the UI (including a HW hack), and allowed the fx'd images to be saved.

toddTodd 12/05/2017 at 22:090 Comments

Especially when I had this idea that I would be able to enhance the UI such that I could create an expanded menu of options and thus more control over any individual effect, I started thinking what would be the best UX for that level of range of control. Then I remembered I had a number of Spectra ThinPots, and they work well with MCU's.

At first I wasn't sure if there was an analog input; pouring over the datasheet and schematic I wasn't sure.... eventually I realized the pin naming was confusing, and there were a couple analog inputs available on a few pins. I guess if I had paid attention to the Scope and looked at the scope.c code it would have been obvious :/

ProTip: always read the source code.

I guess deceived by Arduino, I thought reading from an analog input would be easy, but ... Once I "discovered" the scope.c code I just copied from it, but since it uses interrupts (which I didn't need) I started cutting out code.... and I cut too deep. That was a waste of a couple hours. I had to cull through this:

claimadc(1);
ANSELBSET = 3;
TRISBSET = 3;
CNPUBCLR = 3;

pb0save = RPB0Rbits.RPB0R;
pb1save = RPB1Rbits.RPB1R;
RPB0Rbits.RPB0R = 0;
RPB1Rbits.RPB1R = 0;
menustate = 0;

T2CON = 0b1000000000001000; // T2 and T3 in 32 bit mode
T3CON = 0b1000000000000000; // prescale /1
   
PR2 = 2 * (clockfreq / 2000000) - 1;
PR2 = 12;
AD1CON1 = 0b1000000001000100; // trigger on T3
//                  IIII   int threshold
AD1CON2 = 0b0000010000000100; //

AD1CON3 = 0b0000001000000000 | 1; // Tad
AD1CHS = 2 << 24 | 3 << 16;
AD1CSSL = 0b0000000000001100; // scan ch2 and ch3
IPC5bits.AD1IP = 6;

To get this setup code, and I'm not even sure I need all of it.

claimadc(1);
ANSELBSET = 1;
TRISBSET = 1;
CNPUBCLR = 1;

pb0save = RPB0Rbits.RPB0R;
pb1save = RPB1Rbits.RPB1R;
RPB0Rbits.RPB0R = 0;
RPB1Rbits.RPB1R = 0;

Then the read code:

AD1CHS = 2 << 16; // select channel
AD1CON1bits.SAMP = 1; // initiates sampling
while (AD1CON1bits.SAMP); // wait til sample done
while (AD1CON1bits.DONE == 0); // wait til conversion done
s0 = ADC1BUF0;

Next will be on the Hardware

Discussions