Jump to content


  • Content Count

  • Joined

  • Last visited

Reputation Activity

  1. Like
    aam reacted to Fmilburn in Frequency Measurement   
    Hi @@aam,
    A while back I posted some Energia projects that were to be used as lessons for High School students.  You can find them here:  http://forum.43oh.com/topic/8766-energia-sensor-code-and-library-examples/
    Keep in mind that these were written by a self taught hobbyist (me) for Energia beginners so expect simple concepts and demonstrations only.  In any event, there is one that uses a photoelectric sensor as a tachometer that you might want to look at:  https://github.com/fmilburn3/Tachometer_CNY70
    Also, see CounterLib which is well written and documented and counts pulses.  It uses timers, is written for Energia, but would be easy to use in CCS also.
  2. Like
    aam reacted to Fmilburn in Problem Sampling Rate MSP430F5529 in Energia   
    Use an array to store the values, something like this:
    set NUM_READS to the number of values you wish to record inside loop(), declare an array to contain NUM_READS values inside the for loop that reads values, read the values into the array outside of the loop that reads the values, print the values
    If you make NUM_READS too large it will corrupt the program.  Do not place the serial print inside the loop with the analog read and make sure there is sufficient time for the serial print to finish before starting another read cycle. Serial print is very slow.  With Robert's code changing NUM_READS to 2000 and replacing loop() with this will work:
    void loop() { mark = millis(); uint16_t analogValue[NUM_READS]; for(i = 0; i < NUM_READS; i++) { analogValue[i] = readADC(); } Serial.print("Time: "); Serial.println(millis() - mark); for(i = 0; i < NUM_READS; i++) { Serial.println(analogValue[i]); } Serial.print(NUM_READS); Serial.println(" values printed"); while(1); }
  3. Like
    aam reacted to energia in Problem Sampling Rate MSP430F5529 in Energia   
    With the current implementation of analogRead(), 10kHz is about the best you can get. Below is Sketch that advanced but will get you to up about 166kHz.
    The main difference between this and the implementation in Energia is the clock source for the ADC. 
    #if defined(__MSP430_HAS_ADC12_PLUS__)#define REFV_MAP(x) ((x>>8) & 0x70)#define REF_MAP(x) (x & 0xB1)#define ADCxMEM0 ADC12MEM0 #define DEFAULT_READ_RESOLUTION 12#endif#if defined(__MSP430_HAS_ADC12_PLUS__)#define DEFAULT (ADC12SREF_0 << 8)#define INTERNAL1V5 ((ADC12SREF_1 << 8) | REFON | REFMSTR | REFVSEL_0)#define INTERNAL2V0 ((ADC12SREF_1 << 8) | REFON | REFMSTR | REFVSEL_1)#define INTERNAL2V5 ((ADC12SREF_1 << 8) | REFON | REFMSTR | REFVSEL_2)#define EXTERNAL (ADC12SREF_2 << 8)#endifuint16_t analog_reference = DEFAULT;#define NUM_READS 10000void setup() { Serial.begin(115200); Serial.println("Setup done"); setupADC(A0);}uint32_t mark, time_it_took;uint16_t i;void loop() {// Serial.println(readADC()); mark = millis(); for(i = 0; i < NUM_READS; i++) { readADC(); } Serial.print("Time: "); Serial.println(millis() - mark); Serial.println(readADC());}uint16_t setupADC(uint8_t pin) { uint8_t channel; // Check if pin is a special analog pin (A10 = temp sensor, A11 = Vcc/2, etc.) if (pin >= 128) channel = pin - 128; else channel = digitalPinToADCIn(pin); // Check if pin is valid if (pin == NOT_ON_ADC) return 0;#if defined(__MSP430_HAS_ADC12_PLUS__) ADC12CTL0 &= ~ADC12ENC; // disable ADC ADC12CTL1 = ADC12SSEL_2 | ADC12DIV_0; // ADC12OSC as ADC12CLK (~5MHz) / 5 while (REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT if (pin == TEMPSENSOR) {// if Temp Sensor REFCTL0 = REF_MAP(INTERNAL1V5); // Set reference to internal 1.5V ADC12MCTL0 = channel | REFV_MAP(INTERNAL1V5); // set channel and reference } else { REFCTL0 = REF_MAP(analog_reference); // Set reference using masking off the SREF bits. See Energia.h. ADC12MCTL0 = channel | REFV_MAP(analog_reference); // set channel and reference } ADC12CTL0 = ADC12ON | ADC12SHT0_4; // turn ADC ON; sample + hold @ 64
  • Create New...