This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Very Short PWM

Other Parts Discussed in Thread: MSP430F5438

Hello, I am new to this forum and also sort of new to the MSP430 but know a little bit more than just "beginners."  I am working on a little project. I need to generate about a 5KHZ pulse for roughly .5 milliseconds every 60 Seconds. I guess my first question, is this possible with my MSP430f5438?  Second, would I have to do any little tricks or could I just program the MSP430 similar to the PWM topic programs that were listed in those PWM forums. Thank you in advance!

  • Hi,

    It's definitely possible for the MSP430 to output a 5KHz signal.  I would use PWM feature of the timers to do this. You are aware that .5 milliseconds is 500 microseconds and that the period of 5KHz is 200 microseconds? So in your 500 microsecond output period you would get out about 2.5 cycles.  Is that enough for what you are doing?

    HTH,

    Barry

  • Wow, that was a really fast reply..greatly appreciated!! That is definitely a good sign that my board is capable of doing this. To answer your question let me explain my project. I am trying to evaluate the distance from the surface of water to the well lid in a water well (6" dia. pipe). I will send a pulse down and receive it. Basically measuring well fluctuations over time/usage.  The shorter my pulse is then the better my resolution or accuracy. I believe that would be sufficient since I am not measuring phase changes or anything like that. I am just looking for a return. Whether this will work I am not sure. If not then I will have to dig a little deeper. LOL

  • What kind of pulse do you send down?

    On a reflected pulse, the duration of the pulse is not important, only the resolution of the time measurement between start of the pulse and start of the echo. Depending on the type of pulse, the pulse duration may even exceed the echo time.

    Barry is right with his note that 0.5ms on 5kHz are just 2.5 cycles. The half cycle is maybe not what you want. Also, a short pulse of one cycle is easy. A short pulse of more than one cycle is more tricky to do. So why exactly these values? Is there a reason?

    What about sending a light pulse down and easure the reflected intensity? then the pulse duration is unimportant. You only need to measure the average light intensity with and without the additional light (to eliminate daylight influence, if any).

    The intensity of the reflected light depends on the distance of the reflective surface from the light source. Ideally, you have a swimming object for the reflection, but it should work without it too (just with a worse S/N ratio because water is mostly transparent, especially on 90° angle)

    However, the cheapest way to get the info is to have two parallel wires in the pipe and a circuit that extracts the resistance between the two, which changes anti-proportionally with the amount of the wires under water level.

  • I will started with just a simple square wave pulse. If that doesnt work then I will have to go to a gated sine wave pulse. I do believe that my pulse duration is very important because then there is no way of telling what is being reflected or if I am just picking up transmission. Is there any way that you can maybe direct me to a previous thread on a similar topic that would fit this application. Thank you all very much for the fast replies.

  • As I said, a simple short pulse is easy to do.

    - set up a timer with a sufficient high clock. e.g. 1MHz (1µs). This gives you 200 timer ticks for your 5kHz (200µs) pulse. For a shorter pulse, you can use a higher clock.

    - set up the tiemr in cont mode.

    - set up one of the timers CCR units for set/reset mode and set its value to (65536-200). Enable the timer overflow interrupt.

    - set the timer register to something below the programmed CCR value (e.g. 65536-220).

    What happens now?

    The timer starts with 65536-220 and counts up with 1MHz.

    when it reaches 65536-200, it sets the output signal to high (set). And when it counts to 65536 (overflows to 0), it sets the output to 0 (reset). With the precision of the clock jitter and duty cycle, far better than 1µs.

    At the same time, the timer overflow ISR is called, so you know that the pulse has been sent, and can enable detection. And disable the pulse sending (e.g. set the output mode to OUTBIT static output.)

    For detection, you can attach the detector to another CCR unit, that will capture the moment of when the echo arrives. This units CCR register will then contain the timer value when the echo arrived, thus the delay in µs (add the 200 µs pulse duration, as you want a sendstart/receivestart time, not a sendend/receive start time).

    You can even let the thing running free. This way you'll get one resutl every 65ms (65536µs = 1 timer round). In this case, you don't need the tiemr overflow Interrupt, but only the capture interrupt that happens each time the echo is received.

    The same mechanism can be used if you have a transmitter that has self-modulation (and a self-demoldulating receiver), and you only gate it on/off by the pulse.

    If you use three CCR units (if the timer has three), you can even limit the timer length from 65536 to a smaller value, speeding up the measurement frequency.

  • JMG thank you for the info out aboveormative reply, I appreciate that a lot! I am currently working on this project as you layed out above. However where can I find the msp430.h files to import to my project, and the other .h files necessary to include in my program? Thank you very much.

  • The msp430.h files are part of the compiler. They should be in the default includ epath of your development environment.

    No other MSP specific files need to be included. Depending on your project settings, MSP430.h will pick the correct MSP430Fxxx.h file for you.

    The other .h files to include are just the generic C ones (e.g. strings.h or whatever you want to use from the C standard library) and should be in the default include path of your compiler too.
    What this default include path is,. depends on your compiler and your isntallation. Usually somewhere in your programs folder, in a subfolder of the compiler/IDE installaiton path.

**Attention** This is a public forum