Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Posts posted by enl

  1. For the sampling strategy, you probably don't want the repeated strategies.  If it were me, I would  use ADC_SEQofchannels for the two channels.

    As for the dead zone, I generally estimate then adjust it during testing. The value I tend to start with is about 5 degrees (2.5 to either side of the zero)or 2 to 3 percent for linear slides, unless the pot has very small mechanical range (less than 180 degrees, shorter than 10mm for linear). You don't set this in the ADC. That is pure arithmetic after reading, with an approach described above. There are other approaches.The one above doesn't do it if you need control all of the way to zero (with motors, you usually don't, as there won't be enough torque at the bottom end to turn the motor unloaded, much less with load).

    As an example: 270 degree pot, and 5 degree dead zone: When reading, the range for ADC12 is [0..0xfff]. That gives approximately 0x10 counts per degree. The sequence I would use is:

    // n is a signed int to represent the speed
    // d is a bool for direction
    //PWM_max is a constant for the max PWM value. Presume the desired values are UNSIGNED in the range [0..PWM_max]
    scale_val <- PWM_max / 0x800 // this will be computed at compile time. It is more efficient if it is an int
    n <- ADC - 0x800           // set center of pot at zero
    if n<0 then d <- false else d <- true     
    n <- abs(n)     
    if n < 0x28 then n <- 0    // dead zone is 2.5 degrees to either side of zero
    PWM_value <- n*scale_val //scale PWM

    The 0x28 sets the dead zone width. There are other ways, as well, of you need PWM all of the way  to zero, or want independent control of the PWM low end and dead zone width

  2. I can't address everything you asked (I haven't used the eComp) , but as to bidirectional control, that doesn't matter.


    Presume you get a value in the range [0..0xfff] as your control value. There are several approaches, but they all boil down do, essentially, subtracting 0x800 from the read value to put half of the range negative, and half positive.

    For the PWM, if you have a bidirectional driver (inputs are a direction and a PWM pulse) you use the sign for the direction output and the magnitude (absolute value) to set the PWM, probably with scaling.

    For a driver like the 293, you do a bit more in software, but it comes to the same thing. Hold both drives low for stop, Depending on the sign, you pull one high or the other high via PWM.

    For a setup like this, I might set a 'dead band' around the stop. After abs value, if it is less than some small value, treat it as zero. This makes stopping MUCH less touchy, and makes it much easier to avoid the condition of PWM too low for the motor to run, but still heating up the motor and driver.

  3. You have  a wide variety of clock options from 48MHz down to about 10KHz, on board,  the ability to use external clocks (crystals or other sources), and direct support for 32768Hz crystals (and others). You can't reliably go beyond 48MHz, but the internal clock generator will give a fairly smooth range down to the low end (I don't recall the bottom end of the DCO, but the LFO-- ultra low power, low frequency onboard unit- is below 10KHz)


    Most libraries and language families will provide a way to select which clock and set the rate for the DCO or other source. See http://www.ti.com/lit/ds/symlink/msp432p401r.pdf page 123 for summary.

  4. It is a clever solution, and I learned a few things I hadn't realized about the interrupt flags, but I do think it is a solution in search of a problem.

    To me, it isn't that the interrupt handler is the only way, or always the best way, but that it is simple and has a low penalty in cycle usage and power, relative to polling this way. Fewer clock cycles per loop (single mask to check one bit, rather than several changes to control register states and masks), and, since this is likely to be a rare event at code speed, net minimal hit. Without working out the numbers, I would guess that each NMI costs about twice as much as each polling loop hit in this example (cycles and power), versus much greater saving each loop for the polling operation.

    Also, the NMI handler is a natural fit to dropping to lowest power states (though the '430 is better than many processor families with regard to wake up from assorted conditions) and allowing the handler to wake up for the polling loop. Can you tell I am not a fan of delay functions that do not sleep the processor? [My first experience with this involved halt on a Z80, with a line frequency-- actually video frame rate-- wake-up used for delay in 8.3ms increments in conjunction with processor HALT... This allowed for wake up as needed, and, by the standard of the times, moderate power savings]


    Please do correct me if I am missing something here... This isn't something I have really considered with this processor before.

  5. On 12/5/2017 at 4:51 PM, NurseBob said:

    Keep it simple - just edit the <name> folder if that's the one with a space in it.  Over the years I've learned to keep names as close as possible to the old DOS naming standards, as many developer tools are not always forgiving of long names, or other naming issues most of us have forgotten ever existed...

    Fixing the folder name would be far, far less complex than moving all of the Energia files, which would likely introduce other errors.

    As a general rule, you should never use file or directory names with spaces in them. They tend not to work well with many tools, and tend not to work well across platforms, and do not work at all with some environments/platforms. We have all seen the abomination that occurs when a URL contains a space, and some of us have seen environments where some superstar realizes that, on windows, a filename or directory name can consist of nothing but spaces. Have fun with that. It does not help that Windows does not handle paths consistently across contexts, and, though better than in the days of Win95, still does not handle capitalization in file/directory names consistently across all contexts.

  6. Best advice I can give you is to breadboard it. The LM3915 is pretty rugged, as long as you don't mix up the power supply pins, and everything else except the analog switch is, as well. The frequencies are low. This is very bread-boardable. The 4000 series IC's are not as static sensitive as some, but they do take some care. ALL unused inputs should be connected to ground or V+. I generally use about a 10K resistor, rather than direct connection, primarily because there are some failure modes that can occur during power cycling  if the inputs are direct connected to V+ or ground, and the resistor limits current generally preventing damage. The unused analog pins should also be connected to ground.

  7. Does anyone have recommendations for a current probe for use with an oscilloscope? I borrow a Tektronix from work when I need one at home, but a friend now needs one for field work and needs to be able to look at moderately short pulses (1 microsecond-ish), and he needs to buy out of pocket. The low end Tek, which would do the job, are about $700, but there must be other options that are decent these days for 1mA resolution. The specs for the Hantek CC-65 don't really do it, other than price. Suggestions?

  8. I am not sure what you are trying to ask, or what processor you are working with, but it appears that you don't have a good understanding of fixed point representations


    The value from the DS18B20 is a signed (2's complement) fixed point, 16 bit value. Cutting off the last four bits using a right shift that shifts zeros in to the left removes the sign. The shift can be done so as to preserve the sign by using the appropriate arithmetic right shift (arithmetic right shift RRA in assembler on the MSP430, or right shift operator in C on CSS).  This will give an integer in 16 bit 2's complement. The rounding will ALWAYS be the floor (truncate to smaller value; round down) operation.

    To get round towards zero, you can use a condition such as (in C):

    if (t<0) t+=16;


    if (t<0) t++;

    to do the job.


    If you want 'conventional' (grammar school) rounding (round down for the fraction <1/2, up for fractions >=1/2), then


    would be the cannonical way.

    If you want symmetrical rounding such that if the fraction of |t| < 1/2 is toward zero, and if hte fraction of |t|>=1/2, round away from zero, then, again, the easiest way is a condition:

    if (t<0) 

    Really, you need to know the desired behaviour. There are a lot of reasons why the default action is desirable (always round to negative infinity), in particular because then each count represents a range of one degree, rather than the range for zero being two degrees.

  9. Depending on the flash unit, the max current during charge may be quite high, 5A or more, judging by my Vivitar. The LM317 will current limit (the exact value depends on the version and manufacturer of the device), and the supply you are sourcing the LM317 from may also limit current. If the LM317 isn't warming up, it is likely the supply, not hte regulator. Another possibility is that the supply for the lm317 isn't high enough voltage for the regulator to do its job. It is not low drop out, and the max current goes down as the drop across the regulator goes down. Again, the exact voltage depends on the version, but typical is 1A max at 2V (from the onSemi data sheet) and a 2.5 input-to-output for the rater 1.5A output.

  10. 13 hours ago, johnsondavies said:

    I'm really sorry for wasting your time - I've worked out what the problem is and it's entirely my fault. Everything is working fine now.

    Could you tell us the issue so that others can avoid it, or recognize it when a mistake is made?

  11. "if (bar[0]==NULL)" won't look at the pointer value, but instead the memory the pointer references, so that is right out, unless you want to know if the parameter is an empty string (only the null terminator)

    "if (bar == NULL)" should work, in particular if you explicitly pass NULL in since you are comparing a value to itself, as should "if (!bar)", since NULL should be 0.

    I just checked both (using gcc on a windoze machine) and they work as expected, so I can offer no insight as to why you would have a problem. I would suspect that you are seeing a symptom of some other issue than pointer comparison.

  12. In my first reply to the "true random number" thread, the last code block gave weird behaviour. The code editor opened, but refused to close. The code shows in a code block, but, when editing the post, the block can not be selected and acts like regular text.

  13. (continued, due to editor throwing a fit on last code block in previous post)

    Your example: ( {1839765.71, 1839765.79} ) ... But only move the last digit (from 1 to 8)


    Presuming that you mean the last digit is selected from [1, 2, ..9], could be written as


    Again, note that the randomd() function DOES NOT include the right endpoint, so b is one least count greater in the function call than in your example. If you want the upper bound included, the function gets an n-1 for the division in offset.

  14. Notation: [ and ] indicate that the endpoint is included, ( and ) indicate a range that is open (endpoint not included)

    First, I will presume you have a way to produce a random sequence of values (standard function or your own). Depending on the toolchain and libraries you use, the most common results of this are: A float (or double) [0..1), an unsigned (int or long int) over the full range of the type, or an int in a specified interval [0..n). The function to produce a bounded integer can be written several ways, but the two most common are

    // return a random value from the interval[0..n]
    unsigned random (unsigned n) {
       // rand() returns an unsigned int over [0..MAXUNSIGNED]
       return rand()%n;

    as shown above, and

    // return a random value from the interval[0..n]
    unsigned random (unsigned n) {
       // rand() returns an unsigned int over [0..MAXUNSIGNED]
       return (int)((((double)rand())/MAXUNSIGNED)*n);

    The second version (yes, I over-parenthesized to make the structure clear) first generates a real over [0..1) then scales to the desired range and truncates to an int. This is preferred for good behavoiur in some applications, especially with the common congruential pseudorandom generators, but is slower then the other version. For most things, it isn't important.


    (warning: the code is off the top of my head and untested...)


    If you are generating an integer in a range, such as [20..28)--8 values in the set--, or, more generally, [k..k+n) with n values:

    // k is least in interval
    // n is number of values to include
    // random(n) is a function that produces values in the interval [0..n)
    int r=k+random(n);

    If you are generating a real value, as in your example, the principle is the same

    // generate a double in specified interval from [a..b), selected from n values
    double randomd(double a, double b, unsigned n) {
    // this could be simpler in practice, but the structure here is to show method
    // the method requires care it it is critical that it produces best values in
    // that can be represented, starting with the applications definition of 'best'
       unsigned ri=random(n);
       double range =b-a;
       double offset=range*ri/n; // this is the offset from the starting value
       // ri/n will be a real from [0, range/n, 2*range/n,... (n-1)*range/n]
       return a+offset;

    If you want a value selected from all reals in the interval:

    // generate a double in specified interval from [a..b)
    double randomd2(double a, double b) {
       double range =b-a;
       double offset=range*(rand()/MAXUNSIGNED); // this is the offset from the starting value
       return a+offset;
  15. A good bench is at the top of the list. I have an industrial assembly bench as my primary space with a work area of 1500mm by 700mm. It came with outlets mounted in the shelf faces, the front of the work area, and the back f the work area, but I ended up adding several more duplexes (4, for a total of 8 more) as well as a few 2A USB sources and an IEC320 strip (I scored a bunch of 600mm IECmale to female cords at Eli Heffron's back in the late '80s. They still come in handy) Power is key, and not just for electronics work, These power the scope, logic ananyzer, several meters, computer, monitors, power supplies, and several projects.

    The bench has a lighted magnifier-on-a-stick which gets a LOT of use (I have about a half dozen mounted around the shop and the office. I am getting old and have had several eye injuries) as well as the optivisor and a bunch of loupes. My go-to style loupe is the jewelers style (black conical with a single lens) of 2.5 to 5X. The 5X and 10X Bauch and Lomb that clips onto my glasses gets a lot of use, as well. One good one costs as much as several cheapies, but the cheap ones are useless due to distortion. Go good with glass lenses. I also keep several powers of cheater reading glasses around as well as safety glasses with cheaters.


    A stereo microscope gets a lot of use. High power isn't the key for electronics. It lets you work in a more comfortable position and focus without strain. I would love a Mantis, but can't justify the cost, so I have a 7.5 to 75X Nikon that spends most of the time at the 7.5X end. It also gets used for machinist work (I made a mount for the lathe and for the mill), and for measurement and for photography. If you can find one (craigslist is your best friend) an arm mount beats a base any day. It isn't too hard to make a mount, but it is nice to have it come with one.


    My monitors are mounted to the back rail of the bench. Dual monitors (if I upgrade the machine, I'll go for three next time) of good size are a requirement to maximize workflow and reduce eyestrain from focal changes. It doesn't seem like it should matter, but it does. A lot. They also get use with the microscope camera for a lot of things when I prefer not to be staring down the eyepieces.

    A decent workholding vise is nice. I made several for specific purposes, including board-holding.

    If I was to name the MOST important thing, it is light. A lot of glare free light. I have about 5000lm/m^2 at the bench, from multiple directions, most diffuse sources, and have about another 10000lm available task lighting (fixed fluorescent and lamps on movable arms). About 20%  of this os LED floods, to give some shadowing and contrast, the rest being quite uniform from flourescent.. I use high color rendering index lights (90+) daylight (6500k) mostly. I have a few fixtures in the shop with warm (4500K) so it doesn't feel so clinical, but hte key is a LOT of light. Magnification comes right with this.

    As I also use the space for woodwork and machining, I also have a bunch of vises for these tasks. A decent drill press vise can serve a lot of masters.  The one I get the most use from is an ancient, swap meet, palmgren 2-1/2" angle vise. Second is a dirt cheap ($2?) yard sale job with 1" and 1-1/2" jaws that rotates (no brand.... just "Japan"). The jaws on that needed a little dress with a file, and the vacuum holddown went to the trash, but it works a treat for everything from holding a probe in place to holding a micrometer suspended in mineral spirits during rebuild. I never had mch use for a panavise or equivalent, though I have had several, as they never seem to be rigid enough or be able to get to the position I need them in.


  16. On 3/20/2017 at 5:34 PM, biza said:

    Thank you Nurse Bob,
    for answer my question, I have 5V power supply to LM35. but my problem has in P5.4 without connect to the output pin of LM35, in the multimeter I measure 1.10 to 1.15V , why? All that calcules are in LM35 data sheet.



    Am I reading correctly that this is with the LM35 not connected to the input pin? In other words, there is nothing connected to the input pin?

    If this is the case, then the potential on the pin will float, generally to about half of the power supply, give or take (depends on the device) and, being configured as an input, it will have very high impedance, so it will pick up noise. You would be measuring more the properties of the multimeter and its interaction with the floating input than a real potential.

  17. 1 hour ago, yyrkoon said:

    Much of it was talking about BS that has nothing to do with programming, and the assumptions he posed were no where close to how I see things. It was not until the questions part of the video, that someone else even came close to why I prefer C instead of C++ most of the time . . .

    Question: " What do you do when someone says C++ is far more complex than C . . ."

    Dan Saks: "Uh . . . nothing . . . it's true . . ."





    As far as his testing results . . .yeah, I do not believe it. But I'm far more likely to believe all that, than the other crap he was spewing.

    Most of his talk was not about C++, but about how to social engineer others into adopting in a non-supportive environment. It was a religious rather than technical exposition, as many Java talks, for example, also are. 


    As to the data, I buy it. The technical points made are that strong typing reduces run time bugs is true, under the umbrella that only certain flavours of bug are caught, but these flavours lead indirectly to bugs of kinds not caught directly. Another advantage of strong typing is that, properly used, it can let the compiler do better optimization. His test case,  a lightweight class, is probably where the advantages are greatest, but this is where, for many embedded applications, the other benefits to C++ are most available. I am not convinced that many of the 'more advanced' C++ tools and abstractions will give the same benefits, other than, with proper design, reduced debugging.With improper design (as one of the questioners put it, 'naive') there are likely to be losses. Some tools impose run time penalties that are unavoidable (often space rather than time) even with strong typing, but many of the standard tools (vector, for example) minimize this hit and save enough in other ways to be a net gain.


    Well designed standard tools pretty much always beat implementation specific, since they are designed (usually) by a specialist whose sole point is to get the best performance (by some metric) on the specific hardware. C++ provides a LOT of these tools. There are cases where a special purpose tool is better, but these are often brittle when changes are required, and the next revision has a net loss, either in performance (time or space) or in increased debugging.

    For reference, I tend to be a 'well written C is valid C++' kind of programmer, and use the C++ tools sparingly, especially in embedded work, and am NOT a C++ guru. I am, in fact, quite out of date with regards to the state of the C++ art. I still use the tools as they are appropriate, though.


    As for the social engineering aspects of the talk, nothing new. Read Dale Carnagie for the same. It is an effective model for understanding others and working with them. Nothing that hasn't been in writing for a good century, and known much longer, though in this case there is the extra fancy four quadrant graph of belief presentation.

  18. 4 hours ago, bluehash said:

    @enl I don't think https were enabled before the upgrade. There is no ssl cert on the server yet. I plan to get one from Lets Encrypt.

    Ah. I went through the log and saw that I had added the site as an exception on one machine (one I generally use for such) in 2015. Tried accessing from the shop machine today. I am surprised I haven't noticed before, but, then again, the shop machine has all of three bookmarks in the browser, since it is generally used only for the shop gear.

  19. I presently both practice and teach, so, in reference only to the engineering side, which is maybe 30% of my professional life these days:



    How many engineering positions have you had?


    *4 or so in the last 30 years.  Current engineering position has been about 10 years, and is a different field than my degree (mechanical eng/welding is the core scope, but my degree is semiconductor fab/computer eng. I cover a wider base than that, mostly by being liaison between the company and clients or inspectors) I haven't actually worked primarily in my nominal field since the late 1980's.



    Do you enjoy writing?


    *to a point


    What tasks do you do that involve writing in your job position?


    *Job bids/proposals; RFI/RFQ (request for info/request for quote); evaluations; training materials; compliance materials (safety program, statements of compliance, etc); professional opinion documents; requirements documents; interpretations (code and standards, regulations); documantation/logs for jobs;


    Do you use the writing formats/styles that you learned in school?


    *Sometimes. Much of what I do is specialized, though not as specialized as the 2-page-long paragraphs found in military specifications and RFQ's, and much is dealing with non-engineer-tpe, often non-native english speakers (spanish, norwegian, japanese, german, korean, etc), so the formal styles that were focused on when I was in school don't match well. THings have likely changed, though, so the current teaching practice ma be a better match.


    How often do you encounter a disorganized email and/or document?


    *Daily. Hourly.


    Does reading an un-formatted/disorganized document take time away from other job tasks?




    Have you ever had to second guess what a person meant when you read their writing?


    *yes. Daily. Hourly.


    Did you ever have to ask a person what they meant?




    Do you proofread your writing?


    *Yes. I prefer someone else do so, as well. You need to be your own first critic in ANYTHING you do (writing, circuit design, welding, mechanical design, or anything else), but it is easy to be drawn in to what you think you have written. A fresh look helps, especially when it is someone who is not as familiar with the topic as you are.


    Have writing styles changed in the engineering field since you have started?


    *Yup. Computers have made a big difference, as has the default software (MSword). Hand written math  and symbols died not long after I got out of school, expectation of good formatting of text came in at about the same time. For a time, math was either very well formatted (professional tools were used), or was crap (MSword/macwrite). Now, there is a general mediocrity, but most of the time, things can be interpreted. The indented paragraph has given way to the double line-break. The parenthesized clause has become acceptable (and I have accepted it). Spelling is much better with spell check, though odd errors are more common. In the last several years, I have been seeing more textspeak in non-casual documents (for example: "the site crew will return at a l8er date, no less than 30 days and no more than 45 days after work acceptance, to re-pressure test all welds and mechanical joints".) I have also seen a lot more of the use of verbal crutch sounds in written documents (an RFQ starting "So the scope of work shall be"... with no antecedent)

  20. The board sockets on to the power header


    The 5-pin with the cable going to the right is for a button and double pole, center off momentary switch for adjusting the scale in operation. The software does linear interpolation from 0 to 100 degrees F, and allows for key points every 10 degrees. The three yellow wires go to the remote sensor (DS18B20). The mounting is leftover oak from redoing a floor. Glued up, planed, bored for the meter and the electronics, and finished to hang on the wall. The circuit board is mounted by putting epoxy in the pocket and dropping it in.


    Power board on. The tie point for the power line isn't on yet.



    The face of the finished display:


    The finish is shellac. I slopped on a heavy coat, light sanded, and then wiped another couple on. Then paste wax. Not perfect, but I banged it out quickly.


    The meter:



    Operating. The temp in my shop has climbed to 66F with a lot of help from the electric radiator.




  21. I spent some time last year setting up an analog meter driver/thermometer for a client, and at the time, I went through my stock of junk^H^H^H^Hreclaimed parts and found a phase angle meter with degree graduations on it. I said to myself "since I alredy wrote the code and did the dev work on someone elses dime, I should throw one together for myself". A year and a half later, the holidays hit and I was looking for something to do instead of paperwork for work.


    So, I layed out a single sided board (the original was on a launchpad), cut it on the mill, and populated it.




    There was a couple days in the middle between cutting and populating (the holiday, you know), so I had a surprise. The astute amongst you might notice something missing on this layout, given that this is a low power project that will require stable voltage for the analog meter. Yup. No regulator pads.Finished soldering up the board and sitting there in the tray is the regulator. Whoops. I didn't feel like going whole hog (including changing a setup on the mill) for a board just to hold the regulator and a couple caps, so I pulled out a sharpie, a scribe, and an ancient bottle of ferric chloride. 20 minutes later, I had an etched board that would do the job. Ugly, but functional. The layout for the main board will be revised in case I reuse it.




    It doesn't look so bad populated.




    The wire is for USB power.

  22. Presuming you are talking about a processor with no support in hardware for division or multiplication:


    In the absence of hardware support, the fastest is bitwise calculation akin to long division. The cycle is basicly subtract then replace if less, followed by shifts. The structure is similar to long division, and is about the same number of cycles as a single division. This is one-cycle-per-bit in hardware, but a bit more work in software. Figure two shifts, a mask, and a subtraction, and either another mask or unsubracting, plus loop overhead. You may need a 32 (or 24) bit accumulator for the residuals to catch borrows from the LSb.


    The FASTEST CONVERGING practical method is the Babylonian (divide and average; Newton's method), but that requires division, so is likely to be slower in practice for a 16 bit int, even with hardware division (though it may be close)


    If exact value isn't needed, or the range is restricted, other methods can be faster, such as a lookup table, but for a 16bit value, the extra code and lookup table overhead are more likely to slow things down.


    A bit more detail (what processor, what language, how accurate, etc) can narrow it down. This is a case where the wikipedia page isn't bad: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots

  • Create New...