Native Port

Dear all,

I have no idea why, but if I load the sketch using the Programming port, and then change the cable to the Native port things are behaving.

The same behavior for the two units I got (less than $15 each, including cable!).

Just in case someone is interested, I am getting one channel 12Bits ADC reading to the PC at 120KS/s using:

const int analogPin = A0;
int V;
byte buf2[2];
const int pwm_out_pin = 2;
//-------------------------------
void setup() {
// Setup all registers
  pmc_enable_periph_clk(ID_ADC);                                  // To use peripheral, we must enable clock distributon to it
  adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); // initialize, set maximum posibble speed
  adc_disable_interrupt(ADC, 0xFFFFFFFF);
  adc_set_resolution(ADC, ADC_12_BITS);
  adc_configure_power_save(ADC, 0, 0);                            // Disable sleep
  adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);           // Set timings - standard values
  adc_set_bias_current(ADC, 1);                                   // Bias current - maximum performance over current consumption
  adc_stop_sequencer(ADC);                                        // not using it
  adc_disable_tag(ADC);                                           // it has to do with sequencer, not using it
  adc_disable_ts(ADC);                                            // disable temperature sensor
  adc_disable_channel_differential_input(ADC, ADC_CHANNEL_7);
  adc_configure_trigger(ADC, ADC_TRIG_SW, 1);                     // triggering from software, freerunning mode
  adc_disable_all_channel(ADC);
  adc_enable_channel(ADC, ADC_CHANNEL_7);                         // just one channel enabled
  adc_start(ADC);
  
  pinMode(pwm_out_pin,OUTPUT); // sets the pin as output
  analogWrite(pwm_out_pin, 128);

  // wait for USB serial port to be connected - wait for pc program to open the serial port
  SerialUSB.begin(115200);    // Initialize Native USB port
  while(!SerialUSB);
}
//-------------------------------
void loop() {
    while((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY){}; //Wait for end of conversion
    V = adc_get_latest_value(ADC);
    buf2[0] = V & 255;
    buf2[1] = (V >> 8)  & 255;
    SerialUSB.write(buf2, 2);
}

The Python code (I use Jupyter, hence the %pylab):

%pylab
import serial

port_str='/dev/ttyACM0'
ser_arduino = serial.Serial(
   port=port_str,
   baudrate=9600,
   parity=serial.PARITY_NONE,
   stopbits=serial.STOPBITS_ONE,
   bytesize=serial.EIGHTBITS
)

buffer_size = 2048
Bit1        = zeros((2,buffer_size),dtype=int)

for i in range(0, buffer_size):
    Bit1[0,i] = int.from_bytes(ser_arduino.read(), byteorder='big', signed=False)
    Bit1[1,i] = int.from_bytes(ser_arduino.read(), byteorder='big', signed=False)
    
V1   = Bit1[0,:] + Bit1[1,:]*2**8

dt_period = mean(diff(where(abs(diff(V1))>1000)))
period = 500e-6 # Measured at the oscilloscope

dt = period/ dt_period
print('The avg time step is [us]:',dt*1e6)
print(1e-3/dt,'KS/s')

I got many things from
http://nicecircuits.com/playing-with-analog-to-digital-converter-on-arduino-due/

Pklaus claims 1MS/s, but his python code is not working in my machine and when I try to use my python code to read the data of his sketch, the data I am getting in the Python side is not correct. I have no more time to spend on this... maybe another time.

Thank anyway for your help.