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.

Using the EK-LM4F120XL to make a square wave on a GPIO pin

Thanks for taking the time to read this.

First off I have little to no experience with this chip. I just got this dev board in the mail the other day and I haven't programmed with an ARM processor before. I have some of the basics down of blinking some LEDs, but I am not very comfortable with it yet. Right now I am just trying to figure out how to send a square wave out of one of the pins on the board. 

Can anyone send me somewhere to figure this out? Or maybe just post some simple code for me to run and play with?

With regards,

Tom 

  • One of the easiest means to do this is via an MCU Timer - configured to "PWM" Mode.  This will provide you full control of: both frequency and duty cycle - and is nicely explained (and code detailed) w/in your MCUs data sheet.  (Timer chapter)

    Suggest that you stick w/StellarisWare (avoiding urge to "direct register write") - there are interesting code examples w/in the examples folder w/in StellarisWare.

    Avoid use of Port_C in your beginning stages - you must review your board to find which Timer pin is routed to the edge connector - for your easy monitoring or outside world usage.  (suspect that many Timer pins meet this qualification)

    Once you get this simple PWM working - beneficial to review general GPIO Chapter - especially StellarisWare's "rather unique" use of data qualifier mask - which impacts writing to the GPIO...

  • When you blink a LED, you are sending a square wave out of one of the pins. So you have already done what you wanted.

  • Thanks for the help!

    I was able to figure out how to send out a square wave out of a pin. I actually was doing it right the first time I had tried it, but my oscilloscope was not working properly at the time, so I couldn't read the wave properly... well actually I couldn't read it at all. I am currently just writing to the pin 0xff, then delaying, then clearing it, then delaying to get the wave.

    I have another question. How can I increase or decrease the voltage of the wave? 

  • Square wave is not "much" of a wave - and unless you add additional components - there's nothing you can do to alter the voltage.  Most any MCU will drive a GPIO pin to near its supply value (when high) or near to ground (when low).  If you're really interested - rear of MCU datasheet details signal levels under both high and low output conditions.

    Anticipating such requirement - I referenced a PWM method - which can then be easily R-C filtered - and can yield reasonably steady/stable DC voltage pretty much between the positive supply and ground.  By increasing the duty cycle (on-time) your voltage will approach the positive supply - decreasing duty will drive that voltage to ground. 

  • Thomas Stortz said:
    First off I have little to no experience with this chip ... I haven't programmed with an ARM processor before

    Do you have any experience with microcontrollers at all?

    Do you understand basic electronics - particularly, digital electronics?

    Can anyone send me somewhere to figure this out?

    There's some useful books & links here: http://www.keil.com/books/ - not (all) specific to Keil

    For the basic electronics, you could start here: http://www.kpsec.freeuk.com/

    Thomas Stortz said:
    How can I increase or decrease the voltage of the wave? 

    The GPIO ports are digital signals.

    A digital signal has only two states - "On" and "Off" or "High" and "Low" - they don't have variable amplitude.

    You would have to add external circuitry to adjust the amplitude from a GPIO pin; eg, see http://www.kpsec.freeuk.com/trancirc.htm

    Alternatively, use an analogue output - or PWM, as previously mentioned...

  • Andy Neil said:
    Alternatively, use an analogue output

    Not too likely w/this vendor's current M4s - and always such DACs are welcome additions...

  • I do have some basic knowledge of a couple processors like some basic 8051's, but I haven't worked with ARM. 

    Yes, I do have some basic understanding of digital electronics. I am a student studying Computer Engineering. (This sounds like I am talking back in a bad way, but I am just providing info about myself)

    I have worked with Keil before on some of the 8051s.

    In terms of the output for the GPIO. I was mainly asking to see if I can change the voltage level that it is sending out. Say right now the pin is sending out a square wave at 3.3V, but could I change that to say 1.5V. I wasn't sure if that was even possible on this board, without having to do something off board.

    Thanks for all the help and input everyone! 

  • Simple voltage divider (2 Rs) can drop 3V3 (signal high) to anything you wish. 

    There are also "level shifter" ICs which can manage multiple channels - and both reduce or raise the level of the signal highs.  (to raise - requires an additional power supply level)

    3V3 has become quite a standard - interfaces widely - you may wish to address why you seek to vary from this standard...

  • The project I am working on is making the EK-LM3F120XL into something that simulates a bunch of signals. Everything can be a digital signal, but I may need to vary the voltages on some of them. One thing is that I also need to be able to do is vary some of the signals frequencies based off of an input that I receive, but that should all be done in my coding.

  • I think I am just going to replicate these signals using SSI or as I know it SPI. I was looking through the StellarisWare and couldn't find any good examples of SSI communication. Can anyone point me in the direction of an example? I have been reading a bit through the data sheet and the library in SSI, but I would just like to look at a good example.

    Once again thanks for all of the help so far. I really appreciate it. 

  • Thomas Stortz said:
    I think I am just going to replicate these signals using SSI

    Really - you do realize that SSI provides a clock, a single data output, and a wider chip select.  And - to add to your woes - the frequency output is more difficult to adjust and is unlikely to have the ease, flexibility and range of "normal/customary" GPIO.  You've repeated your goal of "signals" - you'll get just one from your SSI channel.

    Have a read of the SSI chapters in your MCU datasheet & SW-DRL-UGxxxx.  SSI on any ARM (not just vendor's) is complex/demanding - seems to this reporter that you've added complexity while drastically shrinking the number of output signals. 

    StellarisWare\examples\peripherals has at least 3 SSI code examples.   Your ability to tweak both investigation & decision-making will serve you well when you enter the job market...

  • Well instead of pointing out what I am doing wrong, would you like to give some advice? Other than saying that I'm choosing the wrong method.

    I know earlier I was wanting to send signals as square waves and I was looking at changing the voltages of those waves. But now I can just send out a value (data) that represents the square wave.

    I currently need to replicate 8 signals. These signals can be 10-bits and no larger. This would make the signal have a very high resolution. So then on the receiving end, there can just be a look up table. Like if its within this ranges its going to be this value.

    I was thinking that SSI (which from my understanding is like SPI) could be a solution for this. 

    cb1- said:
    Your ability to tweak both investigation & decision-making will serve you well when you enter the job market...

    As far as this comment, I already have a job, and this whole thing of posting on a forum for help is my "Investigation and Decision-making"

  • Thomas Stortz said:
    would you like to give some advice?

    My friend - don't you mean some more advice?  Here - for the record - is a quick review of my efforts - your behalf...

    *   via an MCU Timer - configured to "PWM" Mode
    *   Avoid use of Port_C in your beginning stages
    *   Referenced a PWM method - which can then be easily R-C filtered - and can yield reasonably steady/stable DC voltage
    *   By increasing the duty cycle (on-time) your voltage will approach the positive supply - decreasing duty will drive that voltage to ground.
    *   Simple voltage divider (2 Rs) can drop 3V3 (signal high)

    We note that - while you ask for still more - "facts in evidence" show a bulk of output - and your response to each/every has been ZERO!

    Beyond this - it's likely I've been in this field bit longer - and often my group tries to prevent those, "about to fly off the rails." 

    Being coachable is an important skill - any unbiased reading reveals I've done my part - and we should consider adding "factuality" to the earlier, "short-list..."

  • Thomas Stortz said:

    ...  But now I can just send out a value (data) that represents the square wave.

    I currently need to replicate 8 signals. These signals can be 10-bits and no larger. This would make the signal have a very high resolution. So then on the receiving end, there can just be a look up table. Like if its within this ranges its going to be this value.

    I was thinking that SSI (which from my understanding is like SPI) could be a solution for this. ...

    Not sure what exactly you mean.

    You have eight input signals on 8 separate wires. Each one can be either high or low at any instance. Correct?

    You want to represent the period of time between the high and the low as a number with 10-bit resolution and send that number out. Correct?

    If so, you need to measure those periods of time with 10-bit precision. It may be possible to do so with a timer. And you can use SSI, I2C, UART, USB, etc. to send the resulting number out.

  • I'll try to explain a little more. 

    One of the 8 signals that I am replicate is a temperature probe. It doesn't literally need to send the same signal out. Because it is varying in voltage and I have been told I can't vary the voltage without changing things physically. So what I was thinking of doing is just sending out a 10-bit value to the chip that is receiving the signal. The chip receiving the signal then can just do a look up chart to figure out what the value would have been from the real temp. prob. that is being simulated.

    Now I am creating this just for a simulation. I'm not really in charge of the other chip I am talking to, but I can decide if it needs to just do a look up of the value I am sending it.

    As far as 8 separate wires, I was thinking I could just send the data for each signal I want to replicate over the SSI and just have a "header" byte or something to differ what data I am sending to the other chip.

    I hope this makes more sense on what I am trying to accomplish. Let me know if I need to explain a little more. 

  • Sorry. I am really confused now.

    To replicate a signal with varying voltage, one can simply use an Operational Amplifier with gain of 1. Using a microprocessor that has both ADC and DAC is also possible. But this like instead of use a copy machine to make a copy, one uses a digital scanner to scan the original and uses a printer to print the scanned image.

    The M4F has no value of doing any of the above.

  • I understand it's a little confusing. Thanks for trying.

    When I say replicate or simulate, I am using the board to create values in place of these signals. Like the temperature probe. I cannot physically connect to the probe itself. So I am going to simulate it with this M4F (mainly cause its the only thing I have available). But I don't exactly have to simulate a square wave or specific voltages. I can just send data that represents those waves or voltages. Then the chip on the receiving end can just look up what I am sending it in a table. Then it can use the value in the table, which should correspond to the square wave or voltage value I am trying to send it.
     

  •  a little confusing...

    Mideast Peace - Nuclear-Tipped Warheads - Hydrogen Fuel Cells... all pale in complexity...

    We have responded - clearly and in multiple - to your original Request, "How to make a square wave..." 

    And the cheese moved - and is yet unstable...

    Perhaps the "boss, client, advisor" - with bit more focused knowledge/experience - can further assist...

  • cb1_mobile said:
    We have responded - clearly and in multiple - to your original Request, "How to make a square wave..."

    I guess a post can't stray from its original subject line in this forum?

     

  • Thomas Stortz said:
    I guess a post can't stray

    Such "stray" is like arguing that South America drifted only "slightly" - from its earlier African attachment.

    Better focus, planning will reap great benefits for you.  (and it may not be unkind - after trying to assist - to point this out...)

  • cb1_mobile said:

    I guess a post can't stray

    Such "stray" is like arguing that South America drifted only "slightly" - from its earlier African attachment.

    Better focus, planning will reap great benefits for you.  (and it may not be unkind - after trying to assist - to point this out...)

    [/quote]

    Ok, I'll take that as a no. I'll go elsewhere for better advice and mentoring. Which probably would mean anywhere else.

    Thanks for all the help guys!