Menu

program malfunctioning

Help
JANIS
2016-11-29
2016-12-02
1 2 > >> (Page 1 of 2)
  • JANIS

    JANIS - 2016-11-29

    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

     
  • JANIS

    JANIS - 2016-11-29

    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.

     
  • Anobium

    Anobium - 2016-11-29

    Look at the url I posted. We need version info before we can help. What version etc?

     
  • JANIS

    JANIS - 2016-11-29

    GCB SynWrite 6.19.2150

     
    • Anobium

      Anobium - 2016-11-29

      Which compiler version ? V0.95.010?

       
  • JANIS

    JANIS - 2016-11-29

    Yes Anobium!! You mean the problem is with the compiler?

     
  • CDRIVE

    CDRIVE - 2016-11-29

    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

     
  • Anobium

    Anobium - 2016-11-29

    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.

     
  • JANIS

    JANIS - 2016-11-29

    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. :(

     
    • Anobium

      Anobium - 2016-11-29

      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.

       
  • Anobium

    Anobium - 2016-11-29

    This code works in a simulator. So, I am puzzled what to advise.

     
  • Anobium

    Anobium - 2016-11-29

    This code works in a simulator. So, I am puzzled what to advise.

     
  • CDRIVE

    CDRIVE - 2016-11-30

    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

     
  • William Roth

    William Roth - 2016-11-30

    @Janis

    I will try to replicate later today. That's about 8 hours from now ( 2:AM CST) Have your meter and scope ready.

     
  • JANIS

    JANIS - 2016-11-30

    I think The Scheme is not the problem. How can a simple instruction to Cause Interference? Just turn on the LED!

     
  • JANIS

    JANIS - 2016-11-30

    I think The Scheme is not the problem. How can a simple instruction to Cause Interference? Just turn on the LED!

     
  • JANIS

    JANIS - 2016-11-30

    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

     
    • Anobium

      Anobium - 2016-12-02

      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.

       
  • CDRIVE

    CDRIVE - 2016-11-30

    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

     
  • Chris Roper

    Chris Roper - 2016-11-30

    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:

    PPSETINIT
    ;RA2PPS = 0x1b
        movlw   27
        banksel RA2PPS
        movwf   RA2PPS
    ;SSP2DATPPS = 0x02
        movlw   2
        banksel SSP2DATPPS
        movwf   SSP2DATPPS
    ;SSP2CLKPPS = 0x04
        movlw   4
        movwf   SSP2CLKPPS
    ;RA4PPS = 0x1a
        movlw   26
        banksel RA4PPS
        movwf   RA4PPS
        banksel STATUS
        return
    

    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
  • CDRIVE

    CDRIVE - 2016-11-30

    Hi Chris. Do you mean 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
  • Chris Roper

    Chris Roper - 2016-11-30

    looks good to me.

     
  • JANIS

    JANIS - 2016-12-01

    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!

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.