Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I guess someone hasn't read all the posts and deciphered some that were instructive and some that were destructive as in off topic. I never posted my final code so how can you determine if nothing was learned. I myself learned alot about how a simple project can entail a massive amount of data to achieve results. By experimenting with different codes and tweek the codes to achieve desired results.
There is a word called inquisitive and imagination. If it doesn't work as desired then ask for suggestions and experiment with the suggestions.
This is what I have done from day one.
...I never posted my final code so how can you determine if nothing was learned....
{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Candle Code test using PWM
pwm W freq .bas
this one works but rev 2 does not have more than 1 port
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
Device = 18F13K22
Clock = 8
Include "osc1322.bas"
Include "RandGen.bas"
Include "Util1322.bas"
// import PWM module...
Include "PWM2.bas"
Const color(10) As Byte = (100, 70,65, 90,75,95,85, 60, 80, 85)
// local duty variable...
Dim Duty As Byte
Dim x As Word
Dim yellow As PORTC.5 ' yellow
Dim red As PORTC.4 ' red
Dim chC As PORTC.3
Dim chD As PORTC.2
// main program...
pwm.SetFreq(5000)
pwm.Start1
PSTRCON = $07 // sets all outputs
Output (yellow)
Output (red)
Output (chC)
Output (chD)
While true
Duty = 30
Repeat
pwm.SetDuty1Percent(Duty)
Inc(Duty)
DelayMS(5)
Until Duty > 100
Duty = 70
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(5)
Until Duty > 100
Duty = 60
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(15)
Until Duty > 100
Duty = 50
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(25)
Until Duty > 70
Duty = 30
Repeat
pwm.SetDuty1Percent(Duty)
Inc(Duty)
DelayMS(5)
Until Duty > 100
Duty = 70
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(5)
Until Duty > 90
Duty = 60
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(5)
Until Duty > 80
Duty = 50
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(15)
Until Duty > 70
Wend
{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Candle Code test using PWM
pwm W freq .bas
this one works but rev 2 does not have more than 1 port
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
Device = 18F13K22
Clock = 8
Include "osc1322.bas"
Include "RandGen.bas"
Include "Util1322.bas"
// import PWM module...
Include "PWM2.bas"
// local duty variable...
Dim Duty As Byte
Dim x As Word
Dim yellow As PORTC.5 ' yellow
Dim red As PORTC.4 ' red
Dim chC As PORTC.3
Dim chD As PORTC.2
// main program...
pwm.SetFreq(5000) '5000
pwm.Start1
PSTRCON = $0f
// sets all outputs
Output (yellow)
Output (red)
Output (chC)
Output (chD)
While true
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 1
//xxxxxxxxxxxxxxxxxx
Duty = 30
Repeat
pwm.SetDuty1Percent(Duty)
Inc(Duty) ' increase DUTY amount by one
DelayMS(5)
Until Duty > 100 ' when DUTY reaches 101 code continues to next " flicker"loop
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 2
//xxxxxxxxxxxxxxxxxx
Duty = 70 ' When the Duty reaches 101 then the DUTY is changed to 70
Repeat ' I found doing it this way avoided the BLINKING effect and made a SMOOTH
pwm.SetDuty1Percent(Duty) ' transition to the next flicker
Inc (Duty)
DelayMS(5)
Until Duty > 100
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 3
//xxxxxxxxxxxxxxxxxx
Duty = 60
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(15)
Until Duty > 100
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 4
//xxxxxxxxxxxxxxxxxx
Duty = 50
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(25)
Until Duty > 70
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 5
//xxxxxxxxxxxxxxxxxx
Duty = 30
Repeat
pwm.SetDuty1Percent(Duty)
Inc(Duty)
DelayMS(5)
Until Duty > 100
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 6
//xxxxxxxxxxxxxxxxxx
Duty = 70
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(5)
Until Duty > 90
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 7
//xxxxxxxxxxxxxxxxxx
Duty = 60
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(5)
Until Duty > 80
//xxxxxxxxxxxxxxxxxxxxxxxx
' flicker 8
//xxxxxxxxxxxxxxxxxx
Duty = 50
Repeat
pwm.SetDuty1Percent(Duty)
Inc (Duty)
DelayMS(15)
Until Duty > 70
Wend
Module pwm
Dim
FMaxDuty As Word,
FTMR2ON As T2CON.2
#if _device in (18F1220, 18F1320)
Dim FPWM1Pin As PORTB.3 // RB3 connected to CCP1 module
#elseif _device in (18F13K22)
Dim FPWM1Pin As PORTC.5 // RC5 connected to CCP1 module
Dim FPWM2Pin As PORTC.4
Dim FPWM3Pin As PORTC.3
#else
Dim FPWM1Pin As PORTC.2 // RC2 connected to CCP1 module
Dim FPWM2Pin As PORTC.1 // RC1 connected to CCP2 module
#endif
{
****************************************************************************
* Name : Start1 *
* Purpose : Start PWM Channel 1 *
****************************************************************************
}
Public Sub Start1()
CCP1CON = $0c ' $0c PWM mode P1A, P1C active high :P1B, P1D active high
Output(FPWM1Pin)
Output(FPWM2Pin)
Output(FPWM3Pin)
FTMR2ON = 1
End Sub
{