PSoC 059 DelSig_ADC to uart

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

I am trying to make an little oscilloscope that works in range of 0-5 V with PSoC 059 and a Python program only (no additional circuits). The python program is working fine, and it just prints the value that comes from UART. I don't know why, but my project on PSoC is not sending the right values.

   

Can someone help me please? I attached the project in this topic.

0 Likes
32 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

A string in C-language is always terminated with a null byte. Your buffer does not contain room enough to store the result of the "%d" formatting.

   

You do not explicitly wait for an ADC conversion ready which is recommended,

   

Do a hand-simulation with values of 9,99 and 101 to see what happens.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I already tested the buffer and it works, because the python code is adapted to It. What do you mean by " hand-simulation with values of 9,99 and 101" ? I tried to use the IsEndConversion() but I wasn't successful. Could you give me some example?

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Here is a similar project I did a while ago (on -050 kit), that might help you a little bit: http://www.hendriklipka.de/hardware/admscope.html (probably needs some porting to work correctly on a PSoC5LP)

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Daniel, when your adc-value is 101 your buffer will get busted because sprintf() tries to store "101\0" which are four bytes into a three byte buffer. The following statements will not touch the buffer any more.

   

When value is 99 buffer will contain "99\0" which would fit into, the next statements will (value < 100) overwrite the '\0' byte at end of buffer. The following PrintString() will send data until it happens to be a null byte.

   

Your turn to do that with value = 9

   

This is called a hand-simulation.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

hli, thanks for the project, but I need something more simple and near from what i had posted. My final goal is to create another system that uses this serial data.

   

Bob, I guess I understood what you meant. I'll fix it, but I have no idea of how to correctly wait the conversion, do you have some hint about it?

0 Likes
Anonymous
Not applicable

Does ADC_DelSig works on 2 complements?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Daniel, i am not quite claer about what you want to perform.

   

What do you want to send over the serial interface, what are the "_" for ???

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I found my mistake! I didn't see the ADC max value isn't set to vdd and that was causing me trouble. Thanks for all.

0 Likes
Anonymous
Not applicable

I found another problem! I don't know why, but the correct response is depending on frequency! For example, let's suppose that Vin is a sine signal. The UART output only has the correct sine shape for certain frequency, like 100 Hz, 120Hz, and going on. It looks like a aliasing effect is happening. What can be done to fix it ?

0 Likes
Anonymous
Not applicable

Hi Daniel

   

In order to have the "correct" wave form you need 2 conditions:
a) sample (and transmit) fast enough. Only if you sample several times faster your sine wave frequency you get a reasonable result. 
b) sample (and transmit) always with the same interval. Otherwise you can not define the point on X axis you just have measured.

   

The effect you are describing probably is more a result low sampling (and or transmit) rate. Never the less try first to ensure that you use fixed intervals and from there try speeding up things.

   

All the Best
Frank

0 Likes
Anonymous
Not applicable

I guess the main problem is when I try to read the adc value, because it interferes the read rate. I don't know why, but I have to use the CyDelay() function to get something. What should be the best way of reading ADC value?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Do not forget to wait for a conversion ready before reading the ADC value. By using a timer to fire an ADC reading you are able to have a constant time between two readings. UART is a comparably slow interface and can distort your readings.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I guess you're right, but I don't know how to make this wait. I didn't see any example of it yet. 😞

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The datasheet for the ADC lists al APIs. You will find an ADC_IsEndConversion().

   

Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I tried to use the ADC_IsEndConversion(), but may be only used when there is no DMA. I tried using it, but it keep stacked on the same command. As soon as possible I'll upload the project.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

There are two ways to get a constant and fixed sample rate:

   
        
  • have the ADC in free-running mode, and use DMA to store the results (there are DMA-Apnotes available that explain how to do this properly)
  •     
  • use a timer with a defined tick rate, and trigger and ISR from it. In this ISR you can read the ADC result, and trigger a new conversion. You also store the result and notify the main loop to send this data out over UART
  •    
   

I would prefer the first solution, since it allows faster sample rates (and this is what my example project uses)

0 Likes
Anonymous
Not applicable

I tried to use the DMA wizard, but it didn't make possible to connect to UART (as a destination). Am I doing something wrong?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You will have to set the destination manually. For the UART the destination is UART_TXDATA_PTR

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I'm uploading the project and a print that was taken about this strange output. It should be in a natural sine shape, but on certain frequency does in the same way of the picture. I'll try to manually assign the DMA, but I've never did it without DMA wizard before so there's a big chance to make it wrong.

   

Another important detail: before I took the UART all the circuit was working fine, even the VDACs! But after getting the UART almost everything on the project messed up. Why is this happening?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Daniel: Your ADC shovels 8000 values per second into your filter which generates on the other side 8000 interrupts per second. Quite a lot!

   

Additionally you request at 115200 baud the UART to transmit/receive data which is generating ~9600 interrupts per second. All this is quite too much. Consider mesuring for a short interval and buffer the values. When measured, sign correct and transmit the buffer to UART. Transmitting continuously at this frequency might not be possible.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

8000 is the minimum rate value that the interface allowed me to set on ADC. I thought that the value must be the same for the filter to make it synchronized. A agree that 115200 is pretty much for UART, but I haven't any reference for choosing it.

   

Could you give me some rate examples for my project please?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I cannot give you any advices as long as I don't know exactly what you want to perform.

   

Filtering ADC dasta (why?) sending them to UART (what for??). How many data items needed???.

   

Fact is, that you busted the limit for interrupts per second.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

My final goal is to develop a system to capture and plot EMG signals by a program written by me. To do that system I'm checking if all the steps are working. When I do not use the UART everything works how expected!

   

How can I calculate the number of interrupts?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The number of interrupts for the UART can be estimated by dividing the baud rate by 12 (8 bits data, start and stop bits).

   

Because you have set your ADC to 8k sps, you cannot use a slower baud rate or you will not be able to transmit all data.

   

Consider reducing the AD conversion rate by using a timer which hardware-triggers the conversions.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I am going to try using a simple sample conversion mode with SOC pin connected to a 2000Hz clock and a 2000Hz conversion rate to see what I get.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I made another test, but I still unsuccessful. Someone can make a suggestion?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your DMA is set up for transferring only one bye.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Where did you see that? I confess that my DMA knowledge is one of my weak points. Did you mean the "#define BYTES_PER_BURST          (1u)" ?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

    CyDmaTdSetConfiguration(DMA_1_TD[0], 1u, DMA_INVALID_TD, DMA_1__TD_TERMOUT_EN);

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Understood! I'll change that and test again!

0 Likes
Anonymous
Not applicable

I guess that the DMA transfer package it is not a problem, since I tried many values and none of them change the results.

0 Likes
Anonymous
Not applicable

After many hours spent I was able to find a critical error on my system! My python code is not working has it suppose to. I will migrate to another language or platform like LabView or Matlab to see if everything works. Sorry for taking yours time on a such dumb error. Thanks for all!

   

Ps: I was able to see that my python scprit was wrong when I tested and compared with Putty and Tera Term in place of it. They don't have any plot tools, but looking at the incoming data was enough to make the diagnosis.

0 Likes