Skip to content

Fix analogWrite() #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2025
Merged

Fix analogWrite() #46

merged 3 commits into from
Jan 24, 2025

Conversation

facchinm
Copy link
Member

Implement DAC and fix the dtoverlay for Giga

Fixes #38 and #19

@facchinm
Copy link
Member Author

@KurtE can you try giving it a spin?
I also noticed in your last PRs that you are still targeting the old zephyr branch. To update, just run west update once in the venv

@KurtE
Copy link

KurtE commented Jan 23, 2025

Will try it out.

Running the west update now.

For some reason I assumed that using the bootstrap.sh would update everything...

@KurtE
Copy link

KurtE commented Jan 23, 2025

I verified that at least most of the PWM pins work, a few I did not test as they were hooked up to my lcd display..., but tried,
2, 3, 4,5, 7

I also tried the DAC and my simple sketch worked:

enum dacPins dp = DAC0;
#define toggle_pin 31
void setup() {
    // put your setup code here, to run once:
    Serial.begin(115200);
    //while (!Serial) {}
    delay(500);

    Serial.println("Start of PWM test");
    pinMode(toggle_pin, OUTPUT);
    delay(1000);
}

void maybe_pause() {
    if (Serial.available()) {
        while (Serial.read() != -1) {}
        Serial.println("Paused");
        while (Serial.read() == -1) {}
        while (Serial.read() != -1) {}

        dp = (dp == DAC0)? DAC1 : DAC0;
    }
}

void loop() {
    // put your main code here, to run repeatedly:
    digitalWrite(toggle_pin, !digitalRead(toggle_pin));
    digitalWrite(toggle_pin, !digitalRead(toggle_pin));
    for (int i = 0; i < 256; i += 32) {
        analogWrite(dp, i);
        digitalWrite(toggle_pin, !digitalRead(toggle_pin));
        maybe_pause();
        delay(100);
    }

    digitalWrite(toggle_pin, !digitalRead(toggle_pin));
    digitalWrite(toggle_pin, !digitalRead(toggle_pin));
    for (int i = 255; i >= 0; i -= 32) {
        analogWrite(dp, i);
        digitalWrite(toggle_pin, !digitalRead(toggle_pin));
        maybe_pause();
        delay(100);
    }
    delay(50);
}
![image](https://github.com/user-attachments/assets/d7ed5c01-803d-4a29-86d9-6b588838325c)

@KurtE
Copy link

KurtE commented Jan 23, 2025

Side note:

I wish that some of these apis did not have two forms of their API.
In this case, having two APIs for analogWrite(pin, value);
does not really impact me, as my usages for DAC versus digital PWM is different.

However for analogRead where the A0-A7 is done by one API with one data type and A8-A11 are done by another API with
different type for selecting pin, feels wrong, as I am using them for the same thing. And for example if I have libraries who take parameters for which Analog pin to use, they won't probably work on the two different types...

But that is probably just me. Glad more things are working!

@facchinm
Copy link
Member Author

The big problem about A8-A11 on the Giga is that the pins can't be used as digital, so either we pollute the whole core for a single use case (which feels very wrong) or we implement something as we did (which indeed creates problems when wrapping the function call, but keeps the core clean)

@facchinm facchinm merged commit 3a06894 into arduino:arduino Jan 24, 2025
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GIGA: analogWrite to DAC pins (A12, A13) does not appear to be implemented.
2 participants