The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 28, 2024, 04:26:07 16:26


Login with username, password and session length


Pages: [1]
Print
Author Topic: RainbowVoltmeter  (Read 3457 times)
0 Members and 1 Guest are viewing this topic.
aslan_korhan
Active Member
***
Offline Offline

Posts: 147

Thank You
-Given: 1
-Receive: 60



WWW
« on: May 19, 2006, 04:52:15 16:52 »

Rainbow LED indicates voltage with        color

Meters that indicate analog levels via a moving-pointer meter, a        numeric display, or a column of LEDs typically occupy considerable panel        area and require more than a casual glance to read. An indicator lamp or        LED takes little space but indicates only an on or off condition. However,        an unobtrusive LED that changes color as a function of a measured value        would enable an observer to easily assess the measurement.

       The circuit in Figure 1 comprises IC1, a        Microchip PIC12F675 microcontroller driving IC2, a Kingbright        AAF5060PBESEEVG "rainbow" indicator that contains three ultrabright LED        chips (red, green, and blue) within one package. Modulating each LED's        duty cycle produces all of the perceivable colors of the visible spectrum,        including white light. Listing 1 contains a PIC program        for the PicBasic Pro compiler, which is available from MicroEngineering        Labs Inc (http://www.melabs.com/). This program converts a 0 to 5V        input applied to Pin 3 of IC1 to an 8-bit digital value that        corresponds to a perceived color containing certain amounts of red, blue,        and green.

Under control of a PWM routine, each LED flashes for an interval        proportional to its corresponding content of red, green, or blue. During        each PWM frame, an LED die receives power for as many as 14 steps per        frame as the color map of Figure 2 shows. Although not        all LEDs are necessarily simultaneously illuminated, the eye's slow        response integrates their output to create the illusion of a change in        intensity proportional to the duty cycle. The RGB-encoding function in        Listing 1 assumes that the analog input to IC1        has a zero-signal offset of 2.5V, which switches all LEDs off. "Cool"        colors (shades of blue, purple, and aqua) denote an input in the 0 to 2.5V        range, and "hot" colors (shades of red, orange, yellow, and white) denote        an input in the 2.5 to 5V range. You can create different palettes by        changing the primary-color proportions stored in the RGB encoding        table.

;***********************************************************************************
;
;        LISTING 1
;
; "Rainbow LED indicates voltage with color," EDN,        December 7, 2004, pg        106
;
;***********************************************************************************

'        PicBasic Pro program to read A/D on 12F675 ADC
' and display voltage        A/D output using multi-color LED
' using a cold-to-hot color        pallette.  Center of range
' is dark.
'

i              VAR     BYTE    ' Define loop        variable
blue    VAR            BYTE    ' Define blue pulse-width        variable
green   VAR            BYTE    ' Define green pulse-width        variable
red     VAR            BYTE    ' Define red pulse-width variable
' GPIO port 0        to GREEN LED
' GPIO port 1 TO RED LED
' GPIO port 2 to BLUE        LED
color   VAR            BYTE    ' Define LED color        variable
x              VAR     BYTE ' Allocate A/D variable

' Set A/D        Parameters
DEFINE ADC_BITS 8 ' Use 10-bit A/D as 8-bit        A/D
ANSEL.3=1 ' Set ANS3 as analog input pin
ANSEL.4 = 0 ' Set        A/D clock
ANSEL.5 = 1
ANSEL.6 = 0
ADCON0.0 =        1            ' Turn        On A/D
ADCON0.2 = 1 ' A/D channel 3
ADCON0.3 = 1
ADCON0.6 =        0 ' VDD is voltage reference
ADCON0.7 =        0            ' Left        Justify result

' Set GPIO port pins 0, 1 and 2 as        outputs
TRISIO.0=0
TRISIO.1=0
TRISIO.2=0


GoTo           mainloop        ' Skip        subroutines

' SUBROUTINES
' -----------

' Subroutine to        read a/d converter
getad:

              ADCON0.1 =        1            '        Start conversion
       PauseUs        50                     ' Wait for conversion
       x =        ADRESH
       Return


'        MAIN
'        ----

mainloop:


               GoSub          getad           ' Get x        value by performing A/D conversion


'  RGB ENCODING        FUNCTION
'  Convert A/D reading into color table
'  Each        color has 14 possible intensity levels


IF x<=42        Then                    'aqua
    red=x/3
      blue=14
           green=(42-x)/3
EndIF
IF x>42 AND x<=84 Then          'shades of violet
    red=(84-x)/3
           green=0
     blue=14
EndIF
IF x>84 AND        x<=126 Then  'shades of green
    red=0
           green=0
    blue=(126-x)/3
  EndIF
         IF x>126 AND x<=130 Then  'dark
          red=0
   green=0
   blue =0
         EndIF
IF x>130 AND x<=172 Then  'shades of        red
   red=(x-130)/3
   green=0
          blue=0
EndIF
IF x>172 AND x<=214 Then  'red / orange /        yellow
   red=14
          green=(x-172)/3
   blue=0
EndIF
IF x>214        Then                    'yellow to white
   red=14
          green=14
   blue=(x-214)/3
EndIF


' PULSE WIDTH        MODULATOR
' Each PWM frame has 14 steps.

For i = 1 TO 14  '        Cycle through 14 steps of frame
color=0
   IF red>0        Then
             color=color+2
      red=red-1
          EndIF
   IF green>0 Then
             color=color+1
             green=green-1
   EndIF
   IF blue>0        Then
             color=color+4
             blue=blue-1
   EndIF
   GPIO=color
PauseUs        100     ' Allow LEDs to shine for a few        microseconds
Next i
GPIO=0
GoTo           mainloop        ' Do it        forever

End
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC