Discussion in "PIC Microcontroller Discussion" started by    leeds    Mar 7, 2008.
Fri Mar 07 2008, 02:25 am
#1
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;

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
#2
You probably need to specify input buffer size.
set(s, 'InputBufferSize', 512) ;

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm
HumanTak
Sun Apr 21 2024, 12:26 pm