I can not generate pulses of higher frequency than 500 Khz

emilts
Posts: 1
Joined: Tue Mar 19, 2019 12:39 pm

I can not generate pulses of higher frequency than 500 Khz

Postby emilts » Tue Mar 19, 2019 12:50 pm

Hi.
I am using Timer, to turn on and off a led (infrered) with "digitalWrtie", but I do not get pulses under 2 microseconds.
I need to generate pulses at a frequency of 6Mhz and 13.3Mhz, please can you help me.

An example of mythe code is:



const int ledPin = 13;
volatile uint8_t ledOn = 1;

hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

//===================================================================================

extern void IRAM_ATTR __digitalWrite(uint8_t pin, uint8_t val){
if(val) {
if(pin < 32) {
GPIO.out_w1ts = ((uint32_t)1 << pin);
} else if(pin < 34) {
GPIO.out1_w1ts.val = ((uint32_t)1 << (pin - 32));
}
} else {
if(pin < 32) {
GPIO.out_w1tc = ((uint32_t)1 << pin);
} else if(pin < 34) {
GPIO.out1_w1tc.val = ((uint32_t)1 << (pin - 32));
}
}
}

//===================================================================================

void IRAM_ATTR onTimer(){
portENTER_CRITICAL_ISR(&timerMux);

__digitalWrite (ledPin, ledOn ^= 1 ? 1 : 0);

portEXIT_CRITICAL_ISR(&timerMux);
}

//===================================================================================

void setup() {

pinMode(ledPin, OUTPUT);

timer = timerBegin(0, 6, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 1, true);
timerAlarmEnable(timer);
}

//===================================================================================

void loop() {
vTaskDelay(portMAX_DELAY);
}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: I can not generate pulses of higher frequency than 500 Khz

Postby WiFive » Tue Mar 19, 2019 2:00 pm


Who is online

Users browsing this forum: Google [Bot] and 230 guests