Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 8th June 2008, 01:07 PM   (permalink)
Default

He (the OP) already referenced your site and this project in his first post...

Mike
Mike, K8LH is offline   Reply With Quote
Old 8th June 2008, 01:19 PM   (permalink)
Default

O nice, i missed that link in the text

__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Old 8th June 2008, 01:51 PM   (permalink)
Default

Quote:
Originally Posted by futz View Post
I'm putting up an article on my site now. It'll be ready in 10 or 15 minutes. Nothing terribly earth shaking. Just a simple little newb article.
Futz,

Nice demo, as always. My only 'nit' would be to use a shadow variable to prevent turning on the LEDs when they have a duty cycle of 0. Updating the output latch from the shadow also produces consistant duty cycle durations. Your example (and another forum members example) will produce different "on times" for the three colors when they have been set to the same duty cycle. Of course this is not important in the context/scope of your very nice demo.

Mike
Code:
;
;  Dim red, grn, blu As Byte    ' duty cycle, 0..255
;  Dim dcy As Byte              ' duty cycle counter, 0..255
;  Dim shadow As Byte           '
;
;  Interrupt rgb_interrupt()
;    t0if = 0                   ' clear timer0 interrupt flag
;    inc(dcy)                   ' increment duty cycle
;    if dcy = 0                 ' if new period
;      shadow = %01110000       ' set RC6..RC4 shadow bits
;    endif                      '
;    if red = dcy then          '
;      shadow.bit6 = 0          ' turn off RC6 shadow bit
;    endif                      '
;    if grn = dcy then          '
;      shadow.bit4 = 0          ' turn off RC4 shadow bit
;    endif                      '
;    if blu = dcy then          '
;      shadow.bit5 = 0          ' turn off RC5 shadow bit
;    endif                      ' 
;    LATC = shadow              ' update port from shadow
;  End Interrupt
;
rgb_interrupt                   ; 14 words
        bcf     INTCON,T0IF     ; clear timer 0 interrupt flag
        movlw   b'01110000'     ;
        infsnz  dcy,F           ; new period? no, skip, else
        movwf   shadow          ; set led bits in shadow
        movf    dcy,W           ; wreg = duty cycle, 0..255
        cpfsgt  red             ; (F) - (W), skip if (F) > (W)
        bcf     shadow,6        ; clear bit if (F) <= (W)
        cpfsgt  grn             ; grn - dcy, skip if grn > dcy
        bcf     shadow,4        ; clear bit if grn <= dcy
        cpfsgt  blu             ; blu - dcy, skip if blu > dcy
        bcf     shadow,5        ; clear bit if blu <= dcy
        movff   shadow,LATC     ; update port c from shadow
        retfie  FAST            ;
(1) this code / algorithm / method is public domain and anyone may use it as they wish...

Last edited by Mike, K8LH; 8th June 2008 at 02:05 PM.
Mike, K8LH is offline   Reply With Quote
Old 8th June 2008, 04:22 PM   (permalink)
Default

Quote:
Originally Posted by gramo View Post
Its generally a very small difference in brightness, if noticeable at all with good LED's
Ya, the LED I'm using has very equal red and green. The blue is just a little dimmer. I plan to lower the value of the resistor feeding blue to equalize things a bit. Should un-pinkify the magenta a little.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 8th June 2008, 04:32 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
My only 'nit' would be to use a shadow variable to prevent turning on the LEDs when they have a duty cycle of 0. Updating the output latch from the shadow also produces consistant duty cycle durations.
Good plan. I'll improve my quick and dirty code.

Quote:
Your example (and another forum members example) will produce different "on times" for the three colors when they have been set to the same duty cycle.
Only the tiniest bit different. But may as well fix it anyway with the shadow variable method.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 8th June 2008, 05:30 PM   (permalink)
Default

I apologize for picking 'nits'. No one could possibly perceive the timing difference. Also happy to contribute in a very small way to your very "shiny" site.

Please note that I reversed the bit polarity in my previous example but I'm sure you already figured that out.

Regards, Mike
Mike, K8LH is offline   Reply With Quote
Old 8th June 2008, 05:43 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
I apologize for picking 'nits'. No one could possibly perceive the timing difference. Also happy to contribute in a very small way to your very "shiny" site.
Heh! Shiny! Ya, that's it. No problem. I hadn't thought about that "nit". In some programs that could be a problem. But in mine it just wouldn't matter. Tis fixed anyway.

I have it cycling thru all 16.7milion colors now. Takes forever!
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is offline   Reply With Quote
Old 8th June 2008, 05:54 PM   (permalink)
Default

Quote:
Originally Posted by PwnToaster View Post
Thanks again for your help. I believe the ATMega168 has internal pull down resistors, so an external resistor is not needed, but thanks for reminding me to enable them!
I gave a fast look at the datasheet and it only shows pull ups lol, it seems that you know everything, why do you ask for help then ?

(i'm in a bad mood today... sry)
__________________
Best Regards,
Tiago Silva.
TiagoSilva is offline   Reply With Quote
Old 8th June 2008, 06:26 PM   (permalink)
Default

Quote:
Originally Posted by TiagoSilva View Post
I gave a fast look at the datasheet and it only shows pull ups lol, it seems that you know everything, why do you ask for help then ?

(i'm in a bad mood today... sry)
I have a low budget and I don't want to buy anything that I don't have to, and I don't want to fry them.
I also like to figure everything out before I buy something so I can do it with minimal frustration. Here is my updated schematic. If you guys see anything, let me know! I can't thank you enough for all of your help everyone!
PwnToaster is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
LEDs RayH General Electronics Chat 33 12th June 2008 08:10 PM
180 leds! justDIY Electronic Projects Design/Ideas/Reviews 4 8th February 2007 05:46 PM
LEDs zachtheterrible Electronic Projects Design/Ideas/Reviews 25 5th October 2004 03:41 PM
RGB LEDs with PWM?? seahkw Micro Controllers 2 27th August 2004 01:30 AM
LEDs-Super Bright White LEDs $1.35USD ea ssullivan777 Datasheet/Parts Requests 0 27th February 2003 02:02 AM



All times are GMT. The time now is 10:35 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.