Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM 74HC595

Status
Not open for further replies.

SwingeyP

Member
Hi again,

Not been doing a lo lately (40m transceiver is still coming along - various design changes)

Anyway,

I new challenge.

I want to control 8 LED's (to start with) and turn them on and off in a defined pattern. (lets start with knight rider). Fairly easy!

Ok now I want to use the 74hc595 shift register. I think I have that kind of in my head too.

The question is what if I want to control the output using PWM. Will this work?

I'd like to make the LED's go from off to on gradually as they move from left to right to left to right to left ..........

I haven't tried this in the real world but here's a bit of code for one LED.

Would I need to send the individual duty PWM's each time then move to the next LED?


Code:
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'LEDPWM - Written by Paul Swingewood (M0TVU)
'14/11/2014   - PIC 16F877A
'--------------------------------------------------------------------------
'PWM control of an LED
'--------------------------------------------------------------------------
'Revision history
'14/11/14 initial code written.

'---------------------------------------------------------------
'DEFININTIONS
'---------------------------------------------------------------

'Define SIMULATION_WAITMS_VALUE = 1



Define CONFIG = 0x3f71  'EXT Oscillator'
Define CLOCK_FREQUENCY = 8
AllDigital

'---------------------______   _____
'--------------------(     (__)     )---------------------
'RESET       \MCLR O (1           40) O RB7   LCD_DATA
'--------------------(              )---------------------
'SPARE         RA0 O (2    1      39) O RB6   LCD_DATA
'--------------------(              )---------------------
'SPARE         RA1 O (3    6      38) O RB5   LCD_DATA
'--------------------(              )---------------------
'SPARE         RA2 O (4    F      37) O RB4   LCD_DATA
'--------------------(              )---------------------
'SPARE         RA3 O (5    8      36) O RB3   LCD_EBIT
'--------------------(              )---------------------
'SPARE         RA4 O (6    7      35) O RB2   LCD_RWBIT
'--------------------(              )---------------------
'SPARE         RA5 O (7    7      34) O RB1   LCD_RSBIT
'--------------------(              )---------------------
'SPARE         RE0 O (8    A      33) O RB0   INTERRUPT
'--------------------(              )---------------------
'SPARE         RE1 O (9           32) O VDD   +5V
'--------------------(              )---------------------
'SPARE         RE2 O (10          31) O VSS   0V
'--------------------(              )---------------------
'+5V           VDD O (11          30) O RD7   AD9850   D7
'--------------------(              )---------------------
'0V            VSS O (12          29) O RD6   AD9850   D6
'--------------------(              )---------------------
'----------[   OSC O (13          32) O RD5   AD9850   D5
'-16 MHZ??           (              )---------------------
'----------[   OSC O (14          31) O RD4   AD9850   D4
'--------------------(              )---------------------
'ENC_A         RC0 O (15          26) O RC7   SPARE
'--------------------(              )---------------------
'ENC_B         RC1 O (16          25) O RC6   AD9850   FQ_UD
'--------------------(              )---------------------
'STEP          RC2 O (17          24) O RC5   AD9850   W_CLK
'--------------------(              )---------------------
'MODE          RC3 O (18          23) O RC4   AD9850   RESET
'--------------------(              )---------------------
'AD9850   D0   RD0 O (19          22) O RD3   AD9850   D3
'--------------------(              )---------------------
'AD9850   D1   RD1 O (20          21) O RD2   AD9850   D2
'--------------------(______________)---------------------

'--------------------------------------------------
'variables
'----------------------------------------------------

Dim duty As Byte


startup:

'----------------------------------------------------------------
'MAIN BODY
'----------------------------------------------------------------

loop:
PWMon 1, 9
WaitMs 10
While duty < 255  'As Long As i < 255;
    duty = duty + 1  'increment i with 1;
    PWMduty 1, duty
    WaitMs 5  'delay;
Wend
'PWMoff 1
'WaitMs 10

'PWMon 1, 9
'WaitMs 10

While duty > 0  'As Long As duty > 0;
    duty = duty - 1  'increment i with 1;
    PWMduty 1, duty
    WaitMs 5  'delay;
Wend

PWMoff 1
WaitMs 500
Goto loop
End
 
Ok after a little more research it looks like the TLC5940 is the answer.

Does anyone have any sample code for controlling this chip?

Cheers - Paul
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top