Shop OBEX P1 Docs P2 Docs Learn Events
Intro and advice on LED bar graph RPM meter — Parallax Forums

Intro and advice on LED bar graph RPM meter

hoff70hoff70 Posts: 7
edited 2013-03-06 20:54 in Propeller 1
Hi,

I've always been interested in tinkering with electronics and have been fooling with some projects off and on for a couple of years. Mainly just repairing stuff by soldering in new components and a little breadboarding. I find it very rewarding even with my limited experience! Anyway, I decided to devote some space into a little "lab" for keeping my growing pile of stuff and tinkering around.

I recently picked up an Arduino UNO and a Prop and it's been fun tinkering with them but my computer code chops = ZERO! I've been bouncing between the UNO and Prop and I haven't really settled on a platform yet. I suppose I need to stick with one at least until I get some basics down...

This is my latest project:

temporary-173.jpg

Probably pretty simple for most folks here but I'm a bit flummoxed.

The breadboards and associated crapola is just a test platform that spins a disc which breaks an IR beam, plus a rig to vary the motor RPM. The trigger is running to an input on the UNO which prints 1 or 0 to the serial monitor and blinks an LED when the beam is broken. I figured it was a good/simple place to start.

The LED setup is (Hopefully) going to be a simple tachometer with the LED's lighting up from green to red as the RPM increases.

Any help would be greatly appreciated! Maybe it's overkill using a Prop for such a simple task but I also have some more tasks for it if I can get this working. I realize that each LED will require it's own pin, plus some resistors or voltage regulation, etc. and I understand the logic behind what I'm trying to do but I don't know how to tell the machine what to do.

I have a trial version of 12 blocks which looks like an IDEAL solution to some of my problems but documentation is lacking.

Thanks in advance!

Oh yea, I plan on using a hall effect sensor for the final product but they are on order. I got the IR setup from RS because I figured the input would be about the same. I would like to have it mostly worked out by the time they arrive.

