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);
}
I can not generate pulses of higher frequency than 500 Khz
Who is online
Users browsing this forum: Baidu [Spider] and 80 guests