fabiovix / py-ads1256

Python Library with C wrappers to read 8 channels from the Texas Instruments ADS1256 ADC chip
29 stars 18 forks source link

reading a single channel's #6

Open olivierausseil opened 7 years ago

olivierausseil commented 7 years ago

Hi, Thanks for your work.

I have a question because i can't explain why.

I use your exemple and add just a loop while when i reading the value.

import ads1256                                   # import this lib
ads1256.start(str(1),"25")                       # initialize the ADC using 25 SPS with GAIN of 1x
i = True
while i :
  ChannelValue = ads1256.read_channel(7)           # read the value from ADC channel 0
  print str(ChannelValue * 0.000596) + " mV"                 # print the value from the variable (mV)
ads1256.stop()

It works but i have the same value 8 times :

19.049352 mV 19.049352 mV 19.049352 mV 19.049352 mV 19.049352 mV 19.049352 mV 19.049352 mV 19.049352 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.044584 mV 19.075576 mV 19.075576 mV 19.075576 mV 19.075576 mV 19.075576 mV 19.075576 mV 19.075576 mV 19.075576 mV 18.998096 mV 18.998096 mV 18.998096 mV 18.998096 mV 18.998096 mV 18.998096 mV 18.998096 mV 18.998096 mV

Maybe is not possible or i do something wrong. I want do a measurement in volt for after calculate a current. I would like to measure every X ms but suddenly I can not.

Thanks in advance Olivier

Jedi91E commented 6 years ago

Hi, i'm starting with this board and i have the same problem: same values for 7/8 times. Do you fix the problem? If you write your code like this: i = True while i : ads1256.start(str(1),"25") # initialize the ADC using 25 SPS with GAIN of 1x ChannelValue = ads1256.read_channel(7) # read the value from ADC channel 0 print str(ChannelValue * 0.000596) + " mV" # print the value from the variable (mV) ads1256.stop() the code should work but the acquisition is much more slow, so you can use it for low frequency signal. In my case i need to measure a 50Hz signal so it's fine, but it's not elegant or efficient.

fabienroots commented 6 years ago

Hi, In signle channel, i have the same issue :'((

Someone find a solution, plz ?

olivierausseil commented 6 years ago

Hi, Yes my program work now. I do a read data continuous (see in the datasheet) and he works for me. I show a piece of code where launch my feature , read data continuous.


void hal_CS (uint8_t valueCS)
{
if (valueCS == 0)
  {
    bcm2835_gpio_write(SPICS,LOW);
  }
  else
  {
    bcm2835_gpio_write(SPICS,HIGH);
  }
}

void hal_send8bit (uint8_t valueToSend)
{
  //printf ("0x%02X\n", valueToSend);
  hal_wait_us(1);
  bcm2835_spi_transfer(valueToSend);
}

uint8_t hal_receive8bit ()
{
  uint8_t receiveValue;
  receiveValue = bcm2835_spi_transfer(0xff);
  //printf ("0x%02X\n", receiveValue);
  return receiveValue;
}

void hal_data_ready()
{
  while (!bcm2835_gpio_lev(DRDY)==0); // a voir?
}

void ADS1256_read_data_continuous (uint32_t sample)
{
uint32_t sample_counter;
uint8_t buf_read[3];
uint32_t valueData;
for (sample_counter = 0 ; sample_counter<sample ; sample_counter++)
  {
    hal_data_ready();
    hal_CS(0);
    buf_read[0] = hal_receive8bit();
    buf_read[1] = hal_receive8bit();
    buf_read[2] = hal_receive8bit();
    hal_CS(1);
    valueData = (buf_read[0] << 16) + (buf_read[1] << 8) + buf_read[2];
    printf("raw value channel = 0x%02X%02X%02X, %08ld\n", (int)buf_read[0],(int)buf_read[1], (int)buf_read[2], (long)valueData);
  }
fabienroots commented 6 years ago

1961513 1961513 1961513 1961513 1961513 1961513 1961513 1961513 1961480 1961480 1961480 1961480 1961480 1961480 1961480 1961480

Same thing in single channel. Thanks for your Answer Olivier. I'm a really newbi in C language, no issue in Python ?

olivierausseil commented 6 years ago

No sorry, only C language, I took a lot of inspiration from your code for write this. Only difference i think is that we read in continuous. When my program worked, i didn't do more research about the cause of this bug. I don't know if my github account is visible by all users but, if that is the case, go to "bench-consumption" for complete code.

SchofieChen commented 5 years ago

guys, I found a solution, I tried to figure out this problem which has 8 times the same value, void ADS1256_ISR(void) { if (g_tADS1256.ScanMode == 0) / 0 Single-ended input 8 channel, 1 Differential input 4 channe / {

    ADS1256_SetChannal(g_tADS1256.Channel); /*Switch channel mode */
    bsp_DelayUS(5);

    ADS1256_WriteCmd(CMD_SYNC);
    bsp_DelayUS(5);

    ADS1256_WriteCmd(CMD_WAKEUP);
    bsp_DelayUS(25);

    if (g_tADS1256.Channel == 0)
    {
        g_tADS1256.AdcNow[7] = ADS1256_ReadData();  
    }
    else
    {
        g_tADS1256.AdcNow[g_tADS1256.Channel-1] = ADS1256_ReadData();   
    }

    if (++g_tADS1256.Channel >= 8)
    {
        g_tADS1256.Channel = 0;
    }

the problem at the code of end if (++g_tADS1256.Channel >= 8) { g_tADS1256.Channel = 0; } it do cycle read channel, that is sock official code.. delete it, will figure out the problem

ghost commented 4 years ago

Thank you very much for sharing your great codes!!

I commented out the four lines, starting from “if (++g_tADS1256.Channel >= 8) to “}”, but then the device gives only the values of zero. Without comment out, I could read the proper values even though 8 values are same as discussed above.

Does someone solve this issue?