Jump to content

Derekspeegle

Members
  • Content Count

    14
  • Joined

  • Last visited

About Derekspeegle

  • Rank
    Member

Contact Methods

  • Website URL
    http://www.keslowcamera.com

Profile Information

  • Location
    Culver City

Recent Profile Visitors

178 profile views
  1. Derekspeegle

    Porting Libraries to energia

    Hello, I've been pulling my hair out trying to get these libraries to compile in Energia for the msp430fr5994. Is there anyone here that might be able to help me port these libraries? I feel like its just about changing some of the declarations and specifics but I don't even know where to start. I would appreciate any help or advice anyone can give . Thanks, CFAF240240A1-013T_Arduino (3).zip
  2. I'm trying to get these libraries and can't seem to get the current versions to compile in energia. Can anyone help with getting these libraries to work, or have advice to point me in the right direction?
  3. Derekspeegle

    Putting a While Loop within a While Loops

    Wow, holy cow. Thank you guys for your amazing input. I have a lot to work through now, I will return and let you guys know how it all went. Thanks a ton. Do you guys think you could look over my other post, ADC with the MSP430? That one is still unanswered. Also, to answer spirilis's questions, I am using the mps430fr4133, can you elaborate more on the problem with analogwrite? I'm using it for another project which involves using analogwrite for rgb values and ive noticed the glitching. Is there a work around?
  4. Derekspeegle

    Putting a While Loop within a While Loops

    Here's my updated code, it should make more sense. Instead of trying to do a while within a while, I just changed it so that the values are constrained. It isnt working the way it should though. The output will go to 100% duty cycle but when It is suppose to fade out it just starts going haywire. I don't think its fading to 0 for some reason. Look at this updated code and let me know what can be done. Thanks. const int voltPin = P1_5; const int voltoutPin = P1_7; const int voltoutPin2 = P1_6; float voltage1; float voltage2; float voltage3; int fadeValue; int fadeValue2; void setup() { pinMode(voltoutPin, OUTPUT); pinMode(voltoutPin2, OUTPUT); pinMode(voltPin, INPUT); analogFrequency(10000); } void loop() { //Obtain RAW voltage data voltage1 = analogRead(voltPin); voltage2 = (voltage1 / 1024) * 3.3; voltage3 = voltage2 * 5.65; //If the priority is high while(voltage3 >= 12) { fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); voltage1 = analogRead(voltPin); voltage2 = (voltage1 / 1024) * 3.3; voltage3 = voltage2 * 5.65; fadeValue = fadeValue + 10; fadeValue2 = fadeValue2 - 10; analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); } // If priority is low while(voltage3 < 12) { fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); voltage1 = analogRead(voltPin); voltage2 = (voltage1 / 1024) * 3.3; voltage3 = voltage2 * 5.65; fadeValue = fadeValue - 10; fadeValue2 = fadeValue2 + 10; analogWrite(voltoutPin2, fadeValue2); analogWrite(voltoutPin, fadeValue); } }
  5. I'm having an issue with Energia where it isnt allowing me to put a while loops within another while loops or any loop for that matter. I need my program to run a loop for as long as the source is correct but run another loop inside of it a specific number of times. It always gives me an error asking for a ";" before a numeric value. Here is my code. const int voltPin = P1_5; const int voltoutPin = P1_7; const int voltoutPin2 = P1_6; float voltage1; float voltage2; float voltage3; int fadeValue; int fadeValue2; void setup() { pinMode(voltoutPin, OUTPUT); pinMode(voltoutPin2, OUTPUT); pinMode(voltPin, INPUT); analogFrequency(10000); } void loop() { while(voltage3 >= 12){ while(fadeValue < 255){ fadeValue ++10; analogWrite(voltoutPin, fadeValue); } analogWrite(voltoutPin, fadeValue); while(fadeValue2 > 0){ fadeValue2 --10; analogWrite(voltoutPin2, fadeValue2); } } while(voltage3 < 12){ while(fadeValue2 < 255) { fadeValue2 ++10; analogWrite(voltoutPin2, fadeValue2); } analogWrite(voltoutPin2, fadeValue2); while(fadeValue > 0){ fadeValue --10; analogWrite(voltoutPin, fadeValue); } } float voltage; voltage1 = analogRead(voltPin); voltage2 = (voltage1 / 1024) * 3.3; voltage3 = voltage2 * 5.65; } // void loop close Let me know how that I can imbed a loop within another loop or just a better way to do this function. Essentially I'm reading a voltage then when the voltage reaches a certain limit I start to cutoff the voltage source by cutting off the PWM. When I cut it off instantly it shut down the whole system, probably from a voltage surge. So I want it now to ramp it down to avoid that.
  6. Derekspeegle

    ADC with MSP430

    Hello everyone, It turned out that in order to get a solid drive I needed a different gate resistor. Having solved that issue, a new issue came up and this one is actually software related. I'm mapping my input values which range from about 0 - 1580 into a range of 0 - 255. From there, I convert the RGB values that I receive into a HSV number range, adjust the V value, then reconvert the numbers to RGB and output it. The problem is that the output values will be sitting on the edge of the input ranges and swing up and down. The input value will only vary around 1 point after I take a large number of samples but that's enough for it to swing between 2 of the 255 output values. Here is my code : byte PWM_PIN = P1_3; byte PWM_PIN2 = P1_4; byte PWM_PIN3 = P1_5; byte rout = P8_3; byte gout = P1_6; byte bout = P1_7; float pwm_value; float pwm; float pwm_value2; float pwm2; float pwm_value3; float pwm3; const int numReadings = 25; const int numReadings2 = 25; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading float total = 0; // the running total float average = 0; // the average int readings2[numReadings]; // the readings from the analog input int readIndex2 = 0; // the index of the current reading float total2 = 0; // the running total float average2 = 0; // the average int readings3[numReadings2]; // the readings from the analog input int readIndex3 = 0; // the index of the current reading float total3 = 0; // the running total float average3 = 0; // the average int readings4[numReadings]; // the readings from the analog input int readIndex4 = 0; // the index of the current reading int total4 = 0; // the running total float average4 = 0; // the average int readings5[numReadings]; // the readings from the analog input int readIndex5 = 0; // the index of the current reading int total5 = 0; // the running total float average5 = 0; // the average int readings6[numReadings2]; // the readings from the analog input int readIndex6 = 0; // the index of the current reading int total6 = 0; // the running total float average6 = 0; // the average double r; double g; double b; double rd; double gd; double bd; double h; double s; double v; double hsv[2]; double max1; double min1; double max2; double min2; double max; double min; double v1; double r1; double r2; double g1; double g2; double b1; double b2; double s1; double r3; double g3; double b3; void setup() { pinMode(PWM_PIN, INPUT); pinMode(PWM_PIN2, INPUT); pinMode(PWM_PIN3, INPUT); pinMode(rout, OUTPUT); pinMode(gout, OUTPUT); pinMode(bout, OUTPUT); Serial.begin(9600); //Setup for the 6 averaging functions for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } for (int thisReading2 = 0; thisReading2 < numReadings; thisReading2++) { readings2[thisReading2] = 0; } for (int thisReading3 = 0; thisReading3 < numReadings2; thisReading3++) { readings3[thisReading3] = 0; } for (int thisReading4 = 0; thisReading4 < numReadings; thisReading4++) { readings4[thisReading4] = 0; } for (int thisReading5 = 0; thisReading5 < numReadings; thisReading5++) { readings5[thisReading5] = 0; } for (int thisReading6 = 0; thisReading6 < numReadings2; thisReading6++) { readings6[thisReading6] = 0; } } void loop() { analogFrequency(10000); //This section is mapping the signal and inverting it so that it is correct, it also makes it so max zeroes out properly. if (average == 0) { pwm = 0; } else { pwm = map(average,1,1560,260,6); } if (average2 == 0) { pwm2 = 0; } else { pwm2 = map(average2,1,1560,260, 6); } if (average3 == 0) { pwm3 = 0; } else { pwm3 = map(average3,1,1560,260,8); } average = constrain(average,0 , 1560); average2 = constrain(average2,0 , 1560); average3 = constrain(average3,0 , 1560); r = pwm; g = pwm2; b = pwm3; //This section converts the rgb values into HSV values double rd = (double) r/255; double gd = (double) g/255; double bd = (double) b/255; double max1 = max(gd, bd); double max2 = max(rd, max1); double min1 = min(gd, bd); double min2 = min(rd, min1); double h, s, v = max2; double d = max2 - min2; s = max2 == 0 ? 0 : d / max2; if (max2 == min2) { h = 0; // achromatic } else { if (max2 == rd) { h = (gd - bd) / d + (gd < bd ? 6 : 0); } else if (max2 == gd) { h = (bd - rd) / d + 2; } else if (max2 == bd) { h = (rd - gd) / d + 4; } h /= 6; } //This section adjusts the HSV values s1=1.08+0.41*logf(s); v1 = v*32/100; s1 = constrain(s1,0,1); //This section takes the newly adjusted HSV values and converts them back to RGB float r1, g1, b1; int i = int(h * 6); float f = h * 6 - i; float p = v1 * (1 - s1); float q = v1 * (1 - f * s1); float t = v1 * (1 - (1 - f) * s1); switch(i % 6){ case 0: r1 = v1, g1 = t, b1 = p; break; case 1: r1 = q, g1= v1, b1 = p; break; case 2: r1 = p, g1 = v1, b1 = t; break; case 3: r1 = p, g1 = q, b1 = v1; break; case 4: r1 = t, g1 = p, b1 = v1; break; case 5: r1 = v1, g1 = p, b1 = q; break; } r2 = r1 * 255; g2 = g1 * 255; b2 = b1 * 255; //Section for taking an average of the 3 inputs total = total - readings[readIndex]; readings[readIndex] = pulseIn(PWM_PIN, HIGH, 10000); total = total + readings[readIndex]; readIndex = readIndex + 1; if (readIndex >= numReadings) { readIndex = 0; } average = total / numReadings; total2 = total2 - readings2[readIndex2]; readings2[readIndex2] = pulseIn(PWM_PIN2, HIGH, 10000); total2 = total2 + readings2[readIndex2]; readIndex2 = readIndex2 + 1; if (readIndex2 >= numReadings) { readIndex2 = 0; } average2 = total2 / numReadings; total3 = total3 - readings3[readIndex3]; readings3[readIndex3] = pulseIn(PWM_PIN3, HIGH, 10000); total3 = total3 + readings3[readIndex3]; readIndex3 = readIndex3 + 1; if (readIndex3 >= numReadings2) { readIndex3 = 0; } average3 = total3 / numReadings2; //Section for taking an average of new rgb values before output total4 = total4 - readings4[readIndex4]; readings4[readIndex4] = r2; total4 = total4 + readings4[readIndex4]; readIndex4 = readIndex4 + 1; if (readIndex4 >= numReadings) { readIndex4 = 0; } r3 = total4 / numReadings; total5 = total5 - readings5[readIndex5]; readings5[readIndex5] = g2; total5 = total5 + readings5[readIndex5]; readIndex5 = readIndex5 + 1; if (readIndex5 >= numReadings) { readIndex5 = 0; } g3 = total5 / numReadings; total6 = total6 - readings6[readIndex6]; readings6[readIndex6] = b2; total6 = total6 + readings6[readIndex6]; readIndex6 = readIndex6 + 1; if (readIndex6 >= numReadings2) { readIndex6 = 0; } b3 = total6 / numReadings2; Serial.println("b1"); Serial.println(average); Serial.println("b2"); Serial.println(average2); Serial.println("b2"); Serial.println(average3); analogWrite(rout, r3); analogWrite(gout, g3 ); analogWrite(bout, b3); //Serial.println("average3"); //Serial.println(; } I was also having an issue where in the final stage of calculation it would multiply 0.01 by 255 but it would give me 4.5 and vary to 3.8 without the input 0.01 changing. Why would the result change without the input changing? This was also making my output vary. I would also appreciate any pointers on how to execute code since I'm a novice. Thanks,
  7. Derekspeegle

    ADC with MSP430

    Thank you for all of your suggestions. Your right that it would seem that the coding is working correctly. I just wasn't sure if there might be a way to help with the problems in the lower range by altering the code. I'll be sure to post this in an electronics forum next using your suggestions.
  8. Derekspeegle

    ADC with MSP430

    So, the signal is mostly a square wave but its frequency is a little messed up. Here is a picture of the signal, https://www.dropbox.com/s/nprycl84ckpgh56/20160303_091710.jpg?dl=0 Once my processor receive it, it runs this code : byte PWM_PIN = P1_5; byte PWM_PIN2 = P1_4; byte PWM_PIN3 = P1_3; byte rout = P1_7; byte gout = P1_6; byte bout = P8_3; float pwm_value; float pwm; float pwm_value2; float pwm2; float pwm_value3; float pwm3; const int numReadings = 15; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average void setup() { pinMode(PWM_PIN, INPUT); pinMode(PWM_PIN2, INPUT); pinMode(PWM_PIN3, INPUT); pinMode(rout, OUTPUT); pinMode(gout, OUTPUT); pinMode(bout, OUTPUT); Serial.begin(9600); for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } } void loop() { analogFrequency(10000); int pwm = map(average, 0, 1579, 0, 255); //pwm_value = pulseIn(PWM_PIN, HIGH, 10000); //int pwm2 = map(pwm_value2, 0, 1579, 0, 255); pwm_value2 = pulseIn(PWM_PIN2, HIGH, 10000); //int pwm3 = map(pwm_value3, 0, 1579, 0, 255); pwm_value3 = pulseIn(PWM_PIN3, HIGH, 10000); total = total - readings[readIndex]; readings[readIndex] = pulseIn(PWM_PIN, HIGH, 5000); total = total + readings[readIndex]; readIndex = readIndex + 1; if (readIndex >= numReadings) { readIndex = 0; } average = total / numReadings; Serial.println(pwm); analogWrite(rout, pwm); analogWrite(gout, pwm2); analogWrite(bout, pwm3); } Then this is the wave I get, which is fairly accurate as the same signal at a higher frequency. https://www.dropbox.com/s/vpbbll1r70b0gvo/20160303_091800.jpg?dl=0 Then it is put through a gate driver , 849-IXDN602SIA, through a 74 Ohm Resistor then into the Omnifet, 511-VND14NV04-E. Afterword, I get this driven signal, . https://www.dropbox.com/s/f1o87jftcq6lu8g/20160303_091822.jpg?dl=0 The issue that I'm having currently is that when I'm in the duty cycle range of 2-19, the Omnifet puts out strange signals. My serial com is showing that my device is putting out the correct duty cycle for the most part. When my duty cycle is 1 it even works correctly Just not between 2 and 19. Here is the signal coming in during that range, https://www.dropbox.com/s/0zxfbskqax7jr0e/20160303_093528.jpg?dl=0 Here is the signal after the MCU https://www.dropbox.com/s/6gb4i490rxo1s06/20160303_093547.jpg?dl=0 Here is my issue, after the Mosfet https://www.dropbox.com/s/vxlbn4psy3xzwxy/20160303_093601.jpg?dl=0 That signal at the end is wavering all over the place. Any help would be appreciated, Thanks.
  9. Derekspeegle

    ADC with MSP430

    Sorry for the slow response, I was doing a ton of testing. Using the delay function from within the PulseIn I am able to have it read and output at a high frequency and its fairly accurate. My issue now is that it has a weird jitter from time to time and cant properly read the pulse when it's value is under 5. How can I trim the results so that they are more solid and enable it to read the low end?? Here is my code as it stands. Thanks for all the help byte PWM_PIN = P1_5; byte PWM_PIN2 = P1_4; byte PWM_PIN3 = P1_3; byte rout = P1_7; byte gout = P1_6; byte bout = P8_3; float pwm_value; float pwm; float pwm_value2; float pwm2; float pwm_value3; float pwm3; void setup() { pinMode(PWM_PIN, INPUT); pinMode(PWM_PIN2, INPUT); pinMode(PWM_PIN3, INPUT); pinMode(rout, OUTPUT); pinMode(gout, OUTPUT); pinMode(bout, OUTPUT); } void loop() { analogFrequency(10000); int pwm = map(pwm_value, 0, 1024, 0, 255); pwm_value = pulseIn(PWM_PIN, HIGH, 10000); int pwm2 = map(pwm_value2, 0, 1024, 0, 255); pwm_value2 = pulseIn(PWM_PIN2, HIGH, 10000); int pwm3 = map(pwm_value3, 0, 1024, 0, 255); pwm_value3 = pulseIn(PWM_PIN3, HIGH, 10000); analogWrite(rout, pwm); analogWrite(gout, pwm2); analogWrite(bout, pwm3); }
  10. Derekspeegle

    ADC with MSP430

    Hello, Thank you for your incredibly helpful replies. I will try out both methods and let you know how they end up working, thanks !
  11. Derekspeegle

    ADC with MSP430

    Hello, So it looks like everyone worked the way it was suppose to except one issue. The PulseIn function causes a huge delay of about 5 seconds when I change the input signal. It updates properly but takes a long time to do it. I know that it's because the PulseIn function sits on the signal until it times out, I just dont know how to fix it. I tried adding a small incremental timer just so that the sample is short but that stops it from working altogether. Please Help >< Here's my code, I'm new to coding so please feel free to give any pointers. byte PWM_PIN = P1_5; byte PWM_PIN2 = P1_4; byte PWM_PIN3 = P1_3; byte rout = P1_7; byte gout = P1_6; byte bout = P8_3; int pwm_value; int pwm; int pwm_value2; int pwm2; int pwm_value3; int pwm3; volatile int timers = 0; void setup() { pinMode(PWM_PIN, INPUT); pinMode(PWM_PIN2, INPUT); pinMode(PWM_PIN3, INPUT); pinMode(rout, OUTPUT); pinMode(gout, OUTPUT); pinMode(bout, OUTPUT); } void loop() { analogFrequency(10000); for (int timers = 0; timers < 2; timers++) { int pwm = map(pwm_value, 0, 1636, 0, 255); pwm_value = pulseIn(PWM_PIN, HIGH); delay(100); } for (int timers = 1; timers < 3; timers++) { int pwm2 = map(pwm_value2, 0, 1636, 0, 255); pwm_value2 = pulseIn(PWM_PIN2, HIGH); delay(100); } for (int timers = 2; timers < 4; timers++) { int pwm3 = map(pwm_value3, 0, 1636, 0, 255); pwm_value3 = pulseIn(PWM_PIN3, HIGH); delay(100); } for (int timers = 3; timers < 5; timers++) { analogWrite(rout, pwm); analogWrite(gout, pwm2); analogWrite(bout, pwm3); delay(100); timers = 0; } }
  12. Derekspeegle

    ADC with MSP430

    Hello, So, I was able to more accurately read the pulses by pulling the PWM from a different location. When I used the pulseIn function before it wasnt working because I was pulling the waves from the output of the driver, so it was supplying ground on the pulses not voltage. Now I'm getting pretty accurate data and it reflects the data of the driver perfectly. I believe I can handle the rest from here, Thanks to both of you Thanks,
  13. Derekspeegle

    ADC with MSP430

    Thanks for the help with that fix energia. Fmilburn, Thanks for the response. I'm working with a frequency around 600hz and I want to step up the frequency to about 10k while keeping the duty cycle. The point is to increase the frequency of an LED driver. So I need to keep the duty cycle in order to output the correct RGB values. This would need to be done in Real Time in order to allow for control of the values. I'm working on creating my own driver but for now i'm trying to use this to improve upon an existing driver. The values done need to anymore accurate then 0-255 decimal so i dont think i need floating point math. Let me know if you have any suggestions. Thanks!
  14. Derekspeegle

    ADC with MSP430

    Update: I need help with another related issue. Hello everyone, It turned out that in order to get a solid drive I needed a different gate resistor. Having solved that issue, a new issue came up and this one is actually software related. I'm mapping my input values which range from about 0 - 1580 into a range of 0 - 255. From there, I convert the RGB values that I receive into a HSV number range, adjust the V value, then reconvert the numbers to RGB and output it. The problem is that the output values will be sitting on the edge of the input ranges and swing up and down. The input value will only vary around 1 point after I take a large number of samples but that's enough for it to swing between 2 of the 255 output values. Here is my code : byte PWM_PIN = P1_3; byte PWM_PIN2 = P1_4; byte PWM_PIN3 = P1_5; byte rout = P8_3; byte gout = P1_6; byte bout = P1_7; float pwm_value; float pwm; float pwm_value2; float pwm2; float pwm_value3; float pwm3; const int numReadings = 25; const int numReadings2 = 25; int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading float total = 0; // the running total float average = 0; // the average int readings2[numReadings]; // the readings from the analog input int readIndex2 = 0; // the index of the current reading float total2 = 0; // the running total float average2 = 0; // the average int readings3[numReadings2]; // the readings from the analog input int readIndex3 = 0; // the index of the current reading float total3 = 0; // the running total float average3 = 0; // the average int readings4[numReadings]; // the readings from the analog input int readIndex4 = 0; // the index of the current reading int total4 = 0; // the running total float average4 = 0; // the average int readings5[numReadings]; // the readings from the analog input int readIndex5 = 0; // the index of the current reading int total5 = 0; // the running total float average5 = 0; // the average int readings6[numReadings2]; // the readings from the analog input int readIndex6 = 0; // the index of the current reading int total6 = 0; // the running total float average6 = 0; // the average double r; double g; double b; double rd; double gd; double bd; double h; double s; double v; double hsv[2]; double max1; double min1; double max2; double min2; double max; double min; double v1; double r1; double r2; double g1; double g2; double b1; double b2; double s1; double r3; double g3; double b3; void setup() { pinMode(PWM_PIN, INPUT); pinMode(PWM_PIN2, INPUT); pinMode(PWM_PIN3, INPUT); pinMode(rout, OUTPUT); pinMode(gout, OUTPUT); pinMode(bout, OUTPUT); Serial.begin(9600); //Setup for the 6 averaging functions for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } for (int thisReading2 = 0; thisReading2 < numReadings; thisReading2++) { readings2[thisReading2] = 0; } for (int thisReading3 = 0; thisReading3 < numReadings2; thisReading3++) { readings3[thisReading3] = 0; } for (int thisReading4 = 0; thisReading4 < numReadings; thisReading4++) { readings4[thisReading4] = 0; } for (int thisReading5 = 0; thisReading5 < numReadings; thisReading5++) { readings5[thisReading5] = 0; } for (int thisReading6 = 0; thisReading6 < numReadings2; thisReading6++) { readings6[thisReading6] = 0; } } void loop() { analogFrequency(10000); //This section is mapping the signal and inverting it so that it is correct, it also makes it so max zeroes out properly. if (average == 0) { pwm = 0; } else { pwm = map(average,1,1560,260,6); } if (average2 == 0) { pwm2 = 0; } else { pwm2 = map(average2,1,1560,260, 6); } if (average3 == 0) { pwm3 = 0; } else { pwm3 = map(average3,1,1560,260,8); } average = constrain(average,0 , 1560); average2 = constrain(average2,0 , 1560); average3 = constrain(average3,0 , 1560); r = pwm; g = pwm2; b = pwm3; //This section converts the rgb values into HSV values double rd = (double) r/255; double gd = (double) g/255; double bd = (double) b/255; double max1 = max(gd, bd); double max2 = max(rd, max1); double min1 = min(gd, bd); double min2 = min(rd, min1); double h, s, v = max2; double d = max2 - min2; s = max2 == 0 ? 0 : d / max2; if (max2 == min2) { h = 0; // achromatic } else { if (max2 == rd) { h = (gd - bd) / d + (gd < bd ? 6 : 0); } else if (max2 == gd) { h = (bd - rd) / d + 2; } else if (max2 == bd) { h = (rd - gd) / d + 4; } h /= 6; } //This section adjusts the HSV values s1=1.08+0.41*logf(s); v1 = v*32/100; s1 = constrain(s1,0,1); //This section takes the newly adjusted HSV values and converts them back to RGB float r1, g1, b1; int i = int(h * 6); float f = h * 6 - i; float p = v1 * (1 - s1); float q = v1 * (1 - f * s1); float t = v1 * (1 - (1 - f) * s1); switch(i % 6){ case 0: r1 = v1, g1 = t, b1 = p; break; case 1: r1 = q, g1= v1, b1 = p; break; case 2: r1 = p, g1 = v1, b1 = t; break; case 3: r1 = p, g1 = q, b1 = v1; break; case 4: r1 = t, g1 = p, b1 = v1; break; case 5: r1 = v1, g1 = p, b1 = q; break; } r2 = r1 * 255; g2 = g1 * 255; b2 = b1 * 255; //Section for taking an average of the 3 inputs total = total - readings[readIndex]; readings[readIndex] = pulseIn(PWM_PIN, HIGH, 10000); total = total + readings[readIndex]; readIndex = readIndex + 1; if (readIndex >= numReadings) { readIndex = 0; } average = total / numReadings; total2 = total2 - readings2[readIndex2]; readings2[readIndex2] = pulseIn(PWM_PIN2, HIGH, 10000); total2 = total2 + readings2[readIndex2]; readIndex2 = readIndex2 + 1; if (readIndex2 >= numReadings) { readIndex2 = 0; } average2 = total2 / numReadings; total3 = total3 - readings3[readIndex3]; readings3[readIndex3] = pulseIn(PWM_PIN3, HIGH, 10000); total3 = total3 + readings3[readIndex3]; readIndex3 = readIndex3 + 1; if (readIndex3 >= numReadings2) { readIndex3 = 0; } average3 = total3 / numReadings2; //Section for taking an average of new rgb values before output total4 = total4 - readings4[readIndex4]; readings4[readIndex4] = r2; total4 = total4 + readings4[readIndex4]; readIndex4 = readIndex4 + 1; if (readIndex4 >= numReadings) { readIndex4 = 0; } r3 = total4 / numReadings; total5 = total5 - readings5[readIndex5]; readings5[readIndex5] = g2; total5 = total5 + readings5[readIndex5]; readIndex5 = readIndex5 + 1; if (readIndex5 >= numReadings) { readIndex5 = 0; } g3 = total5 / numReadings; total6 = total6 - readings6[readIndex6]; readings6[readIndex6] = b2; total6 = total6 + readings6[readIndex6]; readIndex6 = readIndex6 + 1; if (readIndex6 >= numReadings2) { readIndex6 = 0; } b3 = total6 / numReadings2; Serial.println("b1"); Serial.println(average); Serial.println("b2"); Serial.println(average2); Serial.println("b2"); Serial.println(average3); analogWrite(rout, r3); analogWrite(gout, g3 ); analogWrite(bout, b3); //Serial.println("average3"); //Serial.println(; } I was also having an issue where in the final stage of calculation it would multiply 0.01 by 255 but it would give me 4.5 and vary to 3.8 without the input 0.01 changing. Why would the result change without the input changing? This was also making my output vary. I would also appreciate any pointers on how to execute code since I'm a novice. Thanks, Hello, I have been trying to get a program to work that will analyze a ADC signal and send it back out on another pin with a higher frequency. After trying to make it work using different methods of measuring the duty cycle, I found out that the MSP430fr4133 isn't coded correctly in Energia for ADC. My question is, what functions would you suggest to use in order to measure the wave properly? The waves are not clean digital waves, which is why i want to clean it up. Also, what MSP430 launchpad would you suggest for getting ADC to work on Energia? Thanks,
×