Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

i want to make 12 led chaser

Status
Not open for further replies.

jayanath

New Member
Dear,Ian Rogers
I have gone through tutorials but the fading of led cannot done. pls help me to make it from c codes. i want to make 12 led chaser with comet tail effect for any suitable pic.(followed led to be faded off0 request circuit instructions also.thank you any body to help me?
 
For comet tail effect, you're going to need PWM of some sort.... A reasonable output should be achieved by setting up a software PWM.

Four should be enough.... 8 led's on normal and 4 with decreasing brightness... Then some fast pin swapping...

Make it with one at first.... Then once its working try two.....and so on...

Obviously it would be better for each LED to have a PWM of its own... BUT I have only seen eight PWM's on one chip and they are paired... so 4 different PWM's
 
im using PIC16f877a . with this pls explain bit more regarding PWM. im a beginner for this but i can make the circuit and write c code with suitable delays. tnx
 
I wrote a simple example code. It is a naive code, but works well if you do not have any other things (heavy computing) that the uC needs to do.

C:
/* Counter for PWM */
unsigned char counter;

/* The initial values define the brightnes of the LED,
   0 is "led off" and 255 is "full brightnes". */
unsigned char led_pwm[] = {0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220};

void main(void)
{
	/* Initialize LED pins as output */
	   //.. omitted
	
	/* Infinite loop */
	while(1)
	{
		/* Increment counter */
		counter++;
		
		/* Switch LEDS ON/OFF */
		(led_pwm[0] < counter) ? LED_0_OFF : LED_0_OFF;
		(led_pwm[1] < counter) ? LED_1_OFF : LED_1_OFF;
		(led_pwm[2] < counter) ? LED_2_OFF : LED_2_OFF;
		(led_pwm[3] < counter) ? LED_3_OFF : LED_3_OFF;
		(led_pwm[4] < counter) ? LED_4_OFF : LED_4_OFF;
		(led_pwm[5] < counter) ? LED_5_OFF : LED_5_OFF;
		(led_pwm[6] < counter) ? LED_6_OFF : LED_6_OFF;
		(led_pwm[7] < counter) ? LED_7_OFF : LED_7_OFF;
		(led_pwm[8] < counter) ? LED_8_OFF : LED_8_OFF;
		(led_pwm[9] < counter) ? LED_9_OFF : LED_9_OFF;
		(led_pwm[10] < counter) ? LED_10_OFF : LED_10_OFF;
		(led_pwm[11] < counter) ? LED_11_OFF : LED_11_OFF;
			
		/* If you want a "chaser effect"
		   then you can "scroll" the brightness values */
                if(!counter){
		    for (int i=0; i<12; i++) {
			    led_pwm[i] += 1;
		    }
                }
	}
}

You need to define the "LED_x_OFF" and "LED_x_ON" routines to whatever works with your application/compiler.

It is not perfect, but I think that sort of code is a good place to start.. when you play with it you'll learn how it works and how you can modify it the way you like.
 
Last edited:
I am assuming you know about PWM... Pulse Width Modulation???


If not you need to create a square wave output on say PORTB pin 0 then vary the off/on time to decrease / increase the brightness of the LED.

Simple... No because you want the brightness to change depending on the led in the 12 bar array... and the sequence...

Bet way is an buffer led control... a 12 byte array that can hold the brightness in each external LED... then in an interrupt you can adjust timings to suit each LED..


OR just do that.... I was busy typing and MrT came along...
 
Bet way is an buffer led control... a 12 byte array that can hold the brightness in each external LED... then in an interrupt you can adjust timings to suit each LED..
OR just do that.... I was busy typing and MrT came along...

Moving the code (that is inside the while-loop of my example) in an interrupt would be good improvement. It is hard to write example code when you do not know the person you are trying to help.
 
For comet tail effect, you're going to need PWM of some sort....
...

As a hardware alternative, you could put a capacitor across each LED. That could be set up to give a reasonable comet tail effect I think.
 
My wife makes wooden lighthouses amonst other things, they have a pcb with 8 leds that mimicks a lighthouse light scanning.
I did that with a pic16f54, 8 channels of port b are sequenced as though its a non crossfade circuit, then the cathodes of the even leds go to one port a pin which performs a pwm function, this pin is inverted with a transistor which then drives the odd leds.
Net result I have good crossfade and a realistic lighthouse effect with 8 digital sequence channels and just one pwm channel.
Squeezing the most you can from a simple pic.

My prototype circuit working:

https://www.youtube.com/watch?v=eN6lWNRbaUk
 
Nice! You've made the simplest 2-pin A-B crossfade possible with a single PWM pin, then meshed that with the 8-led sequencer. Nice work! :)

I've done it the hard way with an up-down ramp lookup table, and manually PWMed the LEDs (in code) according to their phase position on the lookup table. But that requires the ability to PWM all the LEDs.

Your system could also be done in software. If you software run PWM in an interrupt, and toggle a mask byte from 01010101 to 10101010, that essentially duplicates your hardware PWM. Then you mask the 01010101(etc) with the two seqenced LEDs; 00110000 etc.

The result would be 100% software, uses one PWM, and only needs 8 wires to the 8 LEDs. And still uses the simplicity of your idea. :)
 
