PWPS Servo Problem


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: PWPS Servo Problem

    I tested the PIC12F1840 and PIC16F1824 with software serial input. PIC frequency set to 8MHz as required PBP at 9600 baud.
    It's working, but the response is kinda slow.
    Code:
    '*  Notes   : PIC16F1824                                        *
    '****************************************************************
    
    #CONFIG
      __config  _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
      __config  _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 8     ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    
    ANSELA  = 0
    ANSELC  = 0 
    TRISA = %000000   
    TRISC = %00100001 ; PORT C.5 input RX, C.0 safety, rest output
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2
    OPTION_REG.7=1    ; Disable weak pull ups
    APFCON0.7=0
    APFCON0.2=0
    
    
    ; def_ports:
    PWPSpin       var portc.1  ; servo signal OUTPUT (must be defined before PWPS_Servo.INC) 
    safety        var portc.0  ; safety leash magnetic switch
    
    ; def_vars:
    n             var byte 
    cmd           var byte 
    
    ; def ext libr:
    include "PWPS_Servo.INC"                    ; Software Servo PWM module
    include "modedefs.bas"                         ; modedefs must be after PWPS_Servo.INC otherwise it doesn't work
    
    init:                                       ; vars start values
    position      = 1
    cmd           = 245
    n             = 0
    
    gosub StartPWPS                             ; start PWPS module 
    
    Main:                                                      
    
    Serin2 portc.5,84,20,lost, [wait("Q"),dec cmd]         ; wait for Q and then for CMD
    
    if cmd = 155 then                           ; increment servoimpulse
    Position=Position+1
    if Position > 1199 then Position = 1200     ; max servoimpulse lenght 2us
    gosub SetPWPS
    endif
    
    if cmd = 145 then                           ; decrement servoimpulse
    Position=Position-1
    if Position < 1 then Position = 1           ; min servoimpulse lenght 1us
    gosub SetPWPS
    n=n+1                                       ; long press decrement  
    if n=255 then                               ; switch to minimum servoimpulse after cca. 3. sec.
    position=1
    endif
    endif
    
    if cmd = 245 then                            ; if transmitter is switched OFF servoimpulse to nimimum
    Position=1
    gosub SetPWPS
    endif
    
    if safety = 1 then                           ; if safety switch is OFF servoimpulse to nimimum
    Position=1
    gosub SetPWPS
    endif
    
    goto main
    
    lost:                                        
    n=0                                           ; clear long press counter value to 0
    if safety = 1 then                            ; if safety switch is OFF servoimpulse to nimimum
    Position=1
    gosub SetPWPS
    endif
    goto main
    Then I tested even only the PWPS run alone on PIC16F1824 and via serial terminal from PC sent a serial command and the PIC freezes.

    Then I tested what if I stop TMR1 (of course PWPS stopped working) but the HW usart works without problems.

    Something is wrong with this PWPS include but I can't figure out what.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: PWPS Servo Problem

    how sure are you that your code is compiled with the modified inc as i suggested ?

    if you examine the lst file generated and search for NoTimerInt
    do you see

    Name:  Screenshot 2022-07-06 104811.jpg
Views: 1053
Size:  178.6 KB


    pbp can be tricky if multiple versions of inc files exist, sometimes the "wrong" version can be used inadvertently
    Last edited by richard; - 6th July 2022 at 01:55.
    Warning I'm not a teacher

Similar Threads

  1. servo/motor problem
    By griffin in forum mel PIC BASIC
    Replies: 10
    Last Post: - 10th February 2009, 20:07
  2. Servo motor problem
    By dboy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th September 2008, 15:54
  3. servo driver problem
    By al000y in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th February 2007, 10:17
  4. Servo Pulser problem
    By al000y in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th January 2007, 12:48
  5. servo pulse problem...
    By tonkgang in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th April 2006, 16:12

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts