CH559 GPIO最高切换频率

有两个问题:

1. GPIO最高支持的切换频率是多少?

目前测试看直接通过汇编的SETB和CLR调整GPIO脚(已配置成输出)的电平,MCU工作在56MHz,从示波器观察输出大约是14MHz,从理论上讲,SETB和CLR都是单指令周期,那么输出频率应该在56/2=28MHz.


2. UART0中断使能会影响GPIO切换频率

相同的代码,一旦打开UART0的中断使能(ES = 1),GPIO的切换速率就会降低到330KHz左右。


void main() 

{

  CfgFsys();                    // Init system clk

  mDelaymS(5);                  // Wait the clk to be steady


  CH559UART0Alter();            // Switch UART0 pin to 37/38

  mInitSTDIO();                         // Init UART0 for stdio

  //ES = 1;                               // Enalbe UART0 interrupt,一旦打开UART0中断就会导致GPIO切换速度极度降低

  IE_UART1 = 1;

  EA = 1;                               // Enalbe interrupt for all


  CH559GPIOModeSelt(1, 6, 6); // 配置pin1输出

  while(1) pwm_pin1(255);        // pwm_pin1中通过CLR/SETB切换管脚pin1电平

}


以上均是使用CH559EVT中的示例中的函数。目前验证看,UART0中断使能会影响所有端口的切换速度,而不只是UART0映射到的端口0;UART1中断使能没有此问题。

麻烦尽快确认,是否为软件配置问题,谢谢。

SETB and CLR are 2 Byte Instructions, therefore 2 cycles. Your observation of 14MHz matchs. 

With CPL you might reach 28MHz.

You dont show any interrupt handler for Uart0. I guess the irq fires again and again, possibly because TI does not get cleared. Therefore just one instruction gets executed between irqs. 


Hi usbman,


Many thanks to you.

I have checked the instruction datasheet named CH55X汇编指令.PDF,  and you are right, that both SETB bit and CLR bit  would take two cycles, so the first question is cleared.

And again, you are right that TI flag needs to be cleared as well. Forgive my carelessness and put up such a junior issue to bother people.


BTW, it seems that you are not from China, but you are so familar with WCH series of MCUs. My hat off to you. 


 这两个确实是双周期指令。


SETB c 和 CLR c指令是单周期的,但是针对bit是双周期的


@sunshine


You are right, I am from Germany though I had lived in China for some time.

Some WCH chips are available here too. Unfortunately the more interesting chips are out of stock even at LCSC these days. for exampe CH549 or the CH555.


ummm,我的意思就是SETB和CLR单个位就是双周期的,正如你所说的,汇编指令的PDF里写了。

and for @usbman,German friend,ask WCH for a few CH549 or CH555 less than 5chips may be a better choose,specially if you want to design something interesting with these.微信截图_20211026215431.png


@home_everywhere 什么时候WCH这么大方了,德国的仁兄还是多尝试下阿里巴巴海外版吧。

@usbman, maybe you can try Alibaba/Taobao to see if some vendors would like to ship these kinds of chips to Germany.


只有登录才能回复,可以选择微信账号登录