Arduino düşük frekans elde etme

Başlatan bbs2006, 13 Kasım 2023, 14:13:43

bbs2006

Merhaba
Arduinonun pwm uclarından daha düşük frekans elde edebilirmiyiz. Bunun için nasıl ayarlamalar yapmalıyız.

power20

#1
Alıntı:

double frequency_Hz = 20.0; // adjust this to what your board needs
uint32_t wavelength_us = 1000000.0 /  frequency_Hz;
double dutycycle_pct = 35;
uint32_t ontime_us = (double) wavelength_us * dutycycle_pct / 100.0;
uint32_t cycleStart_us;
void setup() {
   cycleStart_us = micros();
   pinMode(pin, OUTPUT);
   digitalWrite(pin, HIGH);
}
void loop() {
  uint32_t us = micros() - cycleStart_us;
  while(us >=  wavelength_us) {
    // this method of adjusting the cyclestart gives more accurate cycles
    cycleStart_us += wavelength_us;
    us -= wavelength_us; 
  }
  digitalWrite(pin, us < ontime_us ? HIGH : LOW);
}

mehmet

Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr
https://creativecommons.org/licenses/by/4.0/deed.tr "CC BY"