Hallo all!
I have a program with a PWM generator for RGB Led. PWM generators implemented using function- for. I need to pass the PWM generator subroutine and jump to another subroutine, if there is a short signal (~ 0.5 sec) from the input. At the bottom of the visible example of do not want to work. The signal from the input must be greater than 0.5 sec, and sometimes does not work. I wrote a small program.
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
stoptimer 1
cleartimer 1
define V_R PORTa.2
define V_G PORTa.4
define V_B PORTA.3
define K_R PORTb.0
define K_G PORTb.2
define K_B PORTb.1
define L_R PORTb.3
define L_G PORTb.5
define L_B PORTb.4
dir PORTA.2 out
dir PORTA.3 out
dir PORTA.4 out
dir PORTb.0 out
dir PORTb.1 out
dir PORTb.2 out
dir PORTb.3 out
dir PORTb.4 out
dir PORTb.5 out
define mic PORTA.1
define button PORTA.6
dir PORTA.1 in
dir PORTA.6 in
re=0
brightVR=0
brightKR=0
brightLR=0
if fast=1 & sec=>1 & sec<=6 then activity
if fast=1 & sec=>6 & sec<15 then RGB
if sec=>15 Then
stoptimer 1
cleartimer 1
standby
fast=0
sec=0
full=0
end if
goto main
sub activity
set V_R on
set K_B on
end sub
sub standby
set V_R off
set K_B off
end sub
sub RGB
for cnt1= 0 to 250 step 5
speed=6
call pwm
brightVB=cnt1
brightKB=cnt1
brightLB=cnt1
brightVG=0
brightKG=0
brightLG=0
brightVR=250-cnt1
brightKR=250-cnt1
brightLR=250-cnt1
??? if mic then exit for??????
next cnt2
''================
for cnt2= 0 to 250 step 5
speed=6
call pwm
brightVR=cnt2
brightKR=cnt2
brightLR=cnt2
??? if mic then exit for??????
next cnt1
end sub
sub pwm
for cyc=0 to speed
for re=0 to 255
if re<brightVR then set V_R on
if re=brightVR then set V_R off
if re<brightKR then set K_R on
if re=brightKR then set K_R off
if re<brightLR then set L_R on
if re=brightLR then set L_R off
''================================
if re<brightVG then set V_G on
if re=brightVG then set V_G off
if re<brightKG then set K_G on
if re=brightKG then set K_G off
if re<brightLG then set L_G on
if re=brightLG then set L_G off
''================================
if re<brightVB then set V_B on
if re=brightVB then set V_B off
if re<brightKB then set K_B on
if re=brightKB then set K_B off
if re<brightLB then set L_B on
if re=brightLB then set L_B off
next re
next cyc
end sub
sub timer
full++
if full=4 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
min=0
end if
end sub
In essence, when the mic = 1,need call sub active. mic = 1 ~ 0,5sec. but the problem is that in this way, as noted by question marks, does not jump out of the sub RGB. :(((
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just laid this out - so, I can read it. I see errors. These need correcting - see bold. There may be more.
So, what are you trying to to do? Are you wanting timer1 to overflow as some specific time period? There may be easier ways to do this. I will let others advise on the best method.
Anobium
#chip 16f88,8
'#option Explicit
#config osc=int
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
stoptimer 1
cleartimer 1
#define V_R PORTa.2
#define V_G PORTa.4
#define V_B PORTA.3
#define K_R PORTb.0
#define K_G PORTb.2
#define K_B PORTb.1
#define L_R PORTb.3
#define L_G PORTb.5
#define L_B PORTb.4
dir PORTA.2 out
dir PORTA.3 out
dir PORTA.4 out
dir PORTb.0 out
dir PORTb.1 out
dir PORTb.2 out
dir PORTb.3 out
dir PORTb.4 out
dir PORTb.5 out
#define mic PORTA.1
#define button PORTA.6
dir PORTA.1 in
dir PORTA.6 in
re=0
brightVR=0
brightKR=0
brightLR=0
brightVB=0
brightKB=0
brightLB=0
brightVG=0
brightKG=0
brightLG=0
fast=0
full=0
sec=0
min=0
main:
if mic=1 then fast=1
** if mic Then**
fast=1
full=0
sec=0
min=0
end if
if fast=1 then
starttimer 1
end if
if fast=1 & sec=>1 & sec<=6 then activity
if fast=1 & sec**=>**6 & sec<15 then RGB
if sec**=>**15 Then
stoptimer 1
cleartimer 1
standby
fast=0
sec=0
full=0
end if
goto main
sub activity
set V_R on
set K_B on
end sub
sub standby
set V_R off
set K_B off
end sub
sub RGB
for cnt1= 0 to 250 step 5
speed=6
call pwm
brightVB=cnt1
brightKB=cnt1
brightLB=cnt1
brightVG=0
brightKG=0
brightLG=0
brightVR=250-cnt1
brightKR=250-cnt1
brightLR=250-cnt1
' ??? if mic then exit for??????
next cnt2
''================
for cnt2= 0 to 250 step 5
speed=6
call pwm
brightVR=cnt2
brightKR=cnt2
brightLR=cnt2
' ??? if mic then exit for??????
next cnt1
end sub
sub pwm
for cyc=0 to speed
for re=0 to 255
if re<brightVR then set V_R on
if re=brightVR then set V_R off
if re<brightKR then set K_R on
if re=brightKR then set K_R off
if re<brightLR then set L_R on
if re=brightLR then set L_R off
''================================
if re<brightVG then set V_G on
if re=brightVG then set V_G off
if re<brightKG then set K_G on
if re=brightKG then set K_G off
if re<brightLG then set L_G on
if re=brightLG then set L_G off
''================================
if re<brightVB then set V_B on
if re=brightVB then set V_B off
if re<brightKB then set K_B on
if re=brightKB then set K_B off
if re<brightLB then set L_B on
if re=brightLB then set L_B off
next re
next cyc
end sub
sub timer
full++
if full=4 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
min=0
end if
** end sub**
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I need at a time when the subroutine RGB is called and a impuls from the mic, then jump out of the subroutine RGB and jump on subrotine - activity. Here I need use the function exit for, but in those places where there are marked with a question mark, exit for -not work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
??? if mic then exit for?????? that was real logic. Oh. @kent that is a good spot. I would not have understood that - I thought it was a code that did not compile. My err.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Trying to help. Can you simplify the code? The bare minimum. This is so I can understand what you trying to do (in the minumum code without all the vars etc). I truly do not understand what the outcome is.
I understand you have an issue but I need to understand the logic.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this example - when I press porta.1 then porta.2 will toggle only when cnt1 is not 250. This simple example works. And, porta.3 is high other times.
'
#chip 16f88,8
#config osc=int
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
stoptimer 1
cleartimer 1
dir porta.3 out
dir porta.2 out
dir porta.1 in
do forever
for cnt1 = 0 to 250 step 5
if porta.1 = 1 then
exit for
end if
Next
if cnt1 <> 250 then
porta.2 = !porta.2
else
porta.3 = !porta.3
end if
loop
sub Timer
timertt++
end sub
Is your port pull high (or low) - it is floating?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The signal on the "mic" pin needs to be of a sufficient stength and duration to reliably be detected. It might work better with the signal generating an interrupt.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hallo all!
I have a program with a PWM generator for RGB Led. PWM generators implemented using function- for. I need to pass the PWM generator subroutine and jump to another subroutine, if there is a short signal (~ 0.5 sec) from the input. At the bottom of the visible example of do not want to work. The signal from the input must be greater than 0.5 sec, and sometimes does not work. I wrote a small program.
Sub RGB
for cnt1 = 0 to 250 Step 5
speed = 6
call PWM
brightVB = cnt1
brightKB = cnt1
brightLB = cnt1
brightVG = 250-cnt1
brightKG = 250-cnt1
brightLG = 250-cnt1
brightVR = 250-cnt1
brightKR = 250-cnt1
brightLR = 250-cnt1
IF porta.1 = 1 then exit for
Next cnt2
'================
for cnt2 = 0 to 250 Step 5
speed = 6
call PWM
brightVR = cnt2
brightKR = cnt2
brightLR = cnt2
IF porta.1 = 1 then exit for
Next cnt1
end Sub
Really "for cnt xx = 0 to 250 Step 5" parts are many.
Love to help. See https://sourceforge.net/p/gcbasic/discussion/579126/thread/b1d3c9ee/#e1c8
What is PWM? Is this a sub? The the error is probably is that sub.
yess, PWM is a sub
sub pwm
for cyc=0 to speed
for re=0 to 255
if re<brightVR then set V_R on
if re=brightVR then set V_R off
if re<brightKR then set K_R on
if re=brightKR then set K_R off
if re<brightLR then set L_R on
if re=brightLR then set L_R off
''================================
if re<brightVG then set V_G on
if re=brightVG then set V_G off
if re<brightKG then set K_G on
if re=brightKG then set K_G off
if re<brightLG then set L_G on
if re=brightLG then set L_G off
''================================
if re<brightVB then set V_B on
if re=brightVB then set V_B off
if re<brightKB then set K_B on
if re=brightKB then set K_B off
if re<brightLB then set L_B on
if re=brightLB then set L_B off
next re
next cyc
end sub
ok, i later will write all code.
Please.program code in a simplified form:
chip 16f88,8
config osc=int
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
stoptimer 1
cleartimer 1
define V_R PORTa.2
define V_G PORTa.4
define V_B PORTA.3
define K_R PORTb.0
define K_G PORTb.2
define K_B PORTb.1
define L_R PORTb.3
define L_G PORTb.5
define L_B PORTb.4
dir PORTA.2 out
dir PORTA.3 out
dir PORTA.4 out
dir PORTb.0 out
dir PORTb.1 out
dir PORTb.2 out
dir PORTb.3 out
dir PORTb.4 out
dir PORTb.5 out
define mic PORTA.1
define button PORTA.6
dir PORTA.1 in
dir PORTA.6 in
re=0
brightVR=0
brightKR=0
brightLR=0
brightVB=0
brightKB=0
brightLB=0
brightVG=0
brightKG=0
brightLG=0
fast=0
full=0
sec=0
min=0
main:
if mic=1 then fast=1
if mic Then
fast=1
full=0
sec=0
min=0
end if
if fast=1 then
starttimer 1
end if
if fast=1 & sec=>1 & sec<=6 then activity
if fast=1 & sec=>6 & sec<15 then RGB
if sec=>15 Then
stoptimer 1
cleartimer 1
standby
fast=0
sec=0
full=0
end if
goto main
sub activity
set V_R on
set K_B on
end sub
sub standby
set V_R off
set K_B off
end sub
sub RGB
for cnt1= 0 to 250 step 5
speed=6
call pwm
brightVB=cnt1
brightKB=cnt1
brightLB=cnt1
brightVG=0
brightKG=0
brightLG=0
brightVR=250-cnt1
brightKR=250-cnt1
brightLR=250-cnt1
??? if mic then exit for??????
next cnt2
''================
for cnt2= 0 to 250 step 5
speed=6
call pwm
brightVR=cnt2
brightKR=cnt2
brightLR=cnt2
??? if mic then exit for??????
next cnt1
end sub
sub pwm
for cyc=0 to speed
for re=0 to 255
if re<brightVR then set V_R on
if re=brightVR then set V_R off
if re<brightKR then set K_R on
if re=brightKR then set K_R off
if re<brightLR then set L_R on
if re=brightLR then set L_R off
''================================
if re<brightVG then set V_G on
if re=brightVG then set V_G off
if re<brightKG then set K_G on
if re=brightKG then set K_G off
if re<brightLG then set L_G on
if re=brightLG then set L_G off
''================================
if re<brightVB then set V_B on
if re=brightVB then set V_B off
if re<brightKB then set K_B on
if re=brightKB then set K_B off
if re<brightLB then set L_B on
if re=brightLB then set L_B off
next re
next cyc
end sub
sub timer
full++
if full=4 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
min=0
end if
end sub
In essence, when the mic = 1,need call sub active. mic = 1 ~ 0,5sec. but the problem is that in this way, as noted by question marks, does not jump out of the sub RGB. :(((
This does not compile. Too many errors. Can you post as an attachment?
And, please indent your code. Give us a chance to understand the structure of the code from the logical indents.
Also, some comments may help our understanding of the issue.
I just laid this out - so, I can read it. I see errors. These need correcting - see bold. There may be more.
So, what are you trying to to do? Are you wanting timer1 to overflow as some specific time period? There may be easier ways to do this. I will let others advise on the best method.
Anobium
I need at a time when the subroutine RGB is called and a impuls from the mic, then jump out of the subroutine RGB and jump on subrotine - activity. Here I need use the function exit for, but in those places where there are marked with a question mark, exit for -not work.
Use equates when evaluating the variable, so "If mic = 1 Then", which is what Anobium could have been inferring?
??? if mic then exit for?????? that was real logic. Oh. @kent that is a good spot. I would not have understood that - I thought it was a code that did not compile. My err.
So , at the time when the subroutine RGB is active , if there is the signal from the input mic, then need jump out of the subroutine RGB.
Yes.
IF mic = 1 then fast = 1 is redundant, but it does not interfere
Trying to help. Can you simplify the code? The bare minimum. This is so I can understand what you trying to do (in the minumum code without all the vars etc). I truly do not understand what the outcome is.
I understand you have an issue but I need to understand the logic.
Anobium
Yes.
'Port is high
IF mic = 1 then exit for
But it does not work !!!
Please... !!! = not happy. Really trying to help.
In this example - when I press porta.1 then porta.2 will toggle only when cnt1 is not 250. This simple example works. And, porta.3 is high other times.
Is your port pull high (or low) - it is floating?
The signal on the "mic" pin needs to be of a sufficient stength and duration to reliably be detected. It might work better with the signal generating an interrupt.
exit for - in my case sometimes works only if the mic port is high more than 2 seconds.
But in my case, a mic port is high in only 0.5 sec
David
"It might work better with the signal generating an interrupt."
how to realize the program code, please help?
What a great idea. Do a search in the Demos folder of your installation for 'interrupts". There are many good examples.
Thanks!!!