Go Down

Topic: Reading two digital Pins at the same time (Read 147 times) previous topic - next topic


Hi, I'm new to this!

I'm working in a counter. I have a detector that will give me a signal when something have pass through it, so I must make coincidence between two detectors. Both signals will be 0.0005 microseconds apart, so I can say that the arduino will get them at the same time.

My goal is to read, for now, 2 pins (in a future I'll want 4, max). I have found PIO registrers are usefull for my case. I read the datasheet, and many posts, but many of them focus in the writing and output function, instead of Input.

I made a simple sketch to see what PIO_PDSR gives, in the monitor it prints 2147483646 (i dont know what it means). And nothing was connected to the arduino (just a test, I thought that the monitor would print a binary or something like that)

Code: [Select]

void setup() {

void loop() {
  unsigned long int stat = PIOC->PIO_PDSR;

So I need help with what should I expect from PIO_PDSR, with the code, or with more information like posts and/or guides.

I've read this posts:

Also I'm kinda new with the arduino language (c/c++), but i know stuff so dont worry about the programming level.

Thanks in advance!


From Sam3x datasheet page 624:

31.5.8 Inputs

The level on each I/O line can be read through PIO_PDSR (Pin Data Status Register). This register indicates the level of the I/O lines regardless of their configuration, whether uniquely as an input or driven by the PIO controller or driven by a peripheral.

Reading the I/O line levels requires the clock of the PIO controller to be enabled, otherwise PIO_PDSR reads the levels present on the I/O line at the time the clock was disabled.

Connect pull down resistors to Pin 44=PC19 and PIn 46=PC17, and try this code :

Code: [Select]

void setup() {
    Pin 44 = PC19
    Pin 46 = PC17
  PMC->PMC_PCER0 = PMC_PCER0_PID13;   // PIOC power ON

void loop() {
  uint32_t status = PIOC->PIO_PDSR;
  boolean statusPin44 = status & (1 << 19);
  boolean statusPin46 = status & (1 << 17);
  Serial.print("status Pin44 = "); Serial.println(statusPin44);
  Serial.print("status Pin46 = "); Serial.println(statusPin46);


Thanks! that worked. I thought that the clock of the PIO was always enabled, and with your answer you cleared my mind about PIO_PDSR; it keeps all the values as a binary and doing that logic operation you get the value of a specific pin.

Again, thank you so much!

Go Up