请问各位大佬,我想用ESP32来改变某几个引脚电平,时序要求严格,需要满足微秒级延时,且脉冲宽度也为微秒级。
我现在是用的while(i){i--};通过改变i的值来实现想要的延时。但用示波器测出来的脉冲宽度不稳定,但都是差了4微秒的整数倍。
我查了一些资料,但是都没有解决。感觉是优先级的问题,被别东西打断了。
我用了portENTER_CRITICAL(mux);进入临界区,但是并没有改善。(不过,第二个参数我不大理解该怎么设置)
请问大家有知道原因的吗?
本人小白,新接触这个领域,向各位学习!
附上一段延时代码,恳请大家批评指正!
portMUX_TYPE a;
a.owner = CORE_ID_APP;
a.count = 2;
for (int i = 0; i < n; i++)
{
portENTER_CRITICAL(&a);
switch (ioio[i])
{
case 0://0
GPIO.out_w1tc = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 1://1
GPIO.out_w1tc = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 2://2
GPIO.out_w1tc = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 3://3
GPIO.out_w1tc = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 4://4
GPIO.out_w1tc = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 5://5
GPIO.out_w1tc = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 6://6
GPIO.out_w1tc = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 7://7
GPIO.out_w1tc = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 8://8
GPIO.out_w1ts = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 9://9
GPIO.out_w1ts = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 10://10
GPIO.out_w1ts = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 11://11
GPIO.out_w1ts = 0x02000000; GPIO.out_w1tc = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 12://12
GPIO.out_w1ts = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 13://13
GPIO.out_w1ts = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1tc.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
case 14://14
GPIO.out_w1ts = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1tc.data =0x00000002; break;
case 15://15
GPIO.out_w1ts = 0x02000000; GPIO.out_w1ts = 0x04000000; GPIO.out1_w1ts.data =0x00000001; GPIO.out1_w1ts.data =0x00000002; break;
default: ESP_LOGI(TAG,"error"); break;
}
portEXIT_CRITICAL(&a);
while(delay[i]){delay[i]--;}
}
//main中的任务语句
xTaskCreatePinnedToCore(&new_send_pulse, "new_send_pulse", 4096, NULL, 0, NULL, 1 );