Electronics PICs, Luxeons, PWM ...n00b in need of some advice!

Discussion in 'Modding' started by H2O-G33K, 11 Apr 2004.

  1. specialk

    specialk What's a Dremel?

    Joined:
    5 Feb 2002
    Posts:
    68
    Likes Received:
    1
    I actually just edited the regular serial PWM controller so that it can run solo. Check out "8 RGB LED Controller" for the code. All you have to do is load your pattern into the EEPROM (at the top of the code) and run! Simple as that :p
    [Well... you do need JAL to compile the code, but it's free, and you need to make the circuit, but that's relatively easy.]

    -special [k]
     
  2. Hazer

    Hazer In time,you too will be relixalated

    Joined:
    14 Apr 2003
    Posts:
    957
    Likes Received:
    2
    16F872 does not have a low-voltage option. Only the 16LF sries does ( and they dont make a 16LF872).

    I dont see why the hardware PWM cant be used, umless we are talking about chasing LED patterns. Easiest thing to do for chasing LED patterns is to create a Timer0/2 Event.

    For timing: use a special Event procedure in your ISR (interupt service routine). This requires a 24 bit GPR (3 GPRs, hibyte, midbyte, lowbyte). Highbyte, midbyte, and lowbyte contain a number (lets say 500,000). With Tosc = 1MHz, this number means half a second. On every rollover (no pre/post scaler) you decrement 1 from the midbyte. Remember to borrow from highbyte when needed. Once hihgbyte and midbyte reach zero, you have an event. At the end of the event, you add 500,000 to what remains in the lowbyte. Over time, this leads to average of zero error for a half second event routine.

    In your event, you could have a bunch of GPRs that hold certain bytes to be output to a whole port. Say you have a red LED on pin0, a blue LED on pin1, and a green LED on pin2. You could (indirectly) change the bytes on that port from 0x00 -> 0x01 -> 0x02 -> 0x03 -> 0x04 -> 0x05 -> 0x06 -> 0x07 and then back to zero or any combination you want.
     
  3. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Alright then, so with 4xAAA NiMH batteries, I should clock it at 4MHz (typically they give ~5.2V at full charge - at least that's what I measured). Sounds fine to me.

    @ConK : Going back to one of your previous posts (#11).. I'm not designing a chaser here, just 3 different colours, red, green and blue. 4 of each colour to make the thing really bright. I'd be tempted to use one of the all-in-one 3 colour LEDs you can get, but I want these things to be super bright so it's got to be seperates :)

    @specialk : Nice work there! My project is a little different as I don't want a chaser, just 3 different colours, PWM'd. I'd like to use the individual 3-colour LEDs you've got, but as I mentioned above, I want higher light output. I'll be using 4 red, 4 green and 4 blue super-bright LEDs inside the containers in the image at the top of the page (not visible 'till about tuesday as my server's down :rolleyes:

    You mentioned in your article that due to the 4MHz operating speed, you had flickering when you moved your head around? This is a big issue for me, because Poi are swung around your body at a fair speed. Is this going to be a problem, or d'you think it can be worked around with some optimisation?

    I'd like these units to last for at 2-3 hours (at the very least) between charges, so the more efficient I can make them, the better. This is the reason I'm drawn to PWM :) If it's going to be impossible to acheive the results without resistors in series with the LEDs, I guess I'll just have to live with it - ho hum :waah:

    Right, got a LAN party to go to so I'll have a bit more of a read up of datasheets over the weekend if there's a chance and have a bit more of a think.

    Thanks for all the input / advice - this project feels a little more like it might actually work thanks to you lot :clap: :D

    [Edit]grrr, curse the caching firewall here at work - missed those last two posts. Sounds almost too easy specialk! Is there a way around the flashing when you move your head? Faster code or something?

    @Hazer : What advantage does the hardware PWM have (I'm not doing any chasing) - faster execution maybe?[/Edit]
     
    Last edited: 16 Apr 2004
  4. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    hardware PWM is much easyer to impliment, as you just set the value of a control register and it will produce the pulses by itself.
     
  5. H2O-G33K

    H2O-G33K What's a Dremel?

    Joined:
    25 Jan 2003
    Posts:
    240
    Likes Received:
    0
    Sounds good, but will it do 3 individual pulses (one for each colour). When I was skimming through the data sheets (not had a chance to have a thorough look yet) it looked like there was just one?
     
  6. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    Yes, unfortunately on that PIC there is only one PWM channel.

    The PIC16F737, 747, 767 and 777 have 3 channels though if you don't want to have to worry about coding the PWM routine.
     
  7. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    if your not having to do anything else that requires much processor time try using the TMR0 interupt like so:
    Code:
    ORG	0x04
    	MOVLW	0xC0
    	MOVWF	TMR0
    	CLRF	_TEMP_GPIO
    	INCF	_LOOP_COUNTER, F
    	MOVF	_LOOP_COUNTER, W
    	ADDWF	_LED0, W
    	BTFSC	STATUS, C
    		BSF	_TEMP_GPIO, 0
    	BTFSS	STATUS, C
    		BCF	_TEMP_GPIO, 0
    	MOVF	_LOOP_COUNTER, W
    	ADDWF	_LED1, W
    	BTFSC	STATUS, C
    		BSF	_TEMP_GPIO, 1
    	BTFSS	STATUS, C
    		BCF	_TEMP_GPIO, 1
    	MOVF	_LOOP_COUNTER, W
    	ADDWF	_LED2, W
    	BTFSC	STATUS, C
    		BSF	_TEMP_GPIO, 2
    	BTFSS	STATUS, C
    		BCF	_TEMP_GPIO, 2
    	MOVF	_TEMPT_GPIO, W
    	MOVWF	GPIO
    	BCF	INTCON, T0IF
    	RETFIE
    
    Anything with a prefix of _ is a "user defined file register" ie, its not a specail hardware one, its just some space you assign a label with

    Lets define these registers with a Constant Block
    Code:
    cblock		0x20
    	_TEMP_GPIO
    	_LED0
    	_LED1
    	_LED2
    endc
    
    This will give you 256 values, but because we see light log, only 8 are useable.
    b'00000001'
    b'00000010'
    b'00000100' and so forth.

    b'00000000' is off
    b'11111111' is on 255 in 256 times, so its close enough.

    Idea is the TMR0 interupt will be called every FF - C0 cycles (64 in decimal). A counter _LOOP_COUNTER is incrmented every time this happens, if the value of the _LEDx register when added with it overflows FF (setting STATUS, C to 1) then set the port to 1. Becase we are good asm'ers we don't use a read write modify on the GPIO ports, because when you read a GPIO port, you get the INPUT value, not the one we have set it too, with an LED on as input this will always appear logic 0. All we have to do now is set this up.

    Code:
    ORG	0x00
    	CLRF	INTCON
    	CLRF	STATUS
    	GOTO	INIT
    
    then below the ISR (org 0x04 is where the interupts always goto)

    Code:
    init:
    	BSF	STATUS, RP0 ; Bank 1
    	CLRF	GPIO
    	MOVLW	b'1001000'
    	MOVWF	OPTION_REG
    	BCF	STATUS, RP0 ; Bank 0
    	; Set up the desired PWM values
    	MOVLW	b'00000001' ; dim
    	MOVWF	_LED0
    	MOVLW	b'00010000' ; towards bright
    	MOVWF	_LED1
    	MOVLW	b'00100000' ; brighter than before.
    	MOVWF	_LED2
    	
    	; Enable the interupts
    	BSF	INTCON, T0IE ; Timer0 Interupt Enable
    	BSF	INTCON, GIE  ; Global Interupts Enable
    
    Program_Loop:
    	GOTO	$ ; you code 'ere
    
    The above should work, i'm wriitng in notepad, so you might find you can't start variable names with _ i only did that to show which our my labels rather than arazona microchip ones.

    If i've not explained something just ask (but not jeves, that search engine is useless).
     
  8. specialk

    specialk What's a Dremel?

    Joined:
    5 Feb 2002
    Posts:
    68
    Likes Received:
    1
    You could use some caps to smooth the PWM output and this would prevent the flickering. Howwever, it is not so easy to do that for my project because the LEDs are multiplexed.

    -special [k]
     
  9. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    By adding capacitors he will definitely need resistors on the LED's which is something that he doesn't want to do.
     
  10. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    Or you could be cunning in your code, to make the PWM internal smaller (like above).
     
  11. ConKbot of Doom

    ConKbot of Doom What's a Dremel?

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    If you just want pwm and dont want it to flicker or run patterns, just use a PWM driver IC and a transistor (or a couple transistors if you are using luxeons)

    This shoule ba a digi-key search for PWM IC drivers. Plenty of choice.
     
  12. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    heya,

    I was following this topic but I dont quite understand how it would work in my situation.

    here are the details of the 10 RGB leds I ordered:
    SOURCE MATERIAL:InGaN
    EMITTING COLOUR:BLUE,GREEN,RED
    LENS TYPE:WATER CLEAR
    Luminous Internsity:1000mcd/Max2000mcd REVERSE VOLTAGE:5.0 V
    DC FORWARD VOLTAGE:3.5V TYPICAL
    DC FORWARD CURRENT:20~30mA
    VIEWING ANGLE:20

    I want to be able to split them into 2 groups of 5 and create multicoloured lights from each.

    so I need 2 seperate 'channels', each needing a red, blue and green.

    I want to use a pic or picaxe to pwm the output. I can order from maxim, farnell uk, rapid electronics or (ugh) maplins. So, I was thinking I need some sort of pic chip, but I don't have any pics, I have some PICAXEs (3x08, 2x18X and 1x40X) which I might be able to use. I'm not sure how I'd like to control them, serial control would be good so I can program sequences but to begin with, manual control from pots would be fine (I have lots of 10k pots). So I could have 6 10k pots, one for red,green and blue for channel 1 and another set for channel 2. maybe I don't even need pics and I can just dim the LEDs with diodes but I expect I won't get as good a range with that.

    so I'm looking for help on that, anyone give me ideas (sorry to hijack the topic, I can create a new one if needed)...

    computer
     
  13. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    What effects are you after from these lights?
     
  14. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    Getting further away from the first person's problem.

    As your wanting more than 3 channels hardware PWM won't help.

    If you want full brightness as a posibility, then for 10RGB Leds you will need 30 i/o pins.
    A PIC16F871 with built in UART would allow you to make a very simple LED throbber, with info been sent to it from the computer via rs232. You should be able to get 16 stages of log PWM from a 20mhz oscilator without much problem.

    PIC-axe's i've never looked at, so i can't say about the feisability, PWM is one of those things that uses a lot of micro controller time so depending on the host environment it might not be possible, if they are just a bootloader then it should be possible.
     
  15. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    well really for now I just want manual control... I'll need 6 channels, 2x each of the colours, and these need to run independantly from each other...
     
  16. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    He'd only need 6 outputs and a ULN2003 or similar as he only wants two sets of RGB lights, so a 16F628 would be fine.
     
  17. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    so what kind of code would I need for this? I'm assuming I'll need 6 analogue inputs, or, 3 analogue inputs and a digital to act as a switch for switching... or maybe some rotary encoders?

    would anyof you guys be willing to program one for me and pop it in the post when I've decided what I need if I pay for the cost of it..
     
  18. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    Oh by 2 sets does he mean, 5 LEDs at the same colour then another 5 LEDs at differn't colour?

    I am confused now!
     
  19. computer

    computer What's a Dremel?

    Joined:
    10 Jan 2004
    Posts:
    205
    Likes Received:
    0
    yeah
    2 sets, each set has got 5 leds all acting in parallel so the group will all be the same colour :)
     
  20. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    That's what I understood.
     

Share This Page