Comments

  • SarielSariel Posts: 182
    edited 2012-05-15 12:09
    Welcome to the wonderful world of the Prop, and the many guru's you will encounter on the way.

    First off, if you have any code for the prop, best way to get a hand is to share how far you are to this point. It goes a long way in getting some advice.

    The way I would tackle something like this is using one of the fine PWM objects in the Obex, and get to the point where you are storing your RPM as a variable. I have had good luck with Dave Fletcher's Frequency meter in measuring the PWM signals from computer fans.

    Lighting the "bargraph" LED's can be as simple as:
    CON
      CON1 = 10     'Constant for RPM level 1      
      CON1 = 20     'Constant for RPM level 2
      CON1 = 30     'Constant for RPM level 3
      CON1 = 40     'Constant for RPM level 4
      CON1 = 50     'Constant for RPM level 5
      CON1 = 60     'Constant for RPM level 6
      CON1 = 70     'Constant for RPM level 7
      CON1 = 80     'Constant for RPM level 8
      CON1 = 90     'Constant for RPM level 9
      LED1 = 0      ' LED output connections
      LED2 = 1
      LED3 = 2
      LED4 = 3
      LED5 = 4
      LED6 = 5
      LED7 = 6
      LED8 = 7
      LED9 = 8 
     
    PUB OutLED[RPMVar]
    '' Method for illuminating LED's based upon RPM constants
      if RPMVar > CON1
        outa[LED1]    
      if RPMVar > CON2
        outa[LED2]
      if RPMVar > CON3
        outa[LED3]
      if RPMVar > CON4
        outa[LED4]  
      if RPMVar > CON5
        outa[LED5]
      if RPMVar > CON6
        outa[LED6]
      if RPMVar > CON7
        outa[LED7]
      if RPMVar > CON8
        outa[LED8]
      if RPMVar > CON9
        outa[LED9]
    


    Of course you would have to add in a way to shut the LED's off when the RPM drops below a certain level... and of course there are many (and obviously better) ways of doing this with less lines of code, but this should give you the basic idea, and introduce a few concepts to you like using constants to make your life easier in calibrating your device, etc.


    Good luck, and have some fun!
  • ratronicratronic Posts: 1,451
    edited 2012-05-15 13:28
    hoff70 here is one example how to use the nine led's as a bargraph when they are properly connected to P0 - P8 but could be modified to use any sequential 9 port pins. "a" would need to be scaled down from whatever you are measuring to a value between 0 - 8 to light that particular led in the bargraph.
    Con   
                                                          
                                                             
      _CLKMODE = XTAL1 + PLL16X                              
      _XINFREQ = 5_000_000 
     
      
    Var
    
     
      long a
    
                      
    Obj  
             
                                               
                       
    Pub main
    
      'set these at the start of your program
      outa[0..8]~   'set P0 thru P8 outputs as low 
      dira[0..8]~~  'set P0 thru P8 direction register as high (output)
    
    
    
      
     'set "a" before running the next three instructions any where in your program
     ' "a" := 0 thru 8 will only light that led in the bargraph
    
      a := 0 #> a <# 8   'limit "a" to 0 thru 8
      outa[0..8]~        'set all led outputs off (low)    
      outa[a] := 1       'set "a" led in bargraph on
    
  • hoff70hoff70 Posts: 7
    edited 2012-05-15 13:49
    Wow! thanks for the help! I'll have to fish through the code you kind folks posted and see what's up. I really need a good beginner text for programming the prop.

    Here's where I'm at now:

    temporary-174.jpg

    Since I have a quickstart I'm running pins 1,3,5,7, etc. It appears as if I'd be better off getting the led's on sequential pins as suggested.

    I'm pretty stoked about putting some fire to this thing!
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2012-05-15 14:03
    If you want a large number of LED's for your bargraph display you can easily cascade four 74HC595 chips which will give you 36 outputs using only 3 microcontroller lines. You can use more than 4 of them but many of the objects are already written to support up to 4.

    Robert
  • JonnyMacJonnyMac Posts: 9,191
    edited 2012-05-15 14:30
    dira[0..8] := 1         'set P0 thru P8 direction register as output
    


    Note: This line of code only sets P8 to output mode. You need to modify it to this:
    dira[0..8] := %1_1111_1111
    


    So long as you're using contiguous pins you can simplify your code with this method -- it takes the MSB and LSB pin numbers, as well as the number of elements lit.
    pub set_graph(msb, lsb, nlit) | bits
    
      outa[msb..lsb] := $1FF >> (9 - nlit)
      dira[msb..lsb] := $1FF
    
  • ratronicratronic Posts: 1,451
    edited 2012-05-15 14:50
    Thanks Jon!

    Edit: hoff70 you could also use outa or dira[0..8]~ to clear all bits or dira[0..8]~~ to set all bits
  • hoff70hoff70 Posts: 7
    edited 2012-05-15 16:32
    Slight information overload guyt, but thanks! I really need to dive into writing some real code and learning more about it. Using outputs to control other IC's sounds really neat and possibly useful in the future but I have a ways to go.

    I did get this far today:

    It's really crude though. Just turning pins off/on with some delay but it does help me see what's going on. I didn't anticipate the delay causing the blinking action (duh...) But at least I have some hardware set up to fool with.
  • ratronicratronic Posts: 1,451
    edited 2012-05-15 16:37
    Very good hoff70!
  • ratronicratronic Posts: 1,451
    edited 2012-05-16 08:51
    hoff70 I have to apoligize for posting some code with an error in it yesterday. I broke one of my own rules - test everything before I post! The code I had originally posted has been replaced with tested code with better explainations. Also try Jon's code it will lite all led's to the measure point as mine only lites a single led at the measure point. If you have any questions about something you are stuck on do not hesitate to ask.
  • hoff70hoff70 Posts: 7
    edited 2012-05-16 20:35
    No problem. I'm still tinkering with the hardware a bit:

    My goal is to get some input from the IR setup over the weekend and get the LED's to do something. My IR setup is a bit hit or miss with some off or on doubling.

    The serial port will occasionally throw a 101010001 or 101010111... I'm going to fool with the slotted disc some more to try smoothing things out. Maybe it's not "fast" enough? It works well on slow speeds but gets wonky when I turn up the RPM.

    Hopefully the HE sensor will be a better trigger but it could be another can-O-worms!

    I do have the LED's set up on 0-9 so that should simplify things.

    Yea, I need to clean the bench!
  • hoff70hoff70 Posts: 7
    edited 2012-05-19 16:11
    I'm still plugging along. I figured I'd redux the IR test rig:

    temporary-175.jpg

    It's an Arduino running a PWM program so I can vary the motor speed. I also tried to do a better job "shielding" the IR emitter by using a metal disc. (Had to finish a jar of olives, and that required a bottle of wine... The price we pay...)

    Anyway, I managed to get the signal from the IR detector to the Prop by using the "Count edges" block. Now it registers on the "Pin states" screen each time the beam shines through the hole. I actually consider this a breakthrough! Pun intended...

    I've been fooling with it about all day. I'm leaning towards the "Count edges" block in 12 Blocks because it can be set to count over a value. 60000 = 1 minute so that would give me my RPM. I think...but I'm a bit stumped now.

    I still haven't managed to get the input over to any kind of output but I'm working on it. Thanks for the code examples! I'm beginning to get some fuzzy ideas about what's going on.

    I think i may benefit from either a pull-up, or pull-down, resistor on the pin that's reading. Any input?
    _CLKMODE = XTAL1 + PLL16X                                _XINFREQ = 5_000_000 
     
      
    Var
    
    
     
      long a
    
    
                      
    Obj  
             
                                               
                       
    Pub main
    
    
      'set these at the start of your program
      outa[0..8] ~   'set P0 thru P8 outputs as low 
      dira[0..8] ~~  'set P0 thru P8 direction register as high (output)
      
      repeat                    
        dira[0..8] ~~ 
        waitcnt(clkfreq + cnt)
        outa[0..8]  ~
            waitcnt(clkfreq + cnt)
    

    I've been fooling with the code posted but still no huzzah.

    well, I met my goal for the weekend! The LED's don't reflect RPM other than blinking slower/faster with the disc speed but it's a start

    I actually did this fumbling around with 12 Blocks..
  • AdyenAdyen Posts: 7
    edited 2013-03-06 10:14
    Hello all.....
    I am Jhone from USA .I am new here with name as jaleb. I love to work with LED lighting. You have shared a good information, i am here to find out the solutions of problems face day by day. I hope you guys will help me out.
  • kwinnkwinn Posts: 8,697
    edited 2013-03-06 20:54
    Adyen wrote: »
    Hello all.....
    I am Jhone from USA .I am new here with name as jaleb. I love to work with LED lighting. You have shared a good information, i am here to find out the solutions of problems face day by day. I hope you guys will help me out.

    Welcome to the forums. You will get lots of help with your questions here. Just try to post as much information (along with code and schematics if possible) along with the questions.
Sign In or Register to comment.