CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

knight rider effect
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

knight rider effect
PostPosted: Tue Jul 20, 2010 5:51 pm     Reply with quote

hi

I try make this effect with an PIC18F252 but I don't know how I can make fading effect.
Code:

while(1)
{
output_b(0b00000001); delay_ms(time);
output_b(0b00000010); delay_ms(time);
output_b(0b00000100); delay_ms(time);
output_b(0b00001000); delay_ms(time);
output_b(0b00010000); delay_ms(time);
output_b(0b00100000); delay_ms(time);
output_b(0b01000000); delay_ms(time);
output_b(0b10000000); delay_ms(time);
output_b(0b01000000); delay_ms(time);
output_b(0b00100000); delay_ms(time);
output_b(0b00010000); delay_ms(time);
output_b(0b00010000); delay_ms(time);
output_b(0b00001000); delay_ms(time);
output_b(0b00000100); delay_ms(time);
output_b(0b00000010); delay_ms(time);
}

Someone can help how I can add fading? link this
http://www.youtube.com/watch?v=DHsjQSv8zMo&feature=related

best regards
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Tue Jul 20, 2010 6:58 pm     Reply with quote

Well it doesn't really matter which chip you use for this. This effect can be done even by a tiny pic. You need to use PWM channels for each LED and fade away the values on a timer.
_________________
Regards
Jerson Fernandes
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 1:05 am     Reply with quote

And as you are working with 8 channels, you'll need to read up on software PWM.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 6:43 am     Reply with quote

hi

I think in use PWM but on PIC18F252 I only have one PWM output.

is possible implement PWM in software to all pins of B port?

best regards
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 21, 2010 7:02 am     Reply with quote

I've done 8 channels on a '628A. My code was based on Scott Dattalo's asm code which can be found here http://www.dattalo.com/technical/software/pic/pwm8.asm.

-Basically, for a 256-level resolution, what you need to do is maintain 8 registers (lets call them 'brightness' registers). The brightness registers hold the PWM value which needs to be output on the corresponding output pin.

-Copy these values into temporary registers.

-Run a loop 256 times; everytime you complete an iteration, decrement the temporary registers. Check the values in each of the registers; if it is greater than 0 then set the corresponding pin high, else set it low.

-After the loop has completed, reload the temporary registers with the brightness values, and repeat the process.

Now this may seem complicated, but it can all be acheived with some simple embedded assembly - BSF, MOV, AND, OR. The reason why I used assembly is beacause it affords me a higher degree of PWM timing accuracy (ie, I know exactly how long a complete PWM cycle will take).

Rohit
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 7:22 am     Reply with quote

As a comment. Consider doing it a different way!.
Take the PWM output, and (if more than 25mA is neeed), feed this to an emitter follower, so it provides a variable duty cycle 'drive' to the 5v. Otherwise just use it directly, and connect to the top of a single resistor to feed the LED anodes. Then have your port B outputs (again buffered if more power is needed), connected to the LED cathodes.
Set PORTB 'all high'. LED's will be off. Now turn the individual bits 'low', and the corresponding LED comes on, but the intensity is now controlled by the PWM. So your code becomes (symbolically):
Code:

while(1)
{
output_b(0b11111110);
Ramp PWM up then down
output_b(0b11111101);
Ramp PWM up then down

etc..
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 21, 2010 7:33 am     Reply with quote

Ttelmah wrote:
Consider doing it a different way!
Wow! Now that's some out of the box thinking! Respect!

Rohit
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 21, 2010 9:02 am     Reply with quote

Ttelmah

I beg to disagree with your scheme. You will not be able to achieve independent yet simultaneous dimming of all the 8 channels. Think of the problem like this.

Any bit set to 1 fades away in time. Now if I set this pattern
0000 0001
the 1 bit will fade away in some mS that is visible enough due to the softPWM
similarly a pattern 0000 1001 will cause the 1 bits to fade away in the fader time

Now, if the bit is rolled left - right and right - left, you can see what this will do. It will give the comet tail effect as seen in that video.

Cheers
Jerson
_________________
Regards
Jerson Fernandes
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 9:07 am     Reply with quote

Hi

Ttelmah your suggestion all LEDs make fading at same time, dont like on video correct?

Rohit de Sa, thanks for your explanation I don't know how I can implement this in C.

best regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Wed Jul 21, 2010 10:02 am     Reply with quote

That's down to decisions on your hardware. If you want to have one LED on full, and another dimmed, then you would need to arrange to switch the one 'on' directly to a non PWM source. It can be done, but gets more complex....

Best Wishes
Rohit de Sa



Joined: 09 Nov 2007
Posts: 282
Location: India

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 21, 2010 10:57 am     Reply with quote

filjoa wrote:
I don't know how I can implement this in C
The way I did is was to declare my variables and perform initializations using normal CCS-C. I then embedded assembly using the #asm and #endasm directives. I suppose you could do the same using C, but you'd probably need to look multiple times at the disassembly listing to ensure tight timing - I'd rather look just once and make sure that my code is doing the PWM loop at the correct frequency.

Rohit
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jul 22, 2010 8:15 am     Reply with quote

I would consider using one cheap PIC12Fxx per LED. Either put them in a daisy chain or have a master PIC to trigger them, and let them deal with dimming their own LED.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jul 22, 2010 5:31 pm     Reply with quote

Here a link to a ready made project using 8 leds. The project is very wel documented including PCB design etc. Too bad it is written in assembly, but well, the Microchip Assembler is a free tool so that shouldn't be a real problem.

A design simplification this project used is that the number of led levels was reduced to 4 (0=off, 3 = full brightness). If you look at the video's this is enough for great effects.

For only a few different PWM levels you can create a simple PWM in a loop using delay statements, or if you want more levels and flexibility use a timer interrupt like discussed here.
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 23, 2010 5:17 am     Reply with quote

Quote:
I would consider using one cheap PIC12Fxx per LED. Either put them in a daisy chain or have a master PIC to trigger them, and let them deal with dimming their own LED.


Or a port expander like the MCP23016..

But I think the 'fading' effect will not be smooth even if you use the PWM method.
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 23, 2010 8:33 am     Reply with quote

The way to go is soft PWM. Here is my quick and dirty rendition of the scanner using a jumbled up 7 segment display of a setup I have at hand.

http://jerson.co.in/NewSite/886_Pwm.mp4

This video plays with VLC Player

edit : I think you need to save the file and then view it
_________________
Regards
Jerson Fernandes


Last edited by Jerson on Fri Jul 23, 2010 11:38 am; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group