Problem with the adc using lib_startkit_support (v 2.0.0)

Technical questions regarding the XTC tools and programming with XMOS.
IgorLopez
Member++
Posts: 25
Joined: Tue Mar 11, 2014 8:16 pm

Problem with the adc using lib_startkit_support (v 2.0.0)

Post by IgorLopez »

Hello,

I have a problem incorporating the adc into my application.
When I run the AN00177_startKIT_adc_demo everything works as expected but not when I add it to my app.
Since the app is using i2c (I have made my own i2c_slave since the lib does not work yet) and it is a rather big app so I will focus on what works and when it not works.

This is how it is layed out on the cores:

Code: Select all

int main()
{
  interface i2c_slave_callback_if i_i2c;
  interface i2c_handler_if i_i2cHandler;
  interface adc_handler_if i_adcHandler;
  startkit_adc_if i_adc;
  chan c_adc;
  par {
    on tile[0].core[1]: i2c_slave(i_i2c, p_scl, p_sda, SLAVE_ADDRESS, CLOCK_STRETCHING);
    on tile[0].core[2]: i2c_handler(i_i2c, i_i2cHandler); //, p_dbg);
    on tile[0].core[3]: handler_demon(i_i2cHandler, i_adcHandler); //, p_dbg);
    on tile[0].core[4]: handler_adc(i_adcHandler, i_adc);
    on tile[0].core[0]: adc_task(i_adc, c_adc, 0);
    startkit_adc(c_adc);
  }
  return 0;
}
The part where it struggles is in handler_adc and I have commented the problems in the code:

Code: Select all

#define LOOP_PERIOD              10000 // meassure adc val each 100 us

[[combinable]]
void handler_adc(client adc_handler_if sH, client startkit_adc_if i_adc)
{
  timer t_loop;
  uint32_t loop_time;
  uint16_t adc_val[4] = {0, 0, 0, 0};
  uint16_t counter = 0;

  t_loop :> loop_time;
  loop_time += LOOP_PERIOD;

  while(1) {
    select {
    case t_loop when timerafter(loop_time) :> void:
      //i_adc.trigger(); // When uncommented will bus.read_word_data(ADDR, 28) always return 0 sH.getADC(counter);
      counter++;
      sH.getADC(counter); // Inform handler about new value
      // Add read of adc here
      // i_adc.read(adc_val);  // Get the values (and clear the notfication). 
                               // If uncommented will bus.read_word_data(ADDR, 28) always return 1
      loop_time += LOOP_PERIOD;
      break;
      // ########################################################################
      // Read ADC upon completion (ADC is triggered every 100us)
      case i_adc.complete():      //Notification from ADC server when aquisition complete
//        i_adc.read(adc_val);      //Get the values (and clear the notfication)
//        sH.getADC(adc_val[0]);
//        sH.getADC(counter);
        break;
    }
  }
}
As the function is posted will the raspberry report the incrementing counter value as expected but as soon I involve any of the i_adc interface functions does it stop working.
Note, bus.read_word_data(ADDR, 28) is the python command executed on my raspberry to read that counter value or rather the adc value once I get it to work.


User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

If you take out communication to the Pi and print out what's returned from the ADC, do you get valid readings?
IgorLopez
Member++
Posts: 25
Joined: Tue Mar 11, 2014 8:16 pm

Post by IgorLopez »

Yes, printing to console instead of sending over I2C to raspberry gives correct values.

It seems there is a conflict or lock up that happens when using the two libs together but I have no idea on how to debug such a problem.

Since I am still very much a newbie with the xcore architecture I hope it is just a matter of a misconfiguration.