Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
   
 Home     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

Author Topic: Landing Pad Project (modding the LED sequencer)  (Read 12488 times)

0 Members and 1 Guest are viewing this topic.

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #30 on: November 16, 2011, 10:20:50 AM »
Oh, i see. So you want to use PWM to control also the brightness. Well, Arduino-users use lots of PWM, because arduino has lots of PWM outputs. May PICs have PWM outputs, most of them limited to 1 or 2 channels, but you want at least 4 channels (3 for the circles and 1 for the blues). 16F1824 for example has 4 PWM channels, and 16F1527 has 10. Check them out using MIPS.

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #31 on: November 16, 2011, 23:16:34 PM »
TY K,

As it happens, I only want the blue ring to pulsate :) and wondered what the code/circuitry would be, see ...

http://picprojects.org.uk/projects/ledchaserpwm/
http://www.micro-examples.com/public/microex-navig/doc/097-pwm-calculator.html

TY for the link, I just wondered if we knew how to PWM from the 16F88, already, just as in motors etc, to pulsate the 4 blue LEDs? I should be able to use the code(s) in the first link, above, to give it a go.

Cheers.

CS
« Last Edit: November 17, 2011, 02:19:30 AM by Colonel Shofer »

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #32 on: November 17, 2011, 07:59:19 AM »
the second link uses the internal pwm module of the pic. I use it quite often myself. Check my circuits with pic and pwm, for example this -http://pcbheaven.com/circuitpages/PWM_LCD_Contrast_Control/


Quote
            ;Setup PWM module
            bank1
            movlw 0x80
            movwf PR2         ; Period
            bank0

            movlw b'00000100'
            movwf T2CON
            movlw b'00111100'      
            movwf CCP1CON

The above code sets the PWM duty cycle and frequency. From that point, you can change the duty cycle only by changing the register CCPR1L. The output is at pin labeled CCP1.


As for the second link, it uses another technique. I suppose that the PIC runs manually PWM loops. Here is how it goes: You set a register with the total pwm period. Then, for each channel you set different duty cycle registers. Then you run the loop. At the beginning of the loop, you turn on all the outputs that have dc-register higher than zero. At every loop. you decrease all the dc-registers and the period register as well. If one of the dc registers becomes zero, then you turn the corresponding output off. Finally, when the period register becomes zero, you re-start the whole process.

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #33 on: November 17, 2011, 23:06:14 PM »
TY K,

Super ... time to put my thinking (and building) cap on :)

Cheers and TY again.

CS.
« Last Edit: November 17, 2011, 23:12:48 PM by Colonel Shofer »

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #34 on: December 05, 2011, 11:40:54 AM »
TY again, we on-the-way ...

First programmed and working LED sequencer circuit
http://www.youtube.com/watch?v=GA_xvIHOKTw

Now to learn more (some !!!) programming, to try and work out how to pulse/breath an LED from one of the outputs, by PWM ... any ideas please? :(

CS

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #35 on: December 05, 2011, 19:15:11 PM »
you want to pulse each LED with different effect? i mean, all 4 leds will pulse together, or it will look like kitt? which pic you used?

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #36 on: December 06, 2011, 16:39:47 PM »
Hi K,

Please see my schematic. I can now work on how to reduce the code, to only three pins and use transistors to drive the red 'rings' ...



I only want the 4 *blue* LEDs to 'breath' (via a transistor, from one pin, I guess).

They should have a different (and programmable) 'breath' frequency, from the red LEDs, but, ideally, be able to match that frequency too, by programming.

So many pins, seems silly to waste them :)

As a newbie ... is it possible to have separate routine 'modules' like this, on different pins, in the same program? I am still trying to get my head around that concept (particularly timings for each 'module').

CS
« Last Edit: December 06, 2011, 16:44:12 PM by Colonel Shofer »

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #37 on: December 06, 2011, 18:38:39 PM »
the pic you use has only 2 PWM channels, so you may have only 2 different pulsing frequencies/Duty cycles. Do you use charlieplexing to drive the LEDs? I cannot tell from the schematic. It is a bit mess.

This is what i would do: I would have 4 pins, one for each circle and one for the blue LED. Then, you can have software PWM to control each channel alone. This means of course that the PIC will be 100% occupied to do the PWM and the PWM only, but i think that this is not a problem for you. Here is the idea for the software PWM. Suppose that you have 4 channels at RB0, RB1, RB2 and RB3 ports.You will need a global counter (GlobalCounter) and 4 DC counters one for each channel (DC_1, DC_2 etc).

Code: [Select]

RestartPWM
 clrf GlobalCounter
 movlw d'128'
 movwf DC_1 ;50% duty cycle for channel 1

 movlw d'64'
 movwf DC_2 ;25% duty cycle for channel 2

 movlw d'192'
 movwf DC_3 ;75% duty cycle for channel 3

 movlw d'10'
 movwf DC_4 ;something else for channel 4

 bsf portb,0
 bsf portb,1
 bsf portb,2
 bsf portb,3

MainLoop
 decf DC_1,f
 btfsc zero
 bcf portb,0

 decf DC_2,f
 btfsc zero
 bcf portb,1

 decf DC_3,f
 btfsc zero
 bcf portb,2

 decf DC_4,f
 btfsc zero
 bcf portb,3

 incf GlobalCounter,f
 btfss zero
 goto MainLoop
 goto RestartPWM
 




Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #38 on: December 06, 2011, 23:04:34 PM »
TY Z,

I will try to see if I can get it working on the simulator, first.

The three red rings are each in parallel and were to be driven from a transistor (3 pins).
The fourth blue ring was in parallel and was to be driven from a transistor (1 PWM pin).

May I ask for more details on ...

Quote
This means of course that the PIC will be 100% occupied to do the PWM and the PWM only

I do understand that you have made all the lines PWM, but, in general, does that not only apply to the 2 PWM pins, leaving the other pins independent, for their own 0/1 states or am I missing something?

TY

CS

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #39 on: December 07, 2011, 07:37:27 AM »
the 2 pwm pins are driven by the internal PWM module (hardware), which means that they can run PWM and still the pic can do other things. The solution i gave you can make all the outputs PWM, but the PIC will not be able to do anything else because it will be occupied by the PWM routine all the time.
Ok, you may be able to run some small parallel routines or work on some interrupts, but if they get too long, it will be observable to the LEDs

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #40 on: December 08, 2011, 14:43:10 PM »
TY K,

Yes, I guessed interrupts may be the way forward, but I need to learn about those too :)

OK, will have a go at your routine, first, and see how that goes

TYVM

CS

Colonel Shofer

  • Guest
Re: Landing Pad Project (modding the LED sequencer)
« Reply #41 on: January 23, 2012, 03:05:33 AM »
Just a quick update ...

Landing Pad (Part 7)
http://colshofer.blogspot.com/2012/01/landing-pad-part-7.html



Code good enough, for now, to allow the model build ... then I will get more sophisticated on it :)

TY again.

CS

kam

  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Re: Landing Pad Project (modding the LED sequencer)
« Reply #42 on: January 23, 2012, 07:43:50 AM »
cool!  8) 8)