ECG 2 Click, a truly working code?

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
columbus
Posts: 6
Joined: 04 Sep 2022 18:05

ECG 2 Click, a truly working code?

#1 Post by columbus » 04 Sep 2022 18:33

Hi,

I just purchased the ECG 2 Click a few weeks ago and started to work on this a few days ago. There are a couples of things that I cannot get information on to get a better understanding of how it works. The sample code for this ECG 2 click are different from one place to another (within mikroe sites). I hope to get some clarification from this forum.
First, there are 4 channels on the ECG 2 providing four different set of raw data. Yet, I saw some sample uses channel 5 to show the data like this one (https://github.com/MikroElektronika/mik ... ple/main.c):

ecg2_read_channel_data( &ecg2, 5, &ecg_an ), which contains:
...
err_t error_flag = ecg2_read_data( ctx, rx_data, 20 );

adc_val = rx_data[ channel + 2 ];
adc_val <<= 8;
adc_val |= rx_data[ channel + 3 ];
...

In this code, I feel like something is not right on the part that reads the rx_data[]. It looks like it is overlaping the last byte of one channel to the first byte of the next channel. For example, channel 1 yields rx_data[3] << 8 | rx_data[4] and channel 2 yields rx_data[4] << 8 | rx_data[5].

Question: What is the data in side the 20 bytes rx_data?

In another example, which is posted on the ECG 2 click product, https://www.mikroe.com/ecg-2-click, which seems to do some calculation before passing on to the mikroPlot:

channel2_voltage = calculate_ecg_channel( ecg_data_sample, 5, Vref, channel_gain, channel2_voltage_offset);

In this example, it picks channel 2 as the returning data.

Question: what does calculate_ecg_channel actually do? I can't find any information about this function.

Semifinal question: There are 4 channels containing 4 different sets of data but there are only three probes (RA, LA, LL), which channel correspond to which probe?

Final question: Again there are 4 channels, why some sample code decided to use channel 2 and not the others?

Thanks

Columbus.

columbus
Posts: 6
Joined: 04 Sep 2022 18:05

Re: ECG 2 Click, a truly working code?

#2 Post by columbus » 06 Sep 2022 22:38

This function is found in the mikroC project:

void applicationTask( )
{
intPinStatus = checkIntPin( );

if (intPinStatus == 0)
{
ecg2_captureData( &capturedData[0] );
plotData( capturedData[2] );
}
}

I can't find any information about ecg2_captureData().

columbus
Posts: 6
Joined: 04 Sep 2022 18:05

Re: ECG 2 Click, a truly working code?

#3 Post by columbus » 10 Sep 2022 15:39

Any help from MikroE is appreciated.

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: ECG 2 Click, a truly working code?

#4 Post by IvanJeremic » 14 Sep 2022 11:06

Hi,

First of all the reason why there are so many different codes because we changed our SDK throughout the years so the code changed with it, that is why you can find so many different ones.

ecg2_read_channel_data( &ecg2, 5, &ecg_an )- While looking at this function it would seem that it wont read from channel 5 but actually from channel 3, the code will be reviewed at some point and this will probably change since it is kinda silly to have it say 5 when it is reading from channel 3...

About the overlapping part, there shouldn't be any overlaps one ends before rx_dat[4] while the other begins at rx_dat[4], you can learn more in the datasheet (https://www.ti.com/lit/ds/symlink/ads1194.pdf)

"What is the data in side the 20 bytes rx_data?" Look up the datasheet i posted above.

As for the calculate_ecg_channel and ecg2_captureData() unfortunately there are no source files for these so i do not know what they actually do, for the calculate_ecg_channel i think it should turn the ADC data into voltage.

"There are 4 channels containing 4 different sets of data but there are only three probes (RA, LA, LL), which channel correspond to which probe?"- The answer is in the schematic in the link below:
https://download.mikroe.com/documents/a ... c-v100.pdf

And for the final question you can change from what channel you want to read the data some chose channel 2 and the one that said it reads from channel 5 reads from channel 3.

Regards,

Ivan.

columbus
Posts: 6
Joined: 04 Sep 2022 18:05

Re: ECG 2 Click, a truly working code?

#5 Post by columbus » 18 Sep 2022 15:58

Ivan,
Thanks for your respond. I did went through the specs and schematic but still not able to clear my questions.
ecg2_read_channel_data( &ecg2, 5, &ecg_an )- While looking at this function it would seem that it wont read from channel 5 but actually from channel 3, the code will be reviewed at some point and this will probably change since it is kinda silly to have it say 5 when it is reading from channel 3...

About the overlapping part, there shouldn't be any overlaps one ends before rx_dat[4] while the other begins at rx_dat[4], you can learn more in the datasheet (https://www.ti.com/lit/ds/symlink/ads1194.pdf)

"What is the data in side the 20 bytes rx_data?" Look up the datasheet i posted above.
Code reference:
err_t ecg2_read_channel_data ( ecg2_t *ctx, uint8_t channel, uint16_t *data_out ) {
uint8_t rx_data[ 20 ];
uint16_t adc_val;

spi_master_select_device( ctx->chip_select );

err_t error_flag = ecg2_read_data( ctx, rx_data, 20 );

adc_val = rx_data[ channel + 2 ];
adc_val <<= 8;
adc_val |= rx_data[ channel + 3 ];

*data_out = adc_val;
return error_flag;
}
According to the ADS1194 specs, the data coming out of DOUT line has 3-status byte followed by 2 bytes for each channel (1-4), which total to be 11 bytes for 1194, 15 bytes for 1196, and 19 bytes for 1198.
there are three logical outputs from ecg2_read_data with one/zero byte padding:
<Status:0-2><Channel1:3-4><Channel2:5-6><Channel3:7-8><Channel4:9=10>
<Pad:0><Status:1-3><Channel1:4-5><Channel2:6-7><Channel3:8-9><Channel4:10=11>
<Status:1-3><Pad:3><Channel1:4-5><Channel2:6-7><Channel3:8-9><Channel4:10=11>
Based on the code above:
Channel 1 will take indexes: 1+2, 1+3 (3,4)
Channel 2 will take indexes: 2+2, 2+3 (4,5)
...
So they are actually overlapping. Channel 2 takes the last byte of channel 1.
As for the calculate_ecg_channel and ecg2_captureData() unfortunately there are no source files for these so i do not know what they actually do, for the calculate_ecg_channel i think it should turn the ADC data into voltage.
I think it's best that Mikroe make the source code for ecg2_captureData() available so the other can contribute to their development. I assume the reason for these sample code is to sell the hardware.
"There are 4 channels containing 4 different sets of data but there are only three probes (RA, LA, LL), which channel correspond to which probe?"- The answer is in the schematic in the link below:
https://download.mikroe.com/documents/a ... c-v100.pdf

And for the final question you can change from what channel you want to read the data some chose channel 2 and the one that said it reads from channel 5 reads from channel 3.
I can only extract the fact that each of the RA, LA, LL feeds two input pins.
LA - IN1 positive, IN3 Negative
RA - IN1 Negative, IN2 Negative
LL - IN2 Positive, IN3 Positive
All inputs are fed into PGA then go through ADC. There is no way that I can tell which input(s) go to which channel without looking at the PGA code. Would you mind elaborate on your previous answer?

Also, three inputs (LA, RA, LL) in medical perspective can provide three distinct signals (RA-LA, RA-LL, LA-LL)

Thanks,
columbus

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: ECG 2 Click, a truly working code?

#6 Post by IvanJeremic » 28 Sep 2022 10:01

Hi,

Sorry for the late reply.

As i said the the channel numbers in the code are weird and we will change this at some point.
The input for the channel in ecg2_read_channel_data should be (channel_id*2-1), so if the value is 1 the corresponding channel should be 1, if the value is 3 the corresponding channel should be 2, if the value is 5 the corresponding channel should be 3 etc...

Also did you try using the click board? Does it work properly for you?

Regards,

Ivan.

columbus
Posts: 6
Joined: 04 Sep 2022 18:05

Re: ECG 2 Click, a truly working code?

#7 Post by columbus » 13 Oct 2022 02:39

I have decided to move on and evaluate other products. MikroE already built 6 click and the 2-click doesn't seem to be in a stable state. The output and availability of the code isn't satisfactory for me to continue investing my time in it.

Thanks
Columbus

Post Reply

Return to “User Projects”