energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
798 stars 670 forks source link

Analog/timer pin definiton incorrect, only one analog output available #41

Closed pbrier closed 12 years ago

pbrier commented 12 years ago

The analog pin/timer definition is incorrect in pins_energia.h. Timer1 outputs are not available.

Note: due to the fact that compare register 0 is used as the PWM period, only two analog outputs are available per timer. And OUT0.2 is not available as a pin, a maximum of 3 independent outputs are available on the 20PIN devices.

Proposed definition:

// Defines for devices with 2x TA3 timers (e.g. MSP430g2553). On the 20pin devices, upto 3 analog outputs are available
// T0A1, T1A1 and T1A2
const uint8_t digital_pin_to_timer[] = {
    NOT_ON_TIMER, /*  dummy */
    NOT_ON_TIMER, /*  1 - VCC */
    NOT_ON_TIMER, /*  2 - P1.0 */
    T0A0,         /*  3 - P1.1, note: A0 output cannot be used with analogWrite */
    T0A1,         /*  4 - P1.2 */
    NOT_ON_TIMER, /*  5 - P1.3 */
    NOT_ON_TIMER, /*  6 - P1.4, TODO: T0A2??, not on DIP20 devices according tot datasheet  */
    T0A0,         /*  7 - P1.5, note: A0 output cannot be used with analogWrite  */
    T1A0,         /*  8 - P2.0, note: A0 output cannot be used with analogWrite */
    T1A1,         /*  9 - P2.1 */
    T1A1,         /* 10 - P2.3 */
    T1A0,         /* 11 - P2.4 note: A0 output cannot be used with analogWrite  */
    T1A2,         /* 12 - P2.5 */
    T1A2,         /* 13 - P2.6 */
    T0A1,         /* 14 - P1.6 */
    NOT_ON_TIMER /* 15 - P1.7 */
//  NOT_ON_TIMER,       /* 16 - /RESET */  
// NOT_ON_TIMER,        /* 17 - TEST */  
// T1A2,                /* 18 - XOUT - P2.7 */
// NOT_ON_TIMER,        /* 18 - XIN - P2.6 */
// NOT_ON_TIMER,        /* 20 - GND */
};
robertinant commented 12 years ago

Good catch! I indeed forgot to add the TA1 to the pins_energia.h when I updated the wiring_analog.c to include TA1. Obviously the code is not tested because of missing pin defs in the .h file which makes this a rather sloppy check in :-(.

TA0.2 indeed does not show on the 20 pin flavors. In fact, it does not show on any of the pin outs yet it seems that TA0.2 is on P1.4 on some devices. TA0.2 seems to only be there if the device features a Comparator. E.g. The diagram "Port P1 Pin Schematic: P1.4, Input/Output With Schmitt Trigger" in the g2553 data sheet shows TA0.2 on P1.4. On the contrary, the same diagram in the data sheet for MSP430G2x33 and MSP430G2x03 do not show TA0.2 on P1.4 due to the lack of the comparator. Let me confirm with the msp430 team in TI. I vaguely remember that I did test analogWrite on P1.4 and verified with a scope. If P1.4 indeed lacks TA0.2 then I agree with your pin def. I am OK with you checking in the T1Ax changes but leave the following in there for now.

//TODO:only g-series with comp have TA0.2 on P1.4??
#if defined(__MSP430_HAS_CAPLUS__)
        T0A2,         /*  6 - P1.4 */
#else
        NOT_ON_TIMER, /*  6 - P1.4 */
#endif
robertinant commented 12 years ago

Confirmed that the data sheet is incorrect. e.g. MSP430G2553 does not have TA0.2 on P1.4. Some devices do have TA0.2 on P1.4. It is unclear how to figure out which ones do and which ones don't so am leaving P1.4 as NOT_A_TIMER for now. Commit: 1a311af

freemansoft commented 12 years ago

Are we sure the pin numbering is right for port 2? The TI doc says p2.0 = pin 8 p2.1 = pin 9 p2.2 = pin 10 p2.3 = pin 11 p2.4 = pin 12 p2.5 = pin 13 p2.6 = pin 19 xtal p2.7 = pin 18 xtal

robertinant commented 12 years ago

There is a minor error in the file https://raw.github.com/energia/Energia/master/hardware/msp430/variants/launchpad/pins_energia.h naming pin 18 twice. Is this what you are referring to?

freemansoft commented 12 years ago

I was referring pins 10,11,12 and 13 which do not appear to agree with the launchpad silk screen or the TI data sheet. P2.2 should be on pin 10...

T1A0,         /*  8 - P2.0 note: A0 output cannot be used with analogWrite */
T1A1,         /*  9 - P2.1 */
T1A1,         /* 10 - P2.3 */
T1A0,         /* 11 - P2.4 note: A0 output cannot be used with analogWrite  */
T1A2,         /* 12 - P2.5 */
T1A2,         /* 13 - P2.6 */

else

NOT_ON_TIMER, /\*  8 - P2.0 _/
NOT_ON_TIMER, /_  9 - P2.1 _/
NOT_ON_TIMER, /_ 10 - P2.3 _/
NOT_ON_TIMER, /_ 11 - P2.4 _/
NOT_ON_TIMER, /_ 12 - P2.5 _/
NOT_ON_TIMER, /_ 13 - P2.6 */

of course I could be reading header files wrong...

robertinant commented 12 years ago

You are absolutely right. The pin comments are wrong. I have pushed a fix with commit id: fe9d061