Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

Anonymous
Not applicable

Hello everyone,

My question is related to the sample rates. What is the criteria for choosing the ADC sample rate for an arbitrary WaveDAC sample rate?

In my case, my WaveDAC (50 kSPS) is directly connected to the ADC( 17- bits; 5kSPS and actual conversion rate = 4935 SPS). Does it make sense?

Telmo Barros

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

If ADC_DelSig samples at 5 kHz, then DAC should be updated at same rate. What is the point to update it faster? Basically, measure ADC sample, write it to DAC, repeat. Set DAC to Register write, don't use sampling clock.

View solution in original post

31 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

If ADC_DelSig samples at 5 kHz, then DAC should be updated at same rate. What is the point to update it faster? Basically, measure ADC sample, write it to DAC, repeat. Set DAC to Register write, don't use sampling clock.

Anonymous
Not applicable

Makes sense. You mentioned the smoking clock. Why should I not just or?

Sorry for these questions but I'm a beginner.

0 Likes

It would be easier to advice if you tell more about the  project.

0 Likes
Anonymous
Not applicable

The idea is to develop a data acquisition channel using PSoC 5LP.

At this moment I'm just using the wavedac + adc connection to make sure I can send data from the adc to the UART (then matlab or python to process the data)

In the end, there'll be an array of sensors between the wavedac and adc delsig.

I've attached the project bundle

0 Likes

The bottleneck is UART.    The sampling frequency is determined by this.

For 16bit ADC (2 bytes) and UART 115200, there are no more than 5000 samples per second (check it) for one channel.

Anonymous
Not applicable

So, let me get this straight. If I want to use the UART, with a 16-bit ADC,  I have to limit the number of samples to 5000, otherwise some do not go through, right?

Basically, what I'm asking is if I can transmit a 16-bit value (ADC) through the UART

0 Likes

Sending data through UART can be a bit difficult.

You have generally two choices: Sending binara data and sending ASCII data.

Binary data will only need two bytes to transmit for a 16 bit value, but you can get into troubles to synchronize or when one byte is dropped.

ASCII data will need 5 characters  maximum + a delimiter byte (i.e. '\n') to separate the items. Additionally some CPU efford is needed for conversion.

Binary data can be transmitted more safely using a different interface as I2C or SPI. Man machine interface is usually made with UART.

Bob

Anonymous
Not applicable

I see. I'm still reading the datasheets, but do you know if I can also connect either the SPI or I2C with Matlab? What I mean is, can I send data to the COM port and fetch it with another program?

Thank you very much for your attention!

Telmo Barros

0 Likes

Yes there will be losses.

I have a very old project of a single-channel oscilloscope on UART: PSoC_OSC_12bit.zip                           

To determine the high and low byte, I used the most significant bit in the byte

so the bit depth can not be more than 14 bits.  it's here (Russian).

Perhaps USBUART is suitable for you there the transmission is carried out by packets, that's why it is known where Lo and Hi bytes is.

For example:  Data acquisition module with external ADC (ADS7818)

Alternatively, you can use a  modbus  or   ASCII simulator module ICP-DAS (protocol DCON)

http://www.cypress.com/?app=forum&id=2233&rID=92508

http://www.psocdeveloper.com/forums/viewtopic.php?f=42&t=8629

https://community.cypress.com/thread/19950

unfortunately many references are no longer relevant

Anonymous
Not applicable

I'm going to check your suggestions. I'm still struggling a bit on understanding the size of the information actually sent.

So, if I wanted to transfer a 16-bit number, I should make sure that the COM port receives an 18-bit data packet?

Thanks for helping me.

Telmo Barros

0 Likes

Sorry,  I don't use Matlab. My tool - LabVIEW.

For SPI and I2C, I use part of the PSoC® 4 CY8CKIT-049 4xxx Prototyping Kits. An example here (LabVIEW and Visual Studio C ++,  Russian)

COM port transmits a stream of bytes. If you want to continuously pass a word (2 bytes) then you need to figure out how to identify the LSB and the MSB in the data stream.

I use 2 ways:

1 - significant bit in a byte is a marker (0 - Lo byte, 1 - Hi byte, ). In this case, I'm limited useful information = 14 bits.

2 - USBUART transmission packets in 64 bytes (32 x 16bit) allows me to know exactly the data structure.

Anonymous
Not applicable

- USBUART transmission packets in 64 bytes (32 x 16bit) allows me to know exactly the data structure.

How does this work?

0 Likes

USBUART is a 64-byte packet exchange.

When you send and receive a packet, you know the number of any byte.

Your task :

1 - to come up with a data structure for this package.

2 - organize the transfer of packets with a certain frequency.

3 - Create a program for PC to receive packets in the PC and disassemble them - this is the most difficult.

The simplest example:

- organize the cycle of sending the table from 64 bytes (0, 1 ,,,,, 63) to USBUART for example with a frequency of 1Hz.

- Create a program for the PC that will receive the data.

0 Likes
Anonymous
Not applicable

I'm not sure I understood what you wrote, so i'm going to repeat with my own words.

USBUART is a 64-byte packet exchange - does it mean I could, possibly, send a maximum of 64 bytes through UART?

Also, when you mentioned organizing the sending cycle, my mind went through a couple options:

- save all the converted data from the ADC in a 64 sized array (for example), then send each value through UART

- or send a value at each time.

My problem stil maintains though, I just want to be able to send a 2-byte sized value through it (I've already managed the receiving end)

Sorry if I didn't understand your explanation

0 Likes

USBUART is a USB CDC device simulating a COM port.

You need to find information about how it works.

I added an example that can help you.

0 Likes
Anonymous
Not applicable

It says that:

" The version value CyDesigner.Common.ProjMgmt.Model.CyPrjMgmtFolderSerialize' for type '3' is an unknown version.. This could mean that the data was corrupted or that it was created by an unsupported software version."

Sorry, I'm a newbie on this sort of projects. My issue is this:

I have the first wave as an output from the VDAC.

pastedImage_0.png

but, instead of the same (or very similar) wave, I get this on matlab:

pastedImage_1.png

After everything you guys said, I'm assuming my problems are:

- UART can't send more than 1 bytes of data (my reads from the adc are 16 bit long)

- or

- ADC sampling rate might be off.

I'm completely lost.

0 Likes

It seems this is a problem with timeouts.

PSoC sends packets of 64 bytes 1000 times per second (it seems).

PC (matlab) collects data into a large buffer (for example 4096).

Therefore, you need to give the program the ability to accumulate a buffer - I have a polling interval of 100 - 500 mSec.

I modified the project a little and added the PSoCUSBUart.exe test program, but it only works for XP / Win7x32.

ps you projects in PSoC Creator 4.1?

USB_.jpg

0 Likes
Anonymous
Not applicable

It's PSoC Creator 4.0

Telmo Barros

0 Likes

project for Creator 4.0:

0 Likes
Anonymous
Not applicable

As I was reading through the datasheets and the project you shared, one very humble doubt came up. Do I make the same connections (wire wise), as I was doing with the other UART or there is no need to wire anything?

Before I connected the TX pin to p0.1 and RX pin to p0.0

0 Likes

There is no UART in my project. Only USBUART.

To connect, usePins P15.6, P15.7    (CY8CKIT-059 PSoC 5LP    connector J6 )

usb_.jpg

0 Likes
Anonymous
Not applicable

Yes, my mistake. Only after some diving on the data sheets did I see that the pins are part of the USB connection.

Thank you so much. Now I just need to create the python file to communicate with PSoC !

Once again, thank you very much. I'll try to do it

0 Likes
Anonymous
Not applicable

Once again, thank you for your (and the others) help. Yes, the interface (and example) you provided certainly work. The thing is, the values that it sends, each and every single one of them, are only 1 byte long. I want to send a big sized array (64 bytes is more than enough) but with each value being 2 bytes.

I've thought about some options to achieve this:

- convert 16 bit ADC sample to hexadecimal and send it (convert again on the pc side)

- convert every 16 bit sample to a string and send them (convert again on the pc side)

- separate the value in order to get first byte and second byte (send to pc and put them together)

I don't know if it is doable, but is there really no way to send a value that is 2 bytes long (just one value)?

0 Likes

It seems I do not understand you.

In my example, 32 words are sent (2 bytes of ADC)

  ....

if (cnt == 32) // accumulated 32x2 bytes, send to USBUART

{......

If you only need 2 bytes, fill in sample16 [0] and sample16 [1]

and leave the remaining 62 = 0.

then send 64 bytes as often as you need.

0 Likes
Anonymous
Not applicable

Yes, your implementation works. I receive data from the ADC (using the USBUART interface).

With that said, I decided to test by filling the buffer with the number 2000 (every slot has the number 2000).

Now, when I send it through USBUART:

- I don't understand this line: USBUART_PutData( (uint8*)&sample16, 64)

(the "uint8 *" means the address is in 8 bits or that every value is going to be 8bits?

- even if the above line does not have any influence, what I get on the PC side is an array filled with the values 208 and 7:

[208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7, 208, 7]) - like this.

0 Likes

For your example:

1. You have prepared an array of uint16 sample16 [32] = {0x07D0,0x07D0, .....};

    it contains 32 words with code 2000 (0x07D0)

2. USBUART_PutData () requires an array of bytes therefore:

(uint8 *) & sample16, 64) you pass a pointer to sample16 [] as an array of bytes (64 bytes)

p.s.    208,7,208,7,...   =  ( 0xD0,0x07,0xD0,0x07,...)         208 +7*256 = 2000

Anonymous
Not applicable

So it has been working all along? Now I feel stupid.

Why do you multiply by 256?

0 Likes

7 - high byte, 208(0xd0)-lo      2000 = 0x07d0    =7*256 +208

Anonymous
Not applicable

Thank you very much for helping me. After some further development, in order to give the user some control, I've tried to implement a Menu (switch case) on the PSoC side.

After some debugging, I think the DMA Flag stops working (after it is set to 0, it does not change it's value) with this implementation. The case that triggers the data gathering process is number 3!

0 Likes

I do not know the way to work with endpoints

I receive signals as per usual UART:

if(USBUART_DataIsReady() != 0u)               /* Check for input data from PC */

     {

       byte_count = USBUART_GetAll(buffer);           /* Read received data and re-enable OUT endpoint */

       key = buffer[0];

.....

}

Like that?

0 Likes
Anonymous
Not applicable

What you say makes sense, but, for example, if I want just a 500Hz (50kSPS) signal, there's no way that my ADC will reach such rates , since the 16 bit option only goes as high as 48kSPS.

Also, the nyquist theorem says that, in order to reconstruct a signal, it is advised to sample at 2 x F (F - signal frequency)

0 Likes