Shop OBEX P1 Docs P2 Docs Learn Events
LED bargraph with max7219 based on rpm/speed input — Parallax Forums

LED bargraph with max7219 based on rpm/speed input

chetw77cruiserchetw77cruiser Posts: 12
edited 2012-01-22 15:47 in Propeller 1
Well, this looks to be my first post here, so I will start off easy. I have been working some on a digital instrument sluster and I have a programmers cramp. I want to be able to input a max rpm variable, divide that by 40(number of leds attached to a max7219) and lite individual leds based on rpm*1, rpm*2, etc. mainly in that order. I am trying the if-else if with little success. I am stumped. I want to be able to enter anyrhing from 4000 rpm to 8000 rpm and be able to divide that between 40 leds, maybe more if needed. Would the lookup/lookdown be a better way?

If this is to little information, let me know and I will fill in the blanks.

Chet W.

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-01-14 20:40
    This may need adjustment depending on when you want the first LED to be on. I assume you are after an increasing LED bar starting at 4000 up to 8000.

    (rpm - rpmmin) / (rpmmax - rpmmin) = n / number_of_LEDs

    with numbers:

    (rpm - 4000) / (8000 - 4000) = n / 40

    or

    n = (rpm - 4000) / 100

    For rpm = 4000 this gives you n = 0 (no LED), rpm = 8000 will result in n = 40 (all LEDs). HTH
  • chetw77cruiserchetw77cruiser Posts: 12
    edited 2012-01-14 20:51
    That does help, thank you. I am after the increasing led bar but starting at 0 and work up to what ever the max rpm setting is. Sometime after I get this figured out, I might even try to code this for a moving dot instead of bar, but first things first.

    I am not sure how to code that and have it output to the max7219. I forgot to mention that I am using spin and I only have a basic knowledge of programing in general, mainly from 15 years ago using qbasic. I am using this project as a learing experience.
  • kuronekokuroneko Posts: 3,623
    edited 2012-01-14 20:59
    Can't help you with that chip in particular (more of a s/w guy). Have a look at [thread=136470]this thread[/thread]. During the w/e the forum is rather slow going but I'm sure others will chime in sooner or later.

    How do you get the RPM into your system? Also, if your min/max values are different simply substitute them in the equation.
  • chetw77cruiserchetw77cruiser Posts: 12
    edited 2012-01-15 21:11
    Right now I am using the jm_freq object to get the rpm signal and then converting to a useable figure. Here is my code so far. I will most likely be changing to a different way though, so this is not set in stone.
    con
    
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    
    
      #0, CLS, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR ' PST formmatting control 
      'cyl4 = 30
      'cyl6 = 20
      'cyl8 = 15
      tachin = 2
    
    var
      long rpm,cylsel,redline   
    obj
    
    fc   : "jm_freqin" 
    term : "jm_txserial"
    
    
    pub main | f
    cylsel := 8
    redline := 4500
    fc.init(tachin) ' freq cntr on p0
    
    term.init(30, 115_200) ' start terminal
    waitcnt(clkfreq/10 + cnt)
    term.tx(CLS)
    
    repeat
      f := fc.freq ' get frequency
      if cylsel := 4
        rpm := (f*30/10)
      if cylsel := 6
        rpm := (f*20/10)
      if cylsel := 8
        rpm := (f*15/10)
      term.str(string(HOME, "revs: "))
      
      'rpm := (f*30/10)
      term.dec(rpm) ' print whole part, 30 constant is for 4-cylinder, four-stroke ICE.
      term.str(string(" rpm", CLREOL))
      if rpm > redline
        term.str(string("WARNING"))
      waitcnt(clkfreq/15 + cnt)
    
  • chetw77cruiserchetw77cruiser Posts: 12
    edited 2012-01-15 21:40
    After trying multiple ideas, I think that the max7219 is not the best for what I want to do. Whith that in mond, what about using the MM5451 led controller. Basically a large shift register. Any pointers on using this chip?
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-01-16 10:46
    Looks like the 7219 is also just fine. There are, however, 8 registers to write. So, you would fill your two LONGs with the bit pattern for the bar graph. Then, write "(1 << 8) + bottom byte" then "(2 << 8) + second-to-bottom byte" and so on and so forth.
  • chetw77cruiserchetw77cruiser Posts: 12
    edited 2012-01-16 11:41
    I goofed and posted the wrong code segment. Here is the correct one.
    con
    
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    
    
      #0, CLS, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR ' PST formmatting control 
      'cyl4 = 30
      'cyl6 = 20
      'cyl8 = 15
      tachin = 2
    
    var
      long rpm,cylsel,redline   
    obj
    
    fc   : "jm_freqin" 
    term : "jm_txserial"
    
    
    pub main | f
    cylsel := 8
    redline := 4500
    fc.init(tachin) ' freq cntr on p0
    
    term.init(30, 115_200) ' start terminal
    waitcnt(clkfreq/10 + cnt)
    term.tx(CLS)
    
    repeat
      f := fc.freq ' get frequency
      if cylsel := 4
        rpm := (f*30/10)
      if cylsel := 6
        rpm := (f*20/10)
      if cylsel := 8
        rpm := (f*15/10)
      term.str(string(HOME, "revs: "))
      
      'rpm := (f*30/10)
      term.dec(rpm) ' print whole part, 30 constant is for 4-cylinder, four-stroke ICE.
      term.str(string(" rpm", CLREOL))
      if rpm > redline
        term.str(string("WARNING"))
      waitcnt(clkfreq/15 + cnt)
    
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-01-22 15:47
    The MM5451 looks like it would be better suited to this task since you're not using groups segments. In this case you could divide max RPM by number of segments and then shift this many bits into your control variable. If I had one of these handy I could whip up something.
Sign In or Register to comment.