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.
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.
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?
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)
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.
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?
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 ?
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
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?
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.
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.
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.
There are two ways to get a constant and fixed sample rate:
I would prefer the first solution, since it allows faster sample rates (and this is what my example project uses)
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?
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.
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?
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.
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?
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.
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.