Go Down

Topic: Arduino Due direct Port Manipulation (Read 160 times) previous topic - next topic

t0bsN

Hello Guys,

i want to reproduce the Signal in the Attachement on only 1 Pin on the Arduino Due.

Here are the Signal specifications:

-> at all the Signal consists out of 19 blocks â 16Bit
-> the first 2 Blocks are every time the same "AAAB" and "2000" the 3rd Block should be variable later
and the last 16 blocks are every time the same "0000"
-> the coding of the Signal in the attachment is, that 1 is a falling edge and 0 is a rising edge
-> between every Bit there is a pause â 1us....(so 1us is the sampling rate)..Signal = 1 Mhz



Can u help me to realize that in a Code for my arduino ?:/


I did something before, to get 4 different Signals â 16Bit on the same Pin by push a Button

Code: [Select]



#define NOP __asm__ __volatile__ ("nop\n\t");
#define PAUSE NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP
// 1 NOP Befehl entspricht 12ns (1/84MHz)
void setup() {
pinMode(5, OUTPUT);
Serial.begin(115200); 
}
void loop() {
/*
on pin 5:
  Signal 1: 1010 1010 1100 1100 
          Signal 2: 1110 1110 1010 1010
          Signal 3: 1010 0110 0110 1010
          Signal 4: 1101 1101 0011 0010
*/
if(Serial.available()>0){

byte input = Serial.read();
 
Pio *p = digitalPinToPort(7); // Port.C

uint32_t s5 = digitalPinToBitMask(5);
uint32_t c5 = digitalPinToBitMask(5);
   
switch (input){
  case '1':
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE           
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE
  p->PIO_CODR = c5; PAUSE
  break;
  case '2':
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE   
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE 
  break;

  case '3':
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  break;
  case '4':
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE
  p->PIO_SODR = s5; PAUSE p->PIO_SODR = s5; PAUSE p->PIO_CODR = c5; PAUSE
  p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE p->PIO_CODR = c5; PAUSE p->PIO_SODR = s5; PAUSE
  p->PIO_CODR = c5; PAUSE
  break;
  }
 }
}





Can I use it maybe for this Task by rewirting ?
Or maybe u have a new Solution for it :)
Would be fine !

Best regards and thank u !

MorganS

There's probably a name for this particular protocol. Once you discover the name you can see if the Due (or other suitable chip) has a hardware mode to produce this protocol.

If I was doing it and there wasn't a name for the protocol, I'l be trying to make the SPI module perform the function. There's a lot of capability in the USARTs on the Due which isn't normally used by Arduino programs.
GoForSmoke: "What GShield? You never mentioned a shield."

t0bsN

ah okay....i dont did something with SPI or UARTS before with the due..

Do u have an example code or something like that for my Problem ?

HermannSW

Quote
// 1 NOP Befehl entspricht 12ns (1/84MHz)
It is not that easy, yes, 1 NOP corresponds to 1 clock tick, but 8 nop operations take 9 Arduino Due clock cycles.

Hemann.

t0bsN

Quote
It is not that easy, yes, 1 NOP corresponds to 1 clock tick, but 8 nop operations take 9 Arduino Due clock cycles.

ah okay, thats new for me...

and how many nop operations i Need for 500ns break ?

i calculated 42, but thats wrong now :D

is it even 1 more after 8 operations ? so 16 nop = 18 clock cycles ?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy