Go Down

Topic: Arduino due digital output (Read 393 times) previous topic - next topic

husseinUKM

can arduino due generate a pulse signal with 125 khz and what is the code

sined23

very easy

  digitalWrite(pin_number, HIGH);
  digitalWrite(pin_number, LOW);

husseinUKM

thank you for your replay but it does no work i used this cod before

void setup() {
  // initialize digital pin 13 as an output.
//  Serial.begin(115200);
  pinMode(5, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
  delayMicroseconds(1);  // wait for a second
  digitalWrite(5, HIGH);    // turn the LED off by making the voltage LOW
  delayMicroseconds(1);              // wait for a second
}

sined23

#3
Apr 07, 2016, 11:57 am Last Edit: Apr 07, 2016, 12:02 pm by sined23
replace delayMicroseconds(1) into delay(1000).

delayMicroseconds(1) - this is 1 microsecond. You can't see blink )
delay(1000) - this is 1000 milliseconds = 1 second

MartinL

Hi husseinUKM,

The following code will output a 125kHz square wave with a 50% duty cycle, on pin DAC1:

Code: [Select]
// Output a 125kHz PWM waveform at a resolution of 9-bits on pin DAC1 (PWML0)
void setup() {
  // PWM Set-up on pin: DAC1
  REG_PMC_PCER1 |= PMC_PCER1_PID36;                     // Enable PWM
  REG_PIOB_ABSR |= PIO_ABSR_P16;                        // Set PWM pin perhipheral type A or B, in this case B
  REG_PIOB_PDR |= PIO_PDR_P16;                          // Set PWM pin to an output
  REG_PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(1);      // Set the PWM clock rate to 84MHz (84MHz/1)
  REG_PWM_CMR0 = PWM_CMR_CPRE_CLKA;                     // Enable single slope PWM and set the clock source as CLKA
  REG_PWM_CPRD0 = 672;                                  // Set the PWM frequency 84MHz/125kHz = 672
  REG_PWM_CDTY0 = 336;                                  // Set the PWM duty cycle 50% (672/2=336)
  REG_PWM_ENA = PWM_ENA_CHID0;                          // Enable the PWM channel    
}

void loop() {}

phr3ak

delayMicroseconds functions are not accurate you cannot use it for time critical things.

husseinUKM

thank you very much for your help MartinL

husseinUKM

can arduino due read analog signal with 125 KHz also?

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