CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Converting 10 bit ADC value to 14 bit midi message

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Skirmitt



Joined: 19 May 2009
Posts: 60

View user's profile Send private message

Converting 10 bit ADC value to 14 bit midi message
PostPosted: Fri Oct 14, 2011 1:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 2:05 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Oct 14, 2011 3:23 am     Reply with quote

Adding this line did what I wanted:

Code:

faderADC = (faderADC << 4);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group