free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
leeds
Thu Mar 06 2008, 12:55PM
 User Offline
Registered Member #6487
Joined: Thu Mar 06 2008, 11:54AM

Posts: 1
Thanked 0 times in 0 post
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;

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

CODE:
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 Fri Mar 07 2008, 07:55PM ]
Back to top


sashijoseph
Thu Mar 06 2008, 09:44PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 554
Thanked 124 times in 117 posts
You probably need to specify input buffer size.
set(s, 'InputBufferSize', 512) ;

Let there be music........
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems