Advanced running light.

Status
Not open for further replies.

ankitvirdi4

Member level 4
Joined
Mar 13, 2012
Messages
70
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Location
India
Visit site
Activity points
1,928
I am new to microcontrollers and I made a simple light chaser with a fixed inbuilt delay for running
My code is


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <htc.h>
#include "delay.h"
void main()
{
 
TRISC=0x00;
while(1)
{
PORTC=0b10000000;
DelayMs(500);
PORTC=0b01000000;
DelayMs(500);
PORTC=0b00100000;
DelayMs(500);
PORTC=0b00010000;
DelayMs(500);
PORTC=0b00001000;
DelayMs(500);
PORTC=0b00000100;
DelayMs(500);
PORTC=0b00000010;
DelayMs(500);
PORTC=0b00000001;
DelayMs(500);
}
}



I was wondering if I can control this delay externally? Using a potentiometer. I don't want to use an ADC because I am working with 16F505 which doesn't have one. Can somebody please suggest some other way? Using the timer perhaps? Please help.
 
Last edited by a moderator:

From what little I know in this area, ................


how many different delays do you want? If you want an "infinite" number I don't see any option but to use a pot and ADC. If only a few, then perhaps it could be done by setting the input ports - reading them and setting the delay accordingly. More than a few and this method becomes awkward and a pot with ADC becomes more attractive.
 

Well not infinite but that's kinda the general idea. I could still do will 10-12 levels I guess.
and Pot with ADC is PERFECT I know, what i also know is a guy has done it using a Pot which is connected to pin no 2 of pic16f505 which is RB5/OSC1/CLKIN as per the datasheet. When I change the pot value the speed of running varies. Any Idea how is he doing that? 16f505 doesn't have ADC i am pretty sure so he is using something else. Also the Pot is grounded through a capacitor 102 (10pf). You think he can be using a RC clock to give to the timer? Using the pot and the capacitor?
 

I was wondering if I can control this delay externally? Using a potentiometer. I don't want to use an ADC because I am working with 16F505 which doesn't have one. Can somebody please suggest some other way? Using the timer perhaps? Please help.

Absolutely.

Using a timer in conjunction with a timer interrupt would certainly allow you to change the delay during runtime.

Without access to an ADC, neither embedded nor external, the delay can be change by monitoring an external interrupt triggered by a switch/button closure.

One button to increase the delay, another to decrease the delay. Or commands could be issued via the UART connected to a PC.

There are several options.

BigDog
 

Can I do it using the external RC clock? By varying the Resister the frequency will change which will change the delay. You think this is possible?
 

Can I do it using the external RC clock? By varying the Resister the frequency will change which will change the delay. You think this is possible?

Yes, it is certainly possible.

Although, I think I would opt for implementing a simple oscillator using the pot which would drive the external timer clock (GP2/RC5/T0CK), rather the varying the system clock (RB5/OSC1/CLKIN).

Also, by using standard serial in/parallel out shift registers which can be cascaded you could control several times the number of LEDs in your original design.

The newly available I/O could then be used to change patterns or increase/decrease the speed, without the use of a pot.


BigDog
 

Also, by using standard serial in/parallel out shift registers which can be cascaded you could control several times the number of LEDs in your original design.

I am sorry I did not understand what you are trying to say here I would be grateful if you can elaborate.
Thank you.
 

Also, by using standard serial in/parallel out shift registers which can be cascaded you could control several times the number of LEDs in your original design.

If you wanted to add more LEDs, then one way to do that is by using SHIFT REGISTERS (google it).
 

I am sorry I did not understand what you are trying to say here I would be grateful if you can elaborate.

The 74HC595, a serial in/parallel out shift register can be employed to increase the number of available output pins for a project such as yours.

In fact several 74HC595 can be easily cascaded by connecting the QH line of the first 74HC595 to the SER of the second 74HC595, and so on.

Using this technique several 74HC595 can be cascaded while only requiring three lines from the microcontroller.

The 74HC595 is equipped with a storage register and 3-state outputs, the storage register is controller by Register Clock (RCLK) or Storage Register Clock Input (SCTP) line, depending on the manufacturer.

While a new state value is being shifted into the device the RCLK/SCTP is held low, once the new state value is in position the RCLK/SCTP line is pulled high storing the new value state with the storage register.

The Master Reset (MR) or Storage Register Clear (SRCLR) line, once again depending on the manufacturer, can also be utilized to initialization the device into a known cleared state.



The following tutorial demonstrates many of the features of the 74HC595, although the tutorial employs an Arduino, the techniques can be easily ported to any microcontroller.

Can you move over? The 74HC595 8 bit shift register

A AVR centric tutorial controlling 16 LEDs using only three pins of a ATmega8:

Introduction to 74HC595 shift register – Controlling 16 LEDs

There are numerous threads in the forum concerning this topic, just search for 74HC595.

Questions bout shiftregisters (74HC575, 74HC597)




TI SN54HC595/SN74HC595 Datasheet


BigDog
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…