View previous topic :: View next topic |
Author |
Message |
Skirmitt
Joined: 19 May 2009 Posts: 60
|
Converting 10 bit ADC value to 14 bit midi message |
Posted: Fri Oct 14, 2011 1:22 am |
|
|
As stated in a previous topic I'm working on a midi controller. For the pitch fader I want to use 10 bit ADC values as it is far more accurate to beatmatch. This is the code I have so far. I don't think it works correctly. The LSB part is ok but the MSB part only goes from 0-7. I do want the MSB part also to go from 0-127. I'm not familiar with bitmasks and don't understand them completely.
Code: |
set_adc_channel(0);
//get ADC
faderADC = read_adc();
//get LSB & MSB for a 14 bit number
faderLSB = (faderAdc & 0b0000000001111111);
faderMSB = (faderAdc & 0b0011111110000000)>>7; //is this correct ??
//check if value has changed
if ((faderADC < oldfaderADC - FADER_RANGE)||(faderADC > oldfaderADC + FADER_RANGE)) {
//send on pitchbend channel 1
midipitchbend(224, faderLSB, faderMSB);
oldfaderADC = faderADC;
|
These are the PIC settings
Code: |
#include <16F886.h>
#device ADC=10
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=8000000)
#use rs232(baud=31250, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define FADER_RANGE 20
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Oct 14, 2011 2:05 am |
|
|
You need to become clear about intended data alignment. 10 bit to 14 bit can be either left or right aligned. Now you have it right alligned. You most likely want it left aligned to cover the full 14-Bit range. This implies the upper 7 bit of ADC value copied to high byte and the lower 3 to low byte, zero filling 4 bits. |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Fri Oct 14, 2011 3:23 am |
|
|
Adding this line did what I wanted:
Code: |
faderADC = (faderADC << 4);
|
|
|
|
|