Jump to content
43oh

Derekspeegle

Members
  • Content Count

    21
  • Joined

  • Last visited

Reputation Activity

  1. Thanks
    Derekspeegle reacted to jcR in Serial1 not Working, attachInterrupt not Working   
    I still do not understand why corrections have still not been made for this chip.
    As I needed these corrections, I had to do them myself although I am not a specialist on this subject.
    So I modified the necessary files to have access to all the pins of the MSP430FR5994,
    even those which are not cabled on the Launchpad, in order to be able to use them on my own cards.
    I enclose the modified files as well as the positions in the folders, to help the users facing the same problems as me.
    It would be desirable for the Energia team to finally address these issues and include these changes in a forthcoming release.
    Indeed this chip is perfect to make very good low consumption modules ,
    and the  ENERGIA concept  makes it easy to develop the complementary software
     
    CORRECTED_BUGS.zip
  2. Like
    Derekspeegle reacted to abecedarian in Putting a While Loop within a While Loops   
    @@Derekspeegle - maybe...:

    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; // get voltages function void getVoltages() { //Obtain RAW voltage data voltage1 = analogRead(voltPin); voltage2 = (voltage1 / 1024) * 3.3; voltage3 = voltage2 * 5.65; } void setup() { // configure input and output pins as required: pinMode(voltPin, INPUT); pinMode(voltoutPin, OUTPUT); pinMode(voltoutPin2, OUTPUT); // configure analog/PWM output frequency: analogFrequency(10000); // get our voltages getVoltages(); // set initial fade values based on voltage3 priority // may need some work + additional math so initial values scale properly if (voltage3 >=12) { // high priority fadeValue = 0; // will start at 0 and count up fadeValue2 = 255; // will start at 255 and count down } else { // low priority fadeValue = 255; // will start at 255 and count down fadeValue2 = 0; // will start at 0 and count up } } void loop() { // When the sketch started running, voltage3, fadeValue and fadeValue2 were // initialized in setup() so we don't need to get them again, at the moment. // However, after the first pass through loop(), fadeValue and fadeValue2 // will have been re-calculated within loop(), so all we need to do is get // voltage3 before we loop() again, so fadeValue and fadeValue2 can be // re-calculated before the outputs are changed. // Decide what to do based on voltage3 priority: if (voltage3 >= 12) { // priority is high fadeValue += 10; // add 10 to fadeValue; store result in fadeValue fadeValue2 -= 10; // sub 10 from fadeValue2; store result in fadeValue2 // limit fadeValue and fadeValue2 to values from 0 to 255 fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); } else { // priority is low fadeValue -= 10; // sub 10 from fadeValue; store result in fadeValue fadeValue2 += 10; // add 10 to fadeValue2; store result in fadeValue2 // limit fadeValue and fadeValue2 to values from 0 to 255 fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); } // update voltout pins: analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); // get our voltages for the next pass through loop() getVoltages(); }
  3. Like
    Derekspeegle reacted to roadrunner84 in Putting a While Loop within a While Loops   
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; //If the priority is high while(voltage >= 12) { fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); voltage = analogRead(voltPin) / 55.0; fadeValue = fadeValue + 10; fadeValue2 = fadeValue2 - 10; analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); } // If priority is low while(voltage < 12) { fadeValue = constrain(fadeValue, 0, 255); fadeValue2 = constrain(fadeValue2, 0, 255); voltage = analogRead(voltPin) / 55.0; fadeValue = fadeValue - 10; fadeValue2 = fadeValue2 + 10; analogWrite(voltoutPin2, fadeValue2); analogWrite(voltoutPin, fadeValue); } } I cleaned up the spacing in your code, as you can see, the only difference between the two blocks is the sign of the changes to fadeValue and fadeValue2. You could consider moving the rest of the code to a common place. Or, to move the constrain() call into the update of fadeValue(2).
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; //If the priority is high while(voltage >= 12) { voltage = analogRead(voltPin) / 55.0; fadeValue = constrain(fadeValue + 10, 0, 255); fadeValue2 = constrain(fadeValue2 - 10, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); } // If priority is low while(voltage < 12) { voltage = analogRead(voltPin) / 55.0; fadeValue = constrain(fadeValue - 10, 0, 255); fadeValue2 = constrain(fadeValue2 + 10, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); } } Also, I guess you're trying make some kind of fade in/out function, which is not what you're really doing. The while loops will be so fast that there is no real fading. The gross result will be that the outputs will drift to some mean point, or maybe oscillate a little around that value at a very high frequency. I assumed in this that voltoutPin and voltPin are tied together, an analog lagging filter would of course result in some kind of slower sinoid signal.
    It triggers me that your two cases seem to be exactly opposite in behavior. You might consider removing those while loops alltogether, since loop() is a loop itself.
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; if(voltage >= 12) // high priority { fadeValue = constrain(fadeValue + 10, 0, 255); fadeValue2 = constrain(fadeValue2 - 10, 0, 255); } else // low priority { fadeValue = constrain(fadeValue - 10, 0, 255); fadeValue2 = constrain(fadeValue2 + 10, 0, 255); } analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, fadeValue2); } Then, in setup() you set either fadeValue or fadeValue2 to 255, the other to 0. Why not do that calculation on the spot, since you'd always have the sum of fadeValue and fadeValue2 be 255.
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; if(voltage >= 12) // high priority fadeValue = constrain(fadeValue + 10, 0, 255); else // low priority fadeValue = constrain(fadeValue - 10, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); } And lastly, I'd like to introduce you to the ternary operator, use it with care, also it might make your code a little more obscure.
    The ternary operator is written like this
    (condition) ? (true-value) : (false-value) In contrast to the if() ... else ... construction, the ternary operator returns a value, it is not intended to run statements. Example:
    food = (animal == monkey) ? banana : grass; so if the animal variable is monkey, food becomes banana, otherwise it becomes grass.
    Another example, now with real values
    abs_val = (val > 0) ? val : -val; This will check is val is positive, then abs_val becomes that val, otherwise abs_val becomes the negative of val, and the negative of a non-positive number is a positive number itself. So now we have abs_val containing the absolute value of val.
     
    In your code, you either add 10 or subtract 10 depending on a condition (voltage >= 12), adding -10 is the same as subtracting 10, so we could either add 10 or -10 depending on your condition:
    fadeValue = constrain(fadeValue + ((voltage >= 12) ? 10 : -10), 0, 255); Note that for readabilities sake I put the ternary operator between braces, though that's not necessary.
    Your code would become:
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; fadeValue = constrain(fadeValue + (voltage >= 12 ? 10 : -10), 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); } You see that the code might become a little harder to read, also it does not speed your code up; the compiler will do something very similar to what it already did.
    Note that voltage is now only used once, so you could slide that in too, but your code would become even more obscure and it would not speed anything up either.
    A little more readable:
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin) / 55.0; fadeValue += (voltage >= 12 ? 10 : -10); fadeValue = constrain(fadeValue, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); }
  4. Like
    Derekspeegle reacted to roadrunner84 in Putting a While Loop within a While Loops   
    That is not my code, that's OP's code, but with nice indentation
    As I said directly below that code block:
    Eventually the values of OP's code would settle to 0 and 255 or mean out to anything that's a sum of those. Since I later optimize fadeValue2 away, the only thing undefined is fadeValue, but that's limited to the 0 to 255 range because of the constrain() call. This means the only thing undefined is where in the settling/oscillation loop the sketch begins, which is okay-ish.
     
    A little more speedy, based on my latest code example.
    As you know you can haul values to the other side of the equation
    a / b = c a = c * b You can do this too to the voltage variable, allowing for you to get rid of the float variable alltogether:
    void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin); fadeValue += (voltage >= 12 * 55.0 ? 10 : -10); fadeValue = constrain(fadeValue, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); } See how I moved the / 55.0 to the other side of the equation in the ternary operator.
    Now since voltage is always an integer value (analogRead gives us an integer value), we can know for sure that the float behaviour is not required:
    int voltage; void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin); fadeValue += (voltage >= 12 * 55 ? 10 : -10); fadeValue = constrain(fadeValue, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); } see how I changes 55.0 to 55, no float constants, so no float calculations.
    Now consider that 55 is a bit magic, (as is 12), consider moving those to constants.
    #define Threshold (12) #define VoltScale (55) /* 5.65 times the voltage at the analog pin ( 3.3 * 5.65 / 1024) */ int voltage; void loop() { //Obtain RAW voltage data voltage = analogRead(voltPin); fadeValue += (voltage >= Threshold * VoltScale ? 10 : -10); fadeValue = constrain(fadeValue, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); } Well, now there is really no good use for the voltage temporary variable:
    #define Threshold (12) #define VoltScale (55) /* 5.65 times the voltage at the analog pin; 1/(3.3 * 5.65 / 1024) */ void loop() { fadeValue += (analogRead(voltPin) >= Threshold * VoltScale ? 10 : -10); fadeValue = constrain(fadeValue, 0, 255); analogWrite(voltoutPin, fadeValue); analogWrite(voltoutPin2, 255 - fadeValue); }
  5. Like
    Derekspeegle reacted to Fmilburn in ADC with MSP430   
    @@Derekspeegle
     
    The input in your first link looks pretty good actually with the exception that it is over 4V.  I don't know what microcontroller you are using but that could be a problem sooner or later.  See the datasheet for maximum.
     
    The code must be working if you get reasonable output after the microcontroller - i.e. the 5th link.  Accordingly, the problem must be in the circuit that follows the microcontroller and not in the code.  You are posting in the wrong place if that is the case since this is the Energia MSP section.
     
    I'm not an electrical engineer and not familiar with those components but here are a couple of suggestions:
    Try probing with the oscilloscope between the discrete components, including the resistor in case it is RC.  That may tell you which one is acting up. Look at the datasheets.  For the 511-VND14NV04-E in particular the maximum turn-on delay, rise time, turn-off delay and fall times add up to a pretty big number at your higher frequency.  
    Suggest posting in an electronics forum rather than microcontroller if you can't figure it out and I have interpreted your problem correctly.  When you post, sketch out the circuit and post it along with oscilloscope so they have the data to help you.  It looks like your oscilloscope has a USB connection.  Use a memory stick and the print button to get better screen shots.
  6. Like
    Derekspeegle reacted to Fmilburn in ADC with MSP430   
    Hi @@Derekspeegle,
     
    There is additional background that would be needed to give meaningful help here.  E.G. what frequencies are you working with, what algorithms are you using, what kind of resolution are you trying to achieve, why are you doing it?  Do you need floating point math?  Are you trying to do it in "real time" or are you storing and processing it later?  Etc...
     
    If this is new to you, then here are a couple of links that might help you get started:
     
    Adafruit tutorial on real time voice changing
    43oh post on 5 kHz FFT using Energia
    43oh post on CounterLib
     
    In any event, this kind of analysis can push (or exceed) the limits of a microcontroller.  So select a fast LaunchPad - e.g. something from the Tiva C series or maybe the MSP432.  Depending on what you are trying to achieve, it may be necessary to code outside of the Energia functions.
     
    edit: took out bit on issues with FR4133
  7. Like
    Derekspeegle reacted to Fmilburn in ADC with MSP430   
    @@Derekspeegle
     
    I don't understand the application, especially the high output frequency, but here are some thoughts....
     
    Signal input and conditioning - Where is it coming from and what does it look like?
     
    Frequency determination - Have you been using PulseIn()? It is a standard Energia function and reads the length of a pulse down to 10 microseconds. Alternatively, you could use CounterLib in the link above to count for a specified time and convert to frequency.
     
    Signal output - It sounds like your output is PWM. Here is a link that explains what you can do in Energia with the MSP430: http://forum.43oh.com/topic/4858-solved-pwm-frequency-in-energia/
     
    For the ARM microcontrollers like the Tiva and CC3200 there is this function that won't work on the MSP430: http://forum.43oh.com/topic/8677-analogfrequency-not-working-cc3200-lp/
  8. Like
    Derekspeegle reacted to Fmilburn in ADC with MSP430   
    Try using the parameter timeout with pulseIn().  Timing is not exact.  Remember that it is in microseconds - not milliseconds. For example, the following should delay about 10 milliseconds...
    pulseIn(2, HIGH, 10000);
  9. Like
    Derekspeegle reacted to abecedarian in ADC with MSP430   
    @@Derekspeegle
     
    Maybe this will do what you want:

    byte PWM1_PIN = P1_5; byte PWM2_PIN = P1_4; byte PWM3_PIN = P1_3; byte ROUT = P1_7; byte GOUT = P1_6; byte BOUT = P8_3; void setup() { analogFrequency(10000); // moved from loop() to setup() pinMode(PWM1_PIN, INPUT); pinMode(PWM2_PIN, INPUT); pinMode(PWM3_PIN, INPUT); pinMode(ROUT, OUTPUT); pinMode(GOUT, OUTPUT); pinMode(BOUT, OUTPUT); } void loop() { analogWrite(ROUT, map(pulseIn(PWM1_PIN, HIGH), 0, 1636, 0, 255)); analogWrite(GOUT, map(pulseIn(PWM2_PIN, HIGH), 0, 1636, 0, 255)); analogWrite(BOUT, map(pulseIn(PWM3_PIN, HIGH), 0, 1636, 0, 255)); }If not, since sometimes some functions have issues calling other functions from within themselves, maybe:
    byte PWM1_PIN = P1_5; byte PWM2_PIN = P1_4; byte PWM3_PIN = P1_3; byte ROUT = P1_7; byte GOUT = P1_6; byte BOUT = P8_3; int pwm1_value; int pwm1; int pwm2_value; int pwm2; int pwm3_value; int pwm3; void setup() { analogFrequency(10000); // moved from loop() to setup() pinMode(PWM1_PIN, INPUT); pinMode(PWM2_PIN, INPUT); pinMode(PWM3_PIN, INPUT); pinMode(ROUT, OUTPUT); pinMode(GOUT, OUTPUT); pinMode(BOUT, OUTPUT); } void loop() { pwm1_value = pulseIn(PWM1_PIN, HIGH); pwm1 = map(pwm1_value, 0, 1636, 0, 255); pwm3_value = pulseIn(PWM2_PIN, HIGH); pwm2 = map(pwm2_value, 0, 1636, 0, 255); pwm3_value = pulseIn(PWM3_PIN, HIGH); pwm3 = map(pwm3_value, 0, 1636, 0, 255); analogWrite(ROUT, pwm1); analogWrite(GOUT, pwm2); analogWrite(BOUT, pwm3); }Note that I changed some of your variables' names and their "case" so that those that don't change are all CAPS and those that do are lower case.
  10. Like
    Derekspeegle reacted to Fmilburn in ADC with MSP430   
    @@Derekspeegle
     
    To clarify, the signal is under 5 Hz? Above you said it is not clean. Is it irregular in frequency and/or amplitude? Do you have an oscilloscope trace?
×
×
  • Create New...