10bit Right justified encoded char
Discussion in "PIC Microcontroller Discussion" started by leeds Mar 7, 2008.
Fri Mar 07 2008, 02:25 am
hello admin,
i have a problem reading the 10-bit right justified 2 byte data from the PIC. i'm using matlab to read the ADC. here is my PIC C code;
using hyperterminal and other serial port monitors, i can get the ADC data. but with matlab it gives me the error: inputBufferSize must be greater than zero which means no data is in the port.
initialization of the serial port with the matlab code was made, serial object creation, serial settings; BaudRate @9600 as with the PIC,8bits, Parity=none
how can i decode the 8 bit encoded character send by the pic?
i have a problem reading the 10-bit right justified 2 byte data from the PIC. i'm using matlab to read the ADC. here is my PIC C code;
main() { long int adcValue; //16-bit A2D reading storage char adcHI, adcLO; //8-bit real time frames storage setup_adc_ports(A_ANALOG); //set all ADC pins to analog setup_adc(ADC_CLOCK_INTERNAL); //enable A2D module set_adc_channel(0); //read channel 0 delay_us(20); //delay for sampling cap to charge while(TRUE) { adcValue = read_adc(); //start conversion adcHI = (char)((adcValue> > 5)& 0x1f); // 0|0|0|d9|d8|d7|d6|d5 adcLO = (char)((adcValue & 0x1f)|0x80); // 1|0|0|d4|d3|d2|d1|d0 putc(adcHI); // Transmit Byte 1 (d9...d5) putc(adcLO); // Transmit Byte 2 (d4...d0) delay_ms(5); //small delay before read } }
using hyperterminal and other serial port monitors, i can get the ADC data. but with matlab it gives me the error: inputBufferSize must be greater than zero which means no data is in the port.
initialization of the serial port with the matlab code was made, serial object creation, serial settings; BaudRate @9600 as with the PIC,8bits, Parity=none
s = serial('COM1'); fopen(s); set (s, 'BaudRate', 9600); data = fread(s,s.BytesAvailable); n = length(data); i=1; while (i<n/2) { } end fclose(s); delete(s); clear(s);
how can i decode the 8 bit encoded character send by the pic?
[ Edited Sat Mar 08 2008, 09:25 am ]
Fri Mar 07 2008, 11:14 am
You probably need to specify input buffer size.
set(s, 'InputBufferSize', 512) ;
set(s, 'InputBufferSize', 512) ;
Powered by e107 Forum System