DeqingSun / ch55xduino

An Arduino-like programming API for the CH55X
GNU Lesser General Public License v2.1
448 stars 86 forks source link

Add 6MHz clock support #139

Open Saatvik-Aggarwal opened 1 year ago

Saatvik-Aggarwal commented 1 year ago

I've added support for 6MHz clock. I've tested it for accuracy with my CH552G.

Here is a loop function you can use to test:

void loop() {
  delay(1000);
  USBSerial_println(millis());

  delay(2000);
  USBSerial_println(millis());

  delay(4000);
  USBSerial_println(millis());

  delay(8000);
  USBSerial_println(millis());

  delay(16000);
  USBSerial_println(millis());
}
DeqingSun commented 1 year ago

Please do not include the formatting code into the PR or I can not see where you changed. At this moment you changed every line of the code.

Also please only cherry pick the necessary commits.

I know there are format issue in this repo and I'll get them fixed these days. You can do your part afterward.

Saatvik-Aggarwal commented 1 year ago

@DeqingSun I've undone the formatting changes. Let me know what you think. I had to add a "hacky" part for the delay() function, I'm not sure why the approach that all the other frequencies used does not work. Nevertheless, the code is working and I am now running my CH552G at 6Mhz, saving a few milliamps of current.

DeqingSun commented 1 year ago

Thanks, this looks nice. But a clock change will require intensive testing with logic analyzer. I will test the timing then I will merge it.