Thanks rb, respect.

Lazyness is the mother of invention, I wanted a easy way, and that worked, pwm is done in software on one pin.

Your idea is also a good one using a mask on the o/p byte, I'll remember that.

The pic16f54 doesnt support interrupts, took me a while to think how to write code as all my code till then was inepterrupt driven.
 
I have following code for PIC16F628A . All LEds are fading together. no tunning action. please help me to correct it. all leds are fading together and getting on together

C:
#include <pic.h>
#define FADE_RATE 12
#define INITIAL_WIDTH 128
void fade()
  {
  unsigned char rate = FADE_RATE;
  unsigned char pulse_width = INITIAL_WIDTH;
  unsigned char count;

  while(pulse_width){
     PORTB= 0b11111111;
     for(count=0; count<pulse_width; count++){
        asm("NOP");
      }

      PORTB=0b00000000;
      for(; count; count++){
         asm("NOP");
      }
     if(!rate--){
        pulse_width--;
        rate = FADE_RATE;
      }
  }

}

int main(void)
   {
    char b;
    TRISB  = 0b00000000;

    while(1){
       for(b=0x02; b; b<<=1){
          PORTB = b;
          fade(b>>1);
        }
      for(b=0x40; b; b>>=1){
        PORTB = b;
        fade(b<<1);
      }
  }
}
MOD Edit!! Please use code tags
 
Last edited by a moderator:
My wife makes wooden lighthouses amonst other things, they have a pcb with 8 leds that mimicks a lighthouse light scanning.
I did that with a pic16f54, 8 channels of port b are sequenced as though its a non crossfade circuit, then the cathodes of the even leds go to one port a pin which performs a pwm function, this pin is inverted with a transistor which then drives the odd leds.
Net result I have good crossfade and a realistic lighthouse effect with 8 digital sequence channels and just one pwm channel.
Squeezing the most you can from a simple pic.

My prototype circuit working:


That's a pretty clever idea... You got a video of the circuit working in one of the lighthouses that's perhaps a little less fuzzy than the video you posted?

Mike
 
My wife makes wooden lighthouses amonst other things, they have a pcb with 8 leds that mimicks a lighthouse light scanning.
I did that with a pic16f54, 8 channels of port b are sequenced as though its a non crossfade circuit, then the cathodes of the even leds go to one port a pin which performs a pwm function, this pin is inverted with a transistor which then drives the odd leds.
Net result I have good crossfade and a realistic lighthouse effect with 8 digital sequence channels and just one pwm channel.
Squeezing the most you can from a simple pic.

My prototype circuit working:

Nice work, love blinky flashy
 
I'm working on it.
Can I post links to adverts on this site?, or is that too cheeky.
Sorry Jayan, theres nothing I do to help I code in assembler.
 
I'm working on it.
Can I post links to adverts on this site?, or is that too cheeky.
Sorry Jayan, theres nothing I do to help I code in assembler.
As long as you are not trying to sell anything I guess.
 
I'm working on it.

Don't worry about it... I was just curious about the effect. It didn't seem like a very smooth fade in that video and I was wondering if I should offer assistance or advice. I've played with LED effects for several years and I've discovered a number of novel PWM techniques. For example, check out this short smooth fade video (below). It's a five pin Charlieplexed matrix of 20 LEDs and each LED has 64 gamma corrected brightness levels that span an 8-bit (256 level) BAM (bit angle modulation) brightness value with a 781 Hz refresh rate. I suspect you could get a pretty good lighthouse effect with a single fading LED pointing up at a small conical shaped mirror but I have no idea how you might get a realistic rotating beacon effect.

My apologies for going slightly off topic...

Cheerful regards, Mike

 
Last edited:
Cant remember now, however you cant really tell any flicker or unsteadyness, from memory there are 128 levels of brightness and the step is smooth, for the application it works great, and from a 'f54 not a lot more could be expected.
I havent charleplexed more than a few led's, that really did my head in, I'm only a simpleton.
 
Very interesting Mike, really nice fade. Ive tried all sorts to get fading as smooth as that, but it isnt as easy as it looks :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top