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.

using PWM to dim LED NEON STRIP

MrDEB

Well-Known Member
couldn't locate this thread but here is the issue
I breadboarded this circuit and it seems to work driving just an LED but I am driving a 12v led neon strip.
The circuit flashes the strip slowly to fast as per pot adjustment.
The 555 circuit works as planned with one LED (it is supposed to change the duty cycle
Thinking the two different supply voltages has something but what to do? Any suggestions?
NOTE THE 7555 IS POWERED BY THE pic
the MOSFET is logic level
 

Attachments

  • dimming circuit brd.png
    dimming circuit brd.png
    89.4 KB · Views: 490
Is it Groundhog Day already?
 
It's not really important if you think that's what I posted or not.

The code uses software pwm, so as long as TMR2 has the same layout it should work with pretty much any of the 18F's
 
I didn't add anything to the first suggestion on code,
Post #58 has the 18f2221
I didn't even start on this code??
The attached PDF is a file compare between the code in post #58 and the code in post #114. The only change I made was to turn everything into lower case. The gold highlights show changes. The green highlights show additions. Hmmm. Wonder where those additions came from? So weird.
 

Attachments

  • file compare.pdf
    70.2 KB · Views: 161
The attached PDF is a file compare between the code in post #58 and the code in post #114. The only change I made was to turn everything into lower case. The gold highlights show changes. The green highlights show additions. Hmmm. Wonder where those additions came from? So weird.
Are you here to help or here to be easily offended by a non-consequential comment?
1695960096946.gif
 
Here's how to adapt the code from post #58 to the new schematic in post #112.

First, since there are only three pots to adjust the pwm and 16 outputs, you have to decide which pot will adjust which output. In the following I used POT1 and POT2 to adjust the PWM1-PWM8 outputs on PORTA, and POT3 to adjust the LED1-LED8 outputs on PORTC. You can change this around as you like.

1 - add definitions for all 16 outputs, PWM1-PWM8 and LED1-LED8
Code:
// PWM outputs  (controlled by POT1 and POT2)
dim
    PWM1 as PORTA.0,    // controlled by POT1
    PWM2 as PORTA.1,    // controlled by POT2
    PWM3 as PORTA.2,    // controlled by POT1
    PWM4 as PORTA.3,    // controlled by POT2
    PWM5 as PORTA.4,    // controlled by POT1
    PWM6 as PORTA.5,    // controlled by POT2
    PWM7 as PORTA.6,    // controlled by POT1
    PWM8 as PORTA.7     // controlled by POT2

// LED PWM outputs (all controlled by POT3)
dim
    LED1 as PORTC.0,
    LED2 as PORTC.1,
    LED3 as PORTC.2,
    LED4 as PORTC.3,
    LED5 as PORTC.4,
    LED6 as PORTC.5,
    LED7 as PORTC.6,
    LED8 as PORTC.7

2 - add pin initialization code to InitIO
Code:
    // set outputs (low to start)
    low(PWM1)
    low(PWM2)
    low(PWM3)
    low(PWM4)
    low(PWM5)
    low(PWM6)
    low(PWM7)
    low(PWM8)

    low(LED1)
    low(LED2)
    low(LED3)
    low(LED4)
    low(LED5)
    low(LED6)
    low(LED7)
    low(LED8)

3 - add code to the tmr2_isr interrupt handler to set the outputs based on which pot they're controlled by
Code:
    // outputs controlled by POT1
    if (pwm_period >= pwm1_duty) then
        PWM1 = 0
        PWM3 = 0
        PWM5 = 0
        PWM7 = 0
    else
        PWM1 = 1
        PWM3 = 1
        PWM5 = 1
        PWM7 = 1
    endif
    // outputs controlled by POT2
    if (pwm_period >= pwm2_duty) then
        PWM2 = 0
        PWM4 = 0
        PWM6 = 0
        PWM8 = 0
    else
        PWM2 = 1
        PWM4 = 1
        PWM6 = 1
        PWM8 = 1
    endif
    // outputs controlled by POT3
    if (pwm_period >= pwm3_duty) then
        LED1 = 0
        LED2 = 0
        LED3 = 0
        LED4 = 0
        LED5 = 0
        LED6 = 0
        LED7 = 0
        LED8 = 0
    else
        LED1 = 1
        LED2 = 1
        LED3 = 1
        LED4 = 1
        LED5 = 1
        LED6 = 1
        LED7 = 1
        LED8 = 1
    endif

Putting all that together you end up with:
Code:
// Swordfish BASIC sixteen channel software PWM using TMR2 and 3 pot ADC inputs
device = 18F2221
clock = 32

include "intosc.bas"
// do NOT include setdigitalio
// to use PORTB for the ADC all pins must be in analog mode due to the way
// these old pics map ADC inputs

include "adc.bas"

// ADC pot inputs
// used to set the PWM duty cycle for PWM1-PWM8 and LED1-LED8
// connect pot upper lug = VDD, lower lug = GND, wiper = port IO
dim
    POT1 as PORTB.0,    // RB0/AN12
    POT2 as PORTB.1,    // RB1/AN10
    POT3 as PORTB.2     // RB2/AN8

// ADC channels
const
    CH_POT1 = 12,       // AN12
    CH_POT2 = 10,       // AN10
    CH_POT3 = 8         // AN8
 
// PWM outputs  (controlled by POT1 and POT2)
dim
    PWM1 as PORTA.0,    // controlled by POT1
    PWM2 as PORTA.1,    // controlled by POT2
    PWM3 as PORTA.2,    // controlled by POT1
    PWM4 as PORTA.3,    // controlled by POT2
    PWM5 as PORTA.4,    // controlled by POT1
    PWM6 as PORTA.5,    // controlled by POT2
    PWM7 as PORTA.6,    // controlled by POT1
    PWM8 as PORTA.7     // controlled by POT2

// LED PWM outputs (all controlled by POT3)
dim
    LED1 as PORTC.0,
    LED2 as PORTC.1,
    LED3 as PORTC.2,
    LED4 as PORTC.3,
    LED5 as PORTC.4,
    LED6 as PORTC.5,
    LED7 as PORTC.6,
    LED8 as PORTC.7 

// pwm duty cycles (from ADC) 0=min, 255=max
dim
    pwm1_duty as byte,
    pwm2_duty as byte,
    pwm3_duty as byte

dim pwm_period as byte

// pwm timer TMR2
dim
    TMR2IF as PIR1.bits(1),
    TMR2IE as PIE1.bits(1),
    TMR2ON as T2CON.bits(2)
 
// set IO pin directions and initial settings
sub InitIO()
    // set inputs
    input(POT1)
    input(POT2)
    input(POT3)
 
    // set outputs (low to start)
    low(PWM1)
    low(PWM2)
    low(PWM3)
    low(PWM4)
    low(PWM5)
    low(PWM6)
    low(PWM7)
    low(PWM8)

    low(LED1)
    low(LED2)
    low(LED3)
    low(LED4)
    low(LED5)
    low(LED6)
    low(LED7)
    low(LED8)
end sub

// pwm TMR2 interrupt
interrupt tmr2_isr()
    TMR2IF = 0   
    pwm_period = pwm_period + 1
    // outputs controlled by POT1
    if (pwm_period >= pwm1_duty) then
        PWM1 = 0
        PWM3 = 0
        PWM5 = 0
        PWM7 = 0
    else
        PWM1 = 1
        PWM3 = 1
        PWM5 = 1
        PWM7 = 1
    endif
    // outputs controlled by POT2
    if (pwm_period >= pwm2_duty) then
        PWM2 = 0
        PWM4 = 0
        PWM6 = 0
        PWM8 = 0
    else
        PWM2 = 1
        PWM4 = 1
        PWM6 = 1
        PWM8 = 1
    endif
    // outputs controlled by POT3
    if (pwm_period >= pwm3_duty) then
        LED1 = 0
        LED2 = 0
        LED3 = 0
        LED4 = 0
        LED5 = 0
        LED6 = 0
        LED7 = 0
        LED8 = 0
    else
        LED1 = 1
        LED2 = 1
        LED3 = 1
        LED4 = 1
        LED5 = 1
        LED6 = 1
        LED7 = 1
        LED8 = 1
    endif
end interrupt


main:
InitIO()

// ADC setup
ADCON1 = $00        // all pins set to analog mode, VREF = VDD/GND
ADCON2 = ADC.FRC    // ADC clock = Frc
ADC.ADFM = 0        // left justify (we only use the 8 MSB's)
ADC.SetAcqTime(100) // 100us delay

pwm_period = 0
pwm1_duty = 0
pwm2_duty = 0
pwm3_duty = 0

// setup pwm timer TMR2
// 25KHz = 40us/bit -> 40us x 256 = 10240us period, ~10ms period (100Hz)
T2CON = %00000001   // T2OUTPS<3:0>=%000 (1:1), TMR2ON=0, T2CKPS<1:0>=%01 (1:4)
PR2 = 176
TMR2 = 0
TMR2IF = 0
TMR2IE = 1
TMR2ON = 1

enable(tmr2_isr)

while (true)
    pwm1_duty = ADC.Read(CH_POT1) >> 8
    pwm2_duty = ADC.Read(CH_POT2) >> 8
    pwm3_duty = ADC.Read(CH_POT3) >> 8
end while

It shouldn't matter too much which 18F device you run this on, but you may have to adjust the CH_POT1-CH_POT3 adc channel constants and the TMR2IF/TMR2IE interrupt bit definitions if you use a more modern device.
 
Tumbleweed, you Sir are a Saint for the amount of effort you put into this. My sainthood has been revoked in favor of my sanity.
 
It's just easier this way... all the code was just sitting there already, so adding a few extra outputs was a no-brainer while waiting for the morning Java to kick in.

The comment in the code about not using SetAllDigital isn't 100% true. As long as the pins used for the pots are set as inputs they can be converted by the ADC. It's just that having them set to analog mode is more proper.
 
I'd use three buttons and one 4-bit encoder. Hold button to activate "pot1" and adjust encoder up or down until desired level. Then hold button 2, and adjust level. Reduces size and hardware. Software is cheap - and highly adaptable.
 
I'd use three buttons and one 4-bit encoder.

How about three buttons (or more) and one pot? Read the pot when the button is pressed and store the result in a variable.

As far as I recall, MrDEB has never used an encoder in any of his projects and it would likely require another 6+ page thread to make that work.
 
It was suggested to get a logic-level MOSFET
As for unused pins, I wanted some flexibility as to how bright the LED strip is without having to reprogram the pic to set the desired brightness of an LED strip.
I am going to do a more intense search for a better mosfet.
The 7555 smd chips etc are relatively cheap from Tayda Electronics and there are only 3 dimming circuits on the board.
Hopefully today I can attach the sign to the PC board.
If you want adaptive brightness, like that on cellphone screens, you should try a CdS cell and a 500K linear pot across the power supply, with the junction feeding the LEDs common feed. As for all the 555's on board, all could be eliminated by using the internal timer in the PIC.
One question: Are the R5-x resistors part of an array to reduce parts count?
 
you should try a CdS cell and a 500K linear pot across the power supply, with the junction feeding the LEDs common feed.
The LED common is the voltage, and there's quite a bit of current there. How would that work?

I know it's hard to follow these multi-page threads, but the latest schematic is in post #112 and all the 555's are gone. MrDEB smartened up and is using the PIC to do the timing. See post #127.
 
finally got back to this project. Have a schematic and PCboard designed and need to edit the barrier strip for only 3 positions. This is using Tumbleweeds suggestion and go without the 555. Really only need 3 dimmable outports but thinking MAYBE add some more as per post 127
 

Attachments

  • pwm board.jpg
    pwm board.jpg
    426.6 KB · Views: 148
  • pwm schematic.jpg
    pwm schematic.jpg
    345.7 KB · Views: 147
I got to get this project done BUT I discovered an error on my part as I need to sequencly turn leads off and on as well as 5 MOSFETs that do not need dimming. Thinking of MAYBE going back to my schematic as per post #135
here the code that Tumbleweed provided but I add for testing the last 3 lines of code which interfere with the dimming using PWM. am lost at this point. been testing the code for using the 555 timers but need to figure out why it doesn't work either.
Code:
{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2024 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 1/5/2024                                                       *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
// Swordfish BASIC three channel software PWM using TMR2 and ADC inputs
Device = 18F2221
Clock = 32

Include "intosc.bas"
// do NOT include setdigitalio
// to use PORTB for the ADC all pins must be in analog mode due to the way
// these old pics map ADC inputs

Include "adc.bas"

// ADC pot inputs
// used to set the PWM duty cycle for PWM1-PWM3
// connect pot upper lug = VDD, lower lug = GND, wiper = port IO
Dim
    POT1 As PORTB.0,    // RB0/AN12
    POT2 As PORTB.1,    // RB1/AN10
    POT3 As PORTB.2     // RB2/AN8

// ADC channels
Const
    CH_POT1 = 12,       // AN12
    CH_POT2 = 10,       // AN10
    CH_POT3 = 8         // AN8
 
// PWM outputs
Dim
    PWM1 As PORTA.5,
    PWM2 As PORTA.6,
    PWM3 As PORTA.7

// pwm duty cycles (from ADC) 0=min, 255=max
Dim
    pwm1_duty As Byte,
    pwm2_duty As Byte,
    pwm3_duty As Byte

Dim pwm_period As Byte

// pwm timer TMR2
Dim
    TMR2IF As PIR1.bits(1),
    TMR2IE As PIE1.bits(1),
    TMR2ON As T2CON.bits(2)
    
    
//non diming mosfets  FOR GLASS, LETTERING AND ICE CUBES
// THE RED STRAW AND ICE CUBES TO HAVE DIMMING
Dim Green_strip_0 As PORTA.0
Dim Green_strip_1 As PORTA.1
Dim Green_strip_2 As PORTA.2
Dim Green_strip_3 As PORTA.3
Dim Green_strip_4 As PORTA.4

 //LEDS ON PORTC
 Dim LED0 As PORTC.0  //USE FOR THE "GREEN STRAW INDICATORS"
 Dim LED1 As PORTC.1
 Dim LED2 As PORTC.2
 Dim LED3 As PORTC.3
 Dim LED4 As PORTC.4
 Dim LED5 As PORTC.5
 Dim LED6 As PORTC.6
 
 Dim X As Byte
 
 
// set IO pin directions and initial settings
Sub InitIO()
    // set inputs
    Input(POT1)
    Input(POT2)
    Input(POT3)
 
    // set outputs (low to start)
    Low(PWM1)
    Low(PWM2)
    Low(PWM3)
End Sub

// pwm TMR2 interrupt
Interrupt tmr2_isr()
    TMR2IF = 0   
    pwm_period = pwm_period + 1
    If (pwm_period >= pwm1_duty) Then
        PWM1 = 0
    Else
        PWM1 = 1
    EndIf
    If (pwm_period >= pwm2_duty) Then
        PWM2 = 1
    Else
        PWM2 = 0
    EndIf
    If (pwm_period >= pwm3_duty) Then
        PWM3 = 1
    Else
        PWM3 = 0
    EndIf
End Interrupt


main:
InitIO()
PORTC = %11111111    // all on for testing
PORTA.0 = 1
PORTA.1 = 1
PORTA.2 = 1
PORTA.3 = 1
PORTA.4 = 1
PORTB.3 = 1
PORTB.4 = 1
PORTB.5 = 1

// ADC setup
ADCON1 = $00        // all pins set to analog mode, VREF = VDD/GND
ADCON2 = ADC.FRC    // ADC clock = Frc
ADC.ADFM = 0        // left justify (we only use the 8 MSB's)
ADC.SetAcqTime(100) // 100us delay

pwm_period = 0
pwm1_duty = 0
pwm2_duty = 0
pwm3_duty = 0

// setup pwm timer TMR2
// 25KHz = 40us/bit -> 40us x 256 = 10240us period, ~10ms period (100Hz)
T2CON = %00000001   // T2OUTPS<3:0>=%000 (1:1), TMR2ON=0, T2CKPS<1:0>=%01 (1:4)
PR2 = 176
TMR2 = 0
TMR2IF = 0
TMR2IE = 1
TMR2ON = 1

Enable(tmr2_isr)

While (true)
For X = 0 To 7
    pwm1_duty = ADC.Read(CH_POT1) >> 8     //porta.5  pot b.o
    pwm2_duty = ADC.Read(CH_POT2) >> 8     //porta.6   pot b.1
    pwm3_duty = ADC.Read(CH_POT3) >> 8     //porta.7    pot b.2
    Next
    Green_strip_0  = 1      //for testing only
    DelayMS(3000)
    Green_strip_0  = 0

End While
 
- you never set PORTA.0-PORTA.4 to outputs
- you never set PORTB.3-PORTB.5 to outputs
- you never set PORTC.0-PORTC.6 to outputs
That means this:
Code:
PORTC = %11111111    // all on for testing
PORTA.0 = 1
PORTA.1 = 1
PORTA.2 = 1
PORTA.3 = 1
PORTA.4 = 1
PORTB.3 = 1
PORTB.4 = 1
PORTB.5 = 1
does absolutely nothing

- the 'for x = 0 to 7... next' loop does almost nothing except waste time
- the added 'delayMS(3000)' will make trying to adjust the pots a very frustrating experience
 
Well it works ok but now I need to add in several leds toggling along with several mofets. going to try inserting a timer interrupt or a long for next loop instead of adding DELAYMS( )
 
Here's one way to take the code from post #127 and make the outputs programmable (schematic in post #112)
The outputs are still dimmable via the pots...
Code:
// Swordfish BASIC sixteen channel software PWM using TMR2 and 3 pot ADC inputs
// schematic https://www.electro-tech-online.com/threads/using-pwm-to-dim-led-neon-strip.165067 post #112
// v2 - programmable outputs
device = 18F2221
clock = 32

include "intosc.bas"
// do NOT include setdigitalio
// to use PORTB for the ADC all pins must be in analog mode due to the way
// these old pics map ADC inputs

include "adc.bas"

// ADC pot inputs
// used to set the PWM duty cycle for PWM1-PWM8 and LED1-LED8
// connect pot upper lug = VDD, lower lug = GND, wiper = port IO
dim
    POT1 as PORTB.0,    // RB0/AN12
    POT2 as PORTB.1,    // RB1/AN10
    POT3 as PORTB.2     // RB2/AN8

// ADC channels
const
    CH_POT1 = 12,       // AN12
    CH_POT2 = 10,       // AN10
    CH_POT3 = 8         // AN8
 
// PWM outputs  (controlled by POT1 and POT2)
dim
    PWM1 as PORTA.0,    // controlled by POT1
    PWM2 as PORTA.1,    // controlled by POT2
    PWM3 as PORTA.2,    // controlled by POT1
    PWM4 as PORTA.3,    // controlled by POT2
    PWM5 as PORTA.4,    // controlled by POT1
    PWM6 as PORTA.5,    // controlled by POT2
    PWM7 as PORTA.6,    // controlled by POT1
    PWM8 as PORTA.7     // controlled by POT2

// LED PWM outputs (all controlled by POT3)
dim
    LED1 as PORTC.0,
    LED2 as PORTC.1,
    LED3 as PORTC.2,
    LED4 as PORTC.3,
    LED5 as PORTC.4,
    LED6 as PORTC.5,
    LED7 as PORTC.6,
    LED8 as PORTC.7 

// this structure holds the on-off state of the pwm and led outputs
// to turn an output on, set it to 1 (ie 'vPORTS.vPWM2 = 1')
// to turn an output off, set it to 0 (ie 'vPORTS.vPWM2 = 0')
// dimming for all outputs is still controlled by the pots
structure vPORT_t
    vPWM as byte
    vLED as byte

    vPWM1 as vPWM.bits(0)       // PWM1-PWM8 settings
    vPWM2 as vPWM.bits(1)
    vPWM3 as vPWM.bits(2)
    vPWM4 as vPWM.bits(3)
    vPWM5 as vPWM.bits(4)
    vPWM6 as vPWM.bits(5)
    vPWM7 as vPWM.bits(6)
    vPWM8 as vPWM.bits(7)
    
    vLED1 as vLED.bits(0)       // LED1-LED8 settings
    vLED2 as vLED.bits(1)
    vLED3 as vLED.bits(2)
    vLED4 as vLED.bits(3)
    vLED5 as vLED.bits(4)
    vLED6 as vLED.bits(5)
    vLED7 as vLED.bits(6)
    vLED8 as vLED.bits(7)
end structure
dim vPORTS as vPORT_t

// pwm duty cycles (from ADC) 0=min, 255=max
dim
    pwm1_duty as byte,
    pwm2_duty as byte,
    pwm3_duty as byte

dim pwm_period as byte

// pwm timer TMR2
dim
    TMR2IF as PIR1.bits(1),
    TMR2IE as PIE1.bits(1),
    TMR2ON as T2CON.bits(2)
 
// set IO pin directions and initial settings
sub InitIO()
    // set inputs
    input(POT1)
    input(POT2)
    input(POT3)
 
    // set outputs (low to start)
    low(PWM1)
    low(PWM2)
    low(PWM3)
    low(PWM4)
    low(PWM5)
    low(PWM6)
    low(PWM7)
    low(PWM8)

    low(LED1)
    low(LED2)
    low(LED3)
    low(LED4)
    low(LED5)
    low(LED6)
    low(LED7)
    low(LED8)

    // set all the variable states to low (off)
    clear(vPORTS)
end sub

// pwm TMR2 interrupt
interrupt tmr2_isr()
    TMR2IF = 0   
    pwm_period = pwm_period + 1
    // outputs controlled by POT1
    if (pwm_period >= pwm1_duty) then   // set outputs off
        PWM1 = 0
        PWM3 = 0
        PWM5 = 0
        PWM7 = 0
    else                                // set outputs to current variable setting
        PWM1 = vPORTS.vPWM1
        PWM3 = vPORTS.vPWM3
        PWM5 = vPORTS.vPWM5
        PWM7 = vPORTS.vPWM7
    endif
    // outputs controlled by POT2
    if (pwm_period >= pwm2_duty) then   // set outputs off
        PWM2 = 0
        PWM4 = 0
        PWM6 = 0
        PWM8 = 0
    else                                // set outputs to current variable setting
        PWM2 = vPORTS.vPWM2
        PWM4 = vPORTS.vPWM4
        PWM6 = vPORTS.vPWM6
        PWM8 = vPORTS.vPWM8
    endif
    // outputs controlled by POT3
    if (pwm_period >= pwm3_duty) then   // set outputs off
        LED1 = 0
        LED2 = 0
        LED3 = 0
        LED4 = 0
        LED5 = 0
        LED6 = 0
        LED7 = 0
        LED8 = 0
    else                                // set outputs to current variable setting
        LED1 = vPORTS.vLED1
        LED2 = vPORTS.vLED2
        LED3 = vPORTS.vLED3
        LED4 = vPORTS.vLED4
        LED5 = vPORTS.vLED5
        LED6 = vPORTS.vLED6 
        LED7 = vPORTS.vLED7
        LED8 = vPORTS.vLED8
    endif
end interrupt


main:
InitIO()

// ADC setup
ADCON1 = $00        // all pins set to analog mode, VREF = VDD/GND
ADCON2 = ADC.FRC    // ADC clock = Frc
ADC.ADFM = 0        // left justify (we only use the 8 MSB's)
ADC.SetAcqTime(100) // 100us delay

pwm_period = 0
pwm1_duty = 0
pwm2_duty = 0
pwm3_duty = 0

// setup pwm timer TMR2
// 25KHz = 40us/bit -> 40us x 256 = 10240us period, ~10ms period (100Hz)
T2CON = %00000001   // T2OUTPS<3:0>=%000 (1:1), TMR2ON=0, T2CKPS<1:0>=%01 (1:4)
PR2 = 176
TMR2 = 0
TMR2IF = 0
TMR2IE = 1
TMR2ON = 1

enable(tmr2_isr)

while (true)
    // read pots and set pwm duty cycle
    pwm1_duty = ADC.Read(CH_POT1) >> 8
    pwm2_duty = ADC.Read(CH_POT2) >> 8
    pwm3_duty = ADC.Read(CH_POT3) >> 8
    
    // to control an LED/PWM output, set the appropriate vPORTS
    // variable to 1 (on) or 0 (off)
    vPORTS.vPWM1 = 1
    vPORTS.vLED1 = 1
end while

The outputs will follow the settings of the vPORTS.vPWMx or vPORTS.vLEDx variables.

If you want to change it to make some of the outputs completely static (not controlled via the dimming pots),
then just comment out the line in the interrupt tmr2_isr() portion that turns that output off.
For example...
Code:
    // outputs controlled by POT1
    if (pwm_period >= pwm1_duty) then   // set outputs off
        PWM1 = 0
        'PWM3 = 0     // PWM3 output no longer dimmed
        PWM5 = 0
        PWM7 = 0
The timer2 ISR will still control turning the output on/off based on the setting of the vPORTS variables...
'vPORTS.vPWM3 = 1' to turn on PWM3 and 'vPORTS.vPWM3 = 0' to turn off PWM3
 

Latest threads

New Articles From Microcontroller Tips

Back
Top