Shop OBEX P1 Docs P2 Docs Learn Events
Display System Counter — Parallax Forums

Display System Counter

HumanoidoHumanoido Posts: 5,770
edited 2010-09-10 22:34 in Propeller 1
How to get the Time variable into the A register and output the result in binary to LEDs 0 - 31? The following code is not working.
' Read system counter and display the binary result
' LEDs on pins 0 through 31

CON     
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

VAR 
  long  Time 

PUB ReadCNT
  Time := cnt         'Read System Counter 32 bit number

PUB LED
  DIRA := %11111111111111111111111111111111    ' make pins 0-31 outputs
  OUTA := Time

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-09-10 19:49
    How do you call this code? Then again, assuming it's a top level object, only the first PUB method is executed. Does that answer your question?
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-10 20:02
    This? Still not working..
    VAR 
      long  Time 
    
    PUB ReadCNT
      Time := cnt         'Read System Counter 32 bit number
      DIRA := %11111111111111111111111111111111    ' make pins 0-31 outputs
      OUTA := Time
    
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-10 20:06
    You have to keep the cog alive, otherwise the SPIN interpreter just exits. Use either repeat or waitpne(0, 0, 0).

    And you are allowed to assign cnt directly to outa :)
  • yarisboyyarisboy Posts: 245
    edited 2010-09-10 20:08
    If you have 31 leds hooked directly to propeller outputs its unlikely they would light up. If each LED needs 20 ma that would be 20*32= 640 ma. I had this oversight on a BS2 project.
    On the BS2 I could only light four LEDs before they browned out on me. I had to come up with a driver scheme to whip the current-budget problem. Harprit Sandhu used invertors and inverted logic in spin to overcome this in his new book.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-10 20:12
    Kuroneko, thank you! That works perfect.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-10 20:26
    yarisboy wrote: »
    If you have 31 leds hooked directly to propeller outputs its unlikely they would light up. If each LED needs 20 ma that would be 20*32= 640 ma. I had this oversight on a BS2 project.
    On the BS2 I could only light four LEDs before they browned out on me. I had to come up with a driver scheme to whip the current-budget problem. Harprit Sandhu used invertors and inverted logic in spin to overcome this in his new book.
    Yarisboy, you are correct. Those brownout detectors can be a real nuisance sometimes. However, to overcome this problem, I upped the dropping resistors from 100 ohms to 220 ohms and boosted the voltage, keeping it just under 4-volts, the max recommended in the prop data sheet. This results in 32 LEDs simultaneously on, drawing 224 to 227mA around 7mA each. The max current draw must be limited to 330mA according to specs so this system works well. No inverter or special software is needed.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-10 22:15
    The maximum current for Vdd or Vss is 300mA according to my datasheet copy and remember that the Prop itself uses some current. I figure about 5mA per active cog plus maybe 2mA for the system clock. That's still just under the absolute maximum.

    Keep in mind that stressing the chip to near its limits may not result in immediate damage to the chip, but it may shorten the time to failure from other processes like metal migration that are current and heat sensitive.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-09-10 22:34
    Mike Green wrote: »
    The maximum current for Vdd or Vss is 300mA according to my datasheet copy and remember that the Prop itself uses some current. I figure about 5mA per active cog plus maybe 2mA for the system clock. That's still just under the absolute maximum.

    Keep in mind that stressing the chip to near its limits may not result in immediate damage to the chip, but it may shorten the time to failure from other processes like metal migration that are current and heat sensitive.
    Thanks Mike. I will immediately go with the quoted max current value of 300 mA and take into consideration the current draw from the cog(s) and system clock - and back off the voltage by not lighting all LEDs at the same time.
Sign In or Register to comment.