PDA

View Full Version : Multiple LEDs and Time Coount



LexManos
- 22nd July 2009, 12:30
I have two questions both unrelated to eachother.
First off I am trying to figure out how I would go about doing something like this: http://www.youtube.com/watch?v=4Hh9FJUTVXU

The catch is, I want this to be controled by as few Pins from a 16f684 as I can (1 if possible). Basically it's going to be a percentage indicator, 10 leds, 0-9% = no lights 10-19% is 1st LED, 20-29% is both 1st and 2nd led, etc...

Next question should be simple, I'm wanting to receive input on multiple pins. As they are PWM IR beams, it's all time based.
Basically, I was thinking:

StartTime, Delay
StartTime = Now
Loop
Delay = Now - StartTime
StartTime = Now
If(Pin1 = High) Then Pin1Count += Delay
If(Pin2 = High) Then Pin2Count += Delay
End LoopPretty straight forward in any other But as I'm completely green to PicBasic, Is there anything like a counter that would give an accurate relative time count in nanoseconds.
Also, my other concern is the actual time delay between each of the comparrisions and increments. I haven't done any of the math on this because as I've said, i'm new to the world of microcontroler programming. I've usually done higher level coding. It needs to be accurate to within like, 50ns (it's pretty straight forward, 600ns pulse is 0, 1200ns pulse is 1, separated by a 600ns low)


Anyways, thats the jist of what i'm trying to do, no flaming me please, if im insane simply tell me.

Archangel
- 22nd July 2009, 17:51
Hello LexManos,
Welcome to the forum !
We usually don't even flame spammers, only arrogant, unappreciative little turds :D I will take a swing at the first request. I think I would use a PWM output feeding an LM3914 / LM3915 to control the LEDs, only 1 pin on the PIC.
Regarding the second request: The ir beams you are decoding, are they constantly on, are they different, does the data on each change,and is there a priority of 1 over any other, or a priority hierarchy? Check out BRUCE's website here: http://www.rentron.com

LexManos
- 24th July 2009, 03:40
I think I would use a PWM output feeding an LM3914 / LM3915 to control the LEDs, only 1 pin on the PIC.Was kinda hoping that i wouldn't need anything to fancy. But, thats not that big of a deal. I can worry about it later, lower on the priority.


Regarding the second request: The ir beams you are decoding, are they constantly on, are they different, does the data on each change,and is there a priority of 1 over any other, or a priority hierarchy? Check out BRUCE's website here: http://www.rentron.comNo, they are not always on, the data that would be transfered over them are different. But the format is the same [(byte)ID, (Word) Data] No priority hierarchy they will all be the same.

This is a vary basic setup we built LED hooked up to PORTA5, TSOP4840 (http://mouser.com/Search/ProductDetail.aspx?R=TSOP4840virtualkey61370000vir tualkey782-TSOP4840) data pin hooked up to PORTC1


TRISA = %00000000
TRISC = %11111111

High PORTA.5

loop:
if (PORTC.1 = 1) then
test:
LOW PORTA.5
pause 1000
high PORTA.5
pause 1000
goto test
Endif
goto loop

end

Pretty obvious what we want it to do to test, but, the LED stays solid, no flashing :/

mackrackit
- 24th July 2009, 04:19
http://www.picbasic.co.uk/forum/showthread.php?t=561
Do not let the thread title fool you, your PIC has analog on PORTC also.
Try a non analog pin or turn the ADC off and see what happens.

Archangel
- 24th July 2009, 06:36
http://www.picbasic.co.uk/forum/showthread.php?t=561
Do not let the thread title fool you, your PIC has analog on PORTC also.
Try a non analog pin or turn the ADC off and see what happens.Data sheet sec4.1 . . . ANSEL and CMCON registers MUST be initialized to configure an analog channel as a digital input. Pins configured as analog inputs will read "0" .
You have these registers to contend with:
ADCON
ADCON1
ANSEL
CMCON0
CMCON1