Skip to content
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

analog write does not work on various pins #5

Open
pelikhan opened this issue Feb 13, 2018 · 4 comments
Open

analog write does not work on various pins #5

pelikhan opened this issue Feb 13, 2018 · 4 comments
Assignees
Labels

Comments

@pelikhan
Copy link
Contributor

pelikhan commented Feb 13, 2018

This is a follow up of microsoft/pxt-adafruit#604
Test sample:

#include "CircuitPlayground.h"
CircuitPlayground cplay;
int main()
{
    while(1)
    {
        cplay.io.a4.setAnalogValue(0);
        cplay.sleep(200);
        cplay.io.a4.setAnalogValue(512);
        cplay.sleep(200);
    }
}

Result:

  • A1, A2, A3: ok
  • A0, A4, ... : freeze
@jamesadevine
Copy link
Contributor

So I tracked this back to mbed.

It seems like the pin map for the peripheral is incomplete, so when you try and use these pins for PWM, mbed throws an error, not a hard fault, halting the user app.

From what I can make out on the datasheet, the following is the summary for user facing pins:

  • A0 (PA02) - DAC only, no PWM.
  • A1 (PA05) - PWM capable, and mapped correctly in mbed.
  • A2 (PA06) - PWM capable, and mapped correctly in mbed.
  • A3 (PA07) - PWM capable, and mapped correctly in mbed.
  • A4 (PB03) - PWM capable, and not mapped in mbed currently.
  • A5 (PB02) - PWM capable, and not mapped in mbed currently.
  • A6 (PB09) - PWM capable, and not mapped in mbed currently.
  • A7 (PB08) - PWM capable, and not mapped in mbed currently.

Actions for this is are as follows:

  • Disallow analog out on A0.
  • Add correct mappings for A4 - A7

@jamesadevine
Copy link
Contributor

Okay, further to my previous comment, it seems like the pins that aren't mapped in mbed use TC clocks, rather than TCC clocks (See section 7.1 of the datasheet). This means that the code for PWMOut WILL NOT work on the above pins, as the implementation assumes TCC.

It may be time to drop mbed for CPlay IO.

@jamesadevine
Copy link
Contributor

@pelikhan I don't have the cycles to write the replacement driver at the moment. In the meantime, it might be best to disable analog out operations on those pins.

@jamesadevine
Copy link
Contributor

Some clarification to my original comment after reading the datasheet again...

  • A0 (PA02) - DAC only, can be added.
  • A1 (PA05) - PWM capable, and mapped correctly in mbed.
  • A2 (PA06) - PWM capable, and mapped correctly in mbed.
  • A3 (PA07) - PWM capable, and mapped correctly in mbed.
    - A4 (PB03) - PWM capable, cannot be mapped due to absence of TC6.
    - A5 (PB02) - PWM capable, cannot be mapped due to absence of TC6.
  • A6 (PB09) - PWM capable, and not mapped in mbed currently.
  • A7 (PB08) - PWM capable, and not mapped in mbed currently.

So, this means that we would have a net gain of 3 "analogue out" pins, rather than the 5 I originally stated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants