Hello! I am confused about a simple problem. Program is designed for DC motor control with 2 buttons and 4 speeds. The program works perfectly, IF there is NO written instructions - set the LED on. If this instruction is written, then Normally not work the PWM off instruction. When switching from case_4 back to case_0 , the motor NOT shuts down - the instruction PWM off not work . LED set off running - LED goes out, but PWMoff doesnt work, the motor start running at full speed AS If They HAD jumped into the case_4. Please HELP! Thanks!
chip 12f683, 4
config osc=int
define down gpio.4
define up gpio.5
define LED gpio.1
dir gpio.4 in
dir gpio.5 in
dir gpio.1 out
dir gpio.2 out '' PWM out
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
now1=0
now2=0
prev1=0
prev2=0
full=0
sec=0
min=0
main:
if !down then '' filtrs
push_down++
Else
push_down=0
end if
if push_down=>200 then
speed=0
push_down=0
stoptimer 1
cleartimer 1
sec=0
min=0
full=0 ''
end if
now2= (push_down=30) & speed>0 ''front detection
if now2>prev2 then
speed --
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev2=now2
''==============================
if !up then
push_up++
Else
push_up=0
end if
now1= (push_up=30) & speed<4 ''front detection '
if now1>prev1 then
speed ++
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev1=now1
'===========================
select case speed
case 0
pwmoff
set LED off
''====================
case 1
hpwm 1,8, 170
''====================
case 2
hpwm 1,8, 185
''====================
case 3
hpwm 1,8, 200
''===='========================
case 4
hpwm 1,8, 255
starttimer 1
end select
set LED on '' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
''===============
wait 5 ms
goto main
''==========
sub timer
full++
if full=2 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
''hours++
min=0
end if
if sec=>5&min=8 then
speed=2
sec=0
min=0
full=0
stoptimer 1
cleartimer 1
end if
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium , I wrote a program code completely! I have an exclamation mark on SET LED ON! If write this instruction, then program does not work normally.
I just not written # before define.
I've been following this with humor..Wow! Talk about pulling teeth! Or at least it seems that a large ViseGrip plier will be needed to extract that tooth. :-)
Joking aside, it's not surprising that there might be confusion between the SynWrite version and the GCB Compiler. Initially I didn't understand that either. ;-)
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After looking at your schematic I see you've filtered the 24V bus with 1000uF cap. I think you'd be well advised to also bypass it with a 0.1uF for spike supression that that 1000uF won't bypass.
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I solved! Change is a hpwm location. the duty cycle is the variable - level.
now working! Thank you all!
chip 12f683, 4
config osc=int
define down gpio.4
define up gpio.5
define LED gpio.1
dir gpio.4 in
dir gpio.5 in
dir gpio.1 out
dir gpio.2 out '' PWM out
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
now1=0
now2=0
prev1=0
prev2=0
level=0
full=0
sec=0
min=0
main:
if !down then '' filtrs
push_down++
Else
push_down=0
end if
if push_down=>200 then
speed=0
push_down=0
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
now2= (push_down=30) & speed>0 ''front detection
if now2>prev2 then
speed --
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev2=now2
''==============================
if !up then
push_up++
Else
push_up=0
end if
now1= (push_up=30) & speed<4 ''front detection '
if now1>prev1 then
speed ++
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev1=now1
'===========================
select case speed
case 0
level=0
set LED off
''====================
case 1
level=170
''====================
case 2
level=185
''====================
case 3
level=200
''===='========================
case 4
level=255
starttimer 1
end select
set LED on '
''===============
hpwm 1,1, level
wait 5 ms
goto main
''==========
sub timer
full++
if full=2 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
''hours++
min=0
end if
if sec=>5&min=8 then
speed=2
sec=0
min=0
full=0
stoptimer 1
cleartimer 1
end if
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William did tell me this was the potential issue but you removed before he/we could post.
Let me update the Help but PMWOff relates to use of PWMOn. Do not use PWMOff in the context of HWPWM as things will not work as you expect - as you found.
I will review the Help and inprove. We need clarity around use of the software PWM routines, PWMOn|PMWOff amd HWPWM. These are three different methods.
Sorry for not spotting when you first posted.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Janis, I'm glad to read that you fixed the problem. I'm new to GCB but not to the Basic language in general. I didn't see any glaring error in your original code that would acount for the PWM failing simply because a line of code brings a GPIO pin high to turn on a LED.
When Anobium posted: "This code works in a simulator. So, I am puzzled what to advise." I wondered what would be different in a live ciruit? So I grabbed at straws when I commented about the 0.1uF cap.
That said you really can't have too much spike suppression and 1000uF electro's have an ESR far to high to be relied on for suppressing fast rising spikes.
Now I have to read through your code again, so I too can understand why your original code failed because it still escapes me.
Speaking of which,.. it would be nice to have an "Insert Code" option included in the message tool bar. It will make reading pasted code much easier to read.
Good luck,
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Speaking of which,.. it would be nice to have an "Insert Code" option included in the message tool bar. It will make reading pasted code much easier to read.
There is - it is the "<""/"">" symbol.
It inserts "~~~", without the quotes, as the start and end of the code block.
You can then post formated code between like this:
Dim GCB As String
Dim ChrisR as String
Private Sub Command1_Click()
GCB = "I love Great Cow Basic"
ChrisR = " and Chris Roper too!"
Me.Print GCB & ChrisR
End Sub
Damn, I'm 70 years old but I thought my eyes were still working. Guess not! Either that or brain farts are becoming way too common!
Thank you!
Chris S.
Last edit: CDRIVE 2016-11-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm sorry that I do not use the box - insert code! I hope that everyone saw and understood the problem and solution? CDRIVE - you are 70 years old? Your hobby is the GCB and microcontrollers? All due respect to you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello! I am confused about a simple problem. Program is designed for DC motor control with 2 buttons and 4 speeds. The program works perfectly, IF there is NO written instructions - set the LED on. If this instruction is written, then Normally not work the PWM off instruction. When switching from case_4 back to case_0 , the motor NOT shuts down - the instruction PWM off not work . LED set off running - LED goes out, but PWMoff doesnt work, the motor start running at full speed AS If They HAD jumped into the case_4. Please HELP! Thanks!
chip 12f683, 4
config osc=int
define down gpio.4
define up gpio.5
define LED gpio.1
dir gpio.4 in
dir gpio.5 in
dir gpio.1 out
dir gpio.2 out '' PWM out
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
now1=0
now2=0
prev1=0
prev2=0
full=0
sec=0
min=0
main:
if !down then '' filtrs
push_down++
Else
push_down=0
end if
if push_down=>200 then
speed=0
push_down=0
stoptimer 1
cleartimer 1
sec=0
min=0
full=0 ''
end if
now2= (push_down=30) & speed>0 ''front detection
if now2>prev2 then
speed --
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev2=now2
''==============================
if !up then
push_up++
Else
push_up=0
end if
now1= (push_up=30) & speed<4 ''front detection '
if now1>prev1 then
speed ++
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev1=now1
'===========================
select case speed
case 0
pwmoff
set LED off
''====================
case 1
hpwm 1,8, 170
''====================
case 2
hpwm 1,8, 185
''====================
case 3
hpwm 1,8, 200
''===='========================
case 4
hpwm 1,8, 255
starttimer 1
end select
set LED on '' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
''===============
wait 5 ms
goto main
''==========
sub timer
full++
if full=2 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
''hours++
min=0
end if
if sec=>5&min=8 then
speed=2
sec=0
min=0
full=0
stoptimer 1
cleartimer 1
end if
end sub
Please read https://sourceforge.net/p/gcbasic/discussion/579126/thread/b1d3c9ee/#e1c8
It is tough without this key information.
Please read https://sourceforge.net/p/gcbasic/discussion/579126/thread/b1d3c9ee/#e1c8
It is tough without this key information.
Anobium , I wrote a program code completely! I have an exclamation mark on SET LED ON! If write this instruction, then program does not work normally.
I just not written # before define.
Look at the url I posted. We need version info before we can help. What version etc?
GCB SynWrite 6.19.2150
Which compiler version ? V0.95.010?
Yes Anobium!! You mean the problem is with the compiler?
I've been following this with humor..Wow! Talk about pulling teeth! Or at least it seems that a large ViseGrip plier will be needed to extract that tooth. :-)
Joking aside, it's not surprising that there might be confusion between the SynWrite version and the GCB Compiler. Initially I didn't understand that either. ;-)
Chris
I have compiled and reviewd. At the moment i see nothing concerning.
Do you have. access to a debugger? Then, you can walk the code line by line.
I have no jokes. simple program does not work! where is the error? I do not have good knowledge of English, but the program code I wrote. :(
Try the following.
... comment out the set led on
... replace with NOP, test
.... add another NOP,,test
.... add another NOP, and test.
I am trying to figure out if you have a page related error.
This code works in a simulator. So, I am puzzled what to advise.
This code works in a simulator. So, I am puzzled what to advise.
After looking at your schematic I see you've filtered the 24V bus with 1000uF cap. I think you'd be well advised to also bypass it with a 0.1uF for spike supression that that 1000uF won't bypass.
Chris
@Janis
I will try to replicate later today. That's about 8 hours from now ( 2:AM CST) Have your meter and scope ready.
I think The Scheme is not the problem. How can a simple instruction to Cause Interference? Just turn on the LED!
I think The Scheme is not the problem. How can a simple instruction to Cause Interference? Just turn on the LED!
I solved! Change is a hpwm location. the duty cycle is the variable - level.
now working! Thank you all!
chip 12f683, 4
config osc=int
define down gpio.4
define up gpio.5
define LED gpio.1
dir gpio.4 in
dir gpio.5 in
dir gpio.1 out
dir gpio.2 out '' PWM out
inittimer1 osc, ps1_8
on interrupt timer1overflow call timer
now1=0
now2=0
prev1=0
prev2=0
level=0
full=0
sec=0
min=0
main:
if !down then '' filtrs
push_down++
Else
push_down=0
end if
if push_down=>200 then
speed=0
push_down=0
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
now2= (push_down=30) & speed>0 ''front detection
if now2>prev2 then
speed --
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev2=now2
''==============================
if !up then
push_up++
Else
push_up=0
end if
now1= (push_up=30) & speed<4 ''front detection '
if now1>prev1 then
speed ++
stoptimer 1
cleartimer 1
sec=0
min=0
full=0
end if
prev1=now1
'===========================
select case speed
case 0
level=0
set LED off
''====================
case 1
level=170
''====================
case 2
level=185
''====================
case 3
level=200
''===='========================
case 4
level=255
starttimer 1
end select
set LED on '
''===============
hpwm 1,1, level
wait 5 ms
goto main
''==========
sub timer
full++
if full=2 then
sec++
full=0
end if
if sec>59 then
min++
sec=0
end if
if min>59 then
''hours++
min=0
end if
if sec=>5&min=8 then
speed=2
sec=0
min=0
full=0
stoptimer 1
cleartimer 1
end if
end sub
The root cause of this issue was the use PMWOff.
William did tell me this was the potential issue but you removed before he/we could post.
Let me update the Help but PMWOff relates to use of PWMOn. Do not use PWMOff in the context of HWPWM as things will not work as you expect - as you found.
I will review the Help and inprove. We need clarity around use of the software PWM routines, PWMOn|PMWOff amd HWPWM. These are three different methods.
Sorry for not spotting when you first posted.
Janis, I'm glad to read that you fixed the problem. I'm new to GCB but not to the Basic language in general. I didn't see any glaring error in your original code that would acount for the PWM failing simply because a line of code brings a GPIO pin high to turn on a LED.
When Anobium posted: "This code works in a simulator. So, I am puzzled what to advise." I wondered what would be different in a live ciruit? So I grabbed at straws when I commented about the 0.1uF cap.
That said you really can't have too much spike suppression and 1000uF electro's have an ESR far to high to be relied on for suppressing fast rising spikes.
Now I have to read through your code again, so I too can understand why your original code failed because it still escapes me.
Speaking of which,.. it would be nice to have an "Insert Code" option included in the message tool bar. It will make reading pasted code much easier to read.
Good luck,
Chris
There is - it is the "<""/"">" symbol.
It inserts "~~~", without the quotes, as the start and end of the code block.
You can then post formated code between like this:
If you look at the tool bar ther is a ? with the hover tip "Formating Help" it is worth a look.
Hope that helps,
Cheers
Chris
Last edit: Chris Roper 2016-11-30
Hi Chris. Do you mean like this?
Damn, I'm 70 years old but I thought my eyes were still working. Guess not! Either that or brain farts are becoming way too common!
Thank you!
Chris S.
Last edit: CDRIVE 2016-11-30
looks good to me.
I'm sorry that I do not use the box - insert code! I hope that everyone saw and understood the problem and solution? CDRIVE - you are 70 years old? Your hobby is the GCB and microcontrollers? All due respect to you!