Jump to content
43oh

oscarl1718

Members
  • Content Count

    5
  • Joined

  • Last visited

Reputation Activity

  1. Like
    oscarl1718 reacted to jsolarski in Digital or analog Write multiple pins in one command ?   
    Yes you can get faster results but you either have to code it in C and interface with the registers directly
    I.E. P1OUT |= bit1+ bit2 or P1OUT &= ~bit1 + bit2
    the other option is code it in assembly
  2. Like
    oscarl1718 reacted to energia in AnalogWrite Period   
    You can use the function analogFrequency(). This code was contributed by a member but I have not used it myself and kind of forgot about that it was there until this post ;-). I should work perfectly though. I will document it and do some testing on it. Let me know if you run into any issues.
     
    Make sure you call analogFrequency() before analogWrite().
    The lowest frequency is defined by the clock frequency F_CPU / max counter value. Fmin = F_CPU / ((2^16) -1). If you have a launchpad that uses MSP430G2553 then F_CPU = 16MHz which makes Fmin = 244Hz.
     
    For pin numbering and pin usage see diagrams on https://github.com/energia/Energia/wiki/Hardware
     
    All of the P2.x pins that can be used with analogWrite() are on Timer 1 (not all P2.x pins can be used. See the diagrams in the link above). The servo happens to use Timer 0. So as long as you use P2.x pins for analogWrite then you can use both analogWrite() and Servo without interference. Note it is OK to use P2.x for both. Just don't use P1.x with analogWrite().
     
    example:

    /* Set PWM frequency to 20 KHz */ analogFrequency(20000); /* PWM on P2.1 (aka pin 9) with 50% duty cycle */ analogWrite(P2_1, 127); /* Use P1_0 (aka pin 2) as servo pin */ myservo.attach(P1_0); /* Set servo pos. to 90 degrees */ myservo.write(90);
  3. Like
    oscarl1718 reacted to energia in Interrupts for a Newbie   
    Same as in Arduino.
     

    volatile int state = HIGH; volatile int flag = HIGH; int count = 0; void setup() { Serial.begin(9600); pinMode(GREEN_LED, OUTPUT); digitalWrite(GREEN_LED, state); attachInterrupt(PUSH2, blink, FALLING); } void loop() { digitalWrite(pin, state); if(flag) { count++; Serial.println(count); flag = LOW; } } void blink() { state = !state; flag = HIGH; }
  4. Like
    oscarl1718 reacted to Rickta59 in Weird Problem with analogRead() and mySerial.print()   
    After conferring with Robert he thinks and I concur that the problem is probably that the watchdog isr is kicking off
    between the time the ADC capture starts and before it has completed. The watchdog timer reenables the CPU
    which causes the analogRead code to continue execution when it really isn't ready. The code below seems to
    work and is somewhat more power friendly. It uses a combination of sleeping and checking the ADC busy bit.
     
    uint16_t analogRead(uint8_t pin) { 
    // make sure we have an ADC
    #if defined(__MSP430_HAS_ADC10__)
    // 0000 A0
    // 0001 A1
    // 0010 A2
    // 0011 A3
    // 0100 A4
    // 0101 A5
    // 0110 A6
    // 0111 A7
    // 1010 Internal temperature sensor
     
    //TODO: Only int. temp. sensor requires Tsample > 30us.
    // The below ADC configuration applies this rule to all channels right now.
    // ADC10CLK = 5MHz / 5 = 1Mhz
    // Tsample = S&H / ADC10CLK = 64 / 1 MHz = 64 us
    // Tconver = 13 / ADC10CLK = 13 / 1 MHz = 13 us
    // Total time per sample = Tconvert + Tsample = 64 + 13 = 67 us = ~15k samples / sec
    if (pin > 7 && pin != 10) // ADC on pin?
    return 0;
     
    ADC10CTL0 &= ~ENC; // disable ADC
    ADC10CTL0 = analog_reference | // set analog reference
    ADC10ON | ADC10SHT_3 | ADC10IE; // turn ADC ON; sample + hold @ 64
×
×
  • Create New...