Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

ADC communiction with UART to Labview

Solved!
Go to solution
It is random and you aren't joining 3 bytes to form a single value. You can use your dataviewer program but if you want to use LabVIEW or any other program, you need to do it correctly. I would suggest you spend some learning learning the fundamentals of serial data transmission and how vendors of commercial products do it.
0 Kudos
Message 11 of 47
(4,661 Views)

okay well how do you bring back the numbers can you help me. and i also attached the micro code, the main is the dma testing.c, maybe you can tell me what i doing wrong.

0 Kudos
Message 12 of 47
(4,655 Views)

you can view all code in text files

 

0 Kudos
Message 13 of 47
(4,654 Views)
Solution
Accepted by muscles05
To add some more details, you start transmitting bytes A,B,C. The read is asynchronous so the first byte you read is EITHER A,B,or C. That's random. If the write by your micro does something more such as send a start and/or end character, then you synch. You need to determine the details of the writing. I'm going to guess you did not write the micro code.
0 Kudos
Message 14 of 47
(4,653 Views)
Just saw you attached a zip file. I get an error trying to unzip. I'm posting by phone and the problem is probably at my end, sorry I can't view it.
0 Kudos
Message 15 of 47
(4,647 Views)

@muscles05 wrote:

it not random cause when i send it to a dataviewer program that designed to view the ADC it actually produces my AC signal. and forms a sine wave.


Do you start the ADC before or after the data viewer?  Here is the thing with streaming data, you need something to tell you which byte is what.  If you just have the ADC streaming the data and then your program randomly starts reading it, you have no clue if you started reading half way through the sample.  What I typically see with something like this is a synch byte (typically 0x02) and possibly even a CRC after the message.

 

So your ADC is sending an I16, Big Endian.  So what I would do is read X bytes and then use the Unflatten From String to convert that read string into an array of I16.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 16 of 47
(4,635 Views)

Here is the code I am using to send data to LabVIEW. First I fill a buffer with a long int the with a max value of 16,777,215 because it is a 24-bit ADC. The buffer counts the number of 10millions, millions, 100thousand,...,ones. The LSB value of the buffer is '!' to signal the beginning of the buffer and the MSB value is '0x38' to signal the end of the buffer. The write buffer is then force sent through the UART to LabVIEW.

 

----------------------------------------------------------------------------------------------------------------------------------------------------

/*
 dsPIC33FJ256GP710A
 note:
 union
{
 unsigned long ADC_ch_0;
 struct
 {
  unsigned int ADC_ch_0_LSB : 8;
  unsigned int ADC_ch_0_lower : 8;
  unsigned int ADC_ch_0_middle : 8;
  unsigned int ADC_ch_0_upper : 8;
 };
} voltage_ch0;
 Vch0[read_counter] = voltage_ch0.ADC_ch_0;
*/
 

 case 7:
// Send DATA from buffer to LabVIEW
  main_state_machine++;          // Go to next state
  TX_counter = 1;
  DMA2_buffer_WR[0] =  '!'    // A new serial transmission is starting
  hexdec_long(Vch0[write_counter]);
  DMA2STA = __builtin_dmaoffset(DMA2_buffer_WR); // Initialize DMA2 buffer address
  DMA2CNT = TX_counter;     // 10-bit DMA Transfer Count register
  DMA2_buffer_WR[TX_counter] = 0x38  // All buffer data has been sent
  DMA2CONbits.CHEN = 1;          // Enable DMA2 Channel
  DMA2REQbits.FORCE = 1;          // Force start
  break;
 case 8:
// Wait for DMA2 transfer to complete...IFS1bits.DMA2IF = 1;  //DMA2 Interrupt Flag 
  break;
 case 9:
// Send next DATA
  if (write_counter < MAX_BUFF)     //MAX_BUFF = 255
  {
   write_counter++;       // increment buffer read counter
   main_state_machine -= 2;       // Go back 2 steps
  }
  else main_state_machine++;        // Go to next state
  break;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// hexdec_long.c
// Fill DMA2_buffer with Vch0 values
extern char DMA2_buffer_WR[];
extern unsigned char TX_counter;
 

void hexdec_long(unsigned long count);
 char tens;
 char ones;
 char hundreds;
 char thousands;
 char thousand10s;
 char thousand100s;
    char mill;
    char mill10s;
 
void hexdec_long( unsigned long count )

 mill10s=0;   
  mill=0;
  thousand100s=0;
  thousand10s=0;
 thousands=0;
 hundreds=0;
 tens  = 0;      
 ones = 0;
 
  while ( count >= 10000000 )
 {
  count -= 10000000;   // subtract 100000
  
  mill10s++;     // increment 10thousands
 }
 
  while ( count >= 1000000 )
 {
  count -= 1000000;   // subtract 100000
  
  mill++;     // increment 10thousands
 }
 
  while ( count >= 100000 )
 {
  count -= 100000;   // subtract 100000
  
  thousand100s++;     // increment 10thousands
 }
 
 while ( count >= 10000 )
 {
  count -= 10000;   // subtract 10000
  
  thousand10s++;     // increment 10thousands
 }
 

  while ( count >= 1000 )
  {
   count -= 1000;   // subtract 1000
  
   thousands++;     // increment thousands
  }
 
   while ( count >= 100 )
   {
    count -= 100;   // subtract 100
  
    hundreds++;     // increment hundreds
   }
 

    while ( count >= 10 )
     {
      count -= 10;   // subtract 10
  
      tens++;     // increment tens
     }
 
      ones = count;     // remaining count equals ones
    
                    DMA2_buffer_WR[TX_counter]=mill10s+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=mill+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=thousand100s+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=thousand10s+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=thousands+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=hundreds+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=tens+0x30;
     TX_counter++;
     DMA2_buffer_WR[TX_counter]=ones+0x30;     
     TX_counter++;
}    
0 Kudos
Message 17 of 47
(4,633 Views)
Since you are sending a byte to signal the start, then you should be able to synch. Read one byte at a time until you see the !. One r that is detected, you set the number of bytes to read and they should be in the order you expect. Subsequent reads can be the entire packet where you discard the start and end bytes.
0 Kudos
Message 18 of 47
(4,622 Views)

Can you explain a little better how do you get them to display correctly, what function looks for this and do I need to use the visa W or can I just keep using visa R without it in labview 

0 Kudos
Message 19 of 47
(4,618 Views)
You just need a read. I would suggest that you right click on the string indicator and select hex display. It does not the change the data but clearer to understand. When you do your comparison (i.e. an equals function), do the same thing with the constant used for the comparison.
0 Kudos
Message 20 of 47
(4,606 Views)