- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I need to write a ECG signal on sd card but i can't because i can't get all samples with ADC.
This is code:
for (i = 0; i < 2000; i++)
{
if(ADC_DelSig_1_IsEndConversion(ADC_DelSig_1_WAIT_FOR_RESULT))
{
output = ADC_DelSig_1_GetResult32();
tensao_auxR = ADC_DelSig_1_CountsTo_mVolts(output);
a=a+1;
sprintf(buffer,"%4.2d\t %6.2f \n", a,tensao_auxR);
FS_Write(pFile,buffer,sizeof(buffer));
//CyDelay(0.1);
}
}
I can't find the error.
Can help me ?
Regards.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using a pointer you simply write doubles at a time, independent of what
the underlying variable is, then reconstruct on client side knowing
what is actually being sent.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is the sample rate fo the ADC ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the conversion rate (sps) is 4000.
Mode is multi-sample
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are getting a sample every 250 uS, does the SDCARD write that
fast ? Eg. 4 bytes every 250 uS, or ~ 62 uS / byte write rate. When you
say you are not getting all samples, does that mean you miss writing some
of the samples the A/D is sending but that A/D is generating them all ?
Do a quick case, flip a pin high, write 2000 test vectors, say an incrementing
numeric, to the SDCARD, when done flip pin low. Measure pin high time
with a scope or whatever, and see what the write rate you are getting from
SDCARD controller (the one inside the SDCARD) is. A quick check is SDCARD
keeping up with sample rate.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The sd card speed is 3.74mb/s .
I think is generate all of the samples..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The only other thing here that interferes in speed is the sprintf() code
execution time, maybe it is causing samples to be skipped. Try the
test to get an idea of loop execution time.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what do you mean about loop execution time?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think the problem is in ADC.
I need to get sine wave with a frequency of 400Hz.
What kind of configuration is that the ADC should have?
Thanks.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Loop execution is the time consumed each pass thru your for() loop.
If you are trying to sample a 400 Hz sine then Nyquist would have min sample
rate of 800 Hz.
What are you actually trying to measure ? RMS, Avg, Peak......or just capture the EKG ?
Regards, Dana,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If the loop execution consume time which advises to use?
I only need to capture the wave signal for the ECG signal.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.
what is alternative to loop execution? i need to capture signal for 60 seconds.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Loop quite appropriate to control sampling and subsequent SDCARD write.
But you could shorten loop by writing raw data to SDCARD instead of the sprintf
converted data, and interpret sdcard data at a later time. Main idea is just make sure
your sample rate is not being altered by sprintf() latency/execution time,
eg. missing samples on SDCARD. Flip a pin high just before sprintf() is called,
then flip low after call, and look at with scope to get an idea of time consumed.
It should be << 1 / SPS A/D.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok.
now i use fwrite to write on txt file. which you recommend to write a int values on sdcard and it is fast?
Thanks.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The write speed of the card will be the same, but the elimination of
the sprintf() execution will increase thruput.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
if i eliminate the sprintf() i can´t write on sdcard.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
any solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The SDCARD does not have any API to write byte/word data ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4.4.5 FS_FWrite()
Description
Writes data to an open file.
Prototype
U32 FS_FWrite(const void * pData,
U32 Size,
U32 N,
FS_FILE * pFile);
Return value
Number of elements written.
Parameter Description
pData Pointer to data to be written to the file.
Size Size of an element to be transferred from a data buffer to a file.
N Number of elements to be transferred to the file.
pFile Pointer to a data structure of type FS_FILE.
Table 4.25: FS_FWrite() parameter list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i check this function but the problem is same.
i have the integer values. how can i convert to void *pdata?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using a pointer you simply write doubles at a time, independent of what
the underlying variable is, then reconstruct on client side knowing
what is actually being sent.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Converting a datafield to a pointer is done by the "&" operator which takes as the result the address of the referenced data.
In your special case it would be better (faster) not to write a single item, but to collect some more and write them as a bunch. You may consider using an array of n elements and when that got filled write out all of them.
Some lit on pointers, addresses and arrays in C language here.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
... and some more: the printf() family converts data into human-readable ASCII characters. Since neither the PSoC nor the SD_card are humans there is absolutely no urgent need converting your data before writing to the SD. Only at the time when the data has to be presented to a human (or sent in an email) a conversion is required.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Based on your sample size desired you should consider a buffer for
each period of waveform, and send that out. You should be able to do
that simultaneously while acquiring the next period of samples, using
a ping pong buffer arrangement.
Problem is detecting period, possibly peak detection, or a form of zero
cross would suffice. Solution would have to accommodate some form of AGC
so period to period detection not affected by system G.
Or to avoid all this keep sending individual samples, SDCARD can support
the data rate.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One advantage to using sprintf() is exactly because they are printable chars,
debug the data stream, simple error detection (values have restricted ranges).....
Ability to frame your data with a non printable character.....
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When i use this sintaxe, i have a error ("Build error: Illegal pointer conversion")
FS_Write(pFile,ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult32()),sizeof(ADC_DelSig_1_CountsTo_mVolts(ADC_DelSig_1_GetResult32())));
how can i solve this?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, of course an error. The result of the function is data, not a datafield. When you store the result in a variable (datafield) first you can specify FS_Write(pFile,&MyADCvalue,....).
It is like a car: A car does not have got an address, the garage where you park it has an address. Read about pointers in the C-manual. They are not quite easy to understand, but when you got them, they enrich your programming technique immense!.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
but i use &MyADCvalue and didn't work...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
...and how did you define MyADCvalue and where did you store the value in?
Watch: everytime you get an error when compiling, it is you that made the error. The explanation is usually quite correct if you didn't forget some braces etc.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i told you. the MyADCvalue is a unit32 and i need to convert on void*pdata...
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So step-by step:
MyADCvalue is an uint32
then
&MyADCvalue is a pointer to an uint32
and
(void*)&MyADCvalue is a void pointer to something (what the meaning of void* is). Putting the type specifier -in this case the void*- in brackets before a variable is named a "Type Cast" which even could imply some conversions like a typecast of an integer to a float.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
any help?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can get help, but what do I have to understand under the error was "1111111111111111111111111"
You can stop with debugger and watch your vars before writing them to SD.
And consider to post your complete project and not only snippets, some relevant information gets lost. To do so, use
Creator->File->Create Workspace Bundle
and attach the resulting file.
Bob