(Picbasic Pro Compiler) Distinct management of two servos per timer(s) of 12F675?


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: (Picbasic Pro Compiler) Distinct management of two servos per timer(s) of 12F675?

    Salut Zorglub, salue Champignac pour moi ... ce pseudo ne m'est pas totalement inconnu

    The question is ...
    what happens is quite predictable ... BUT, having a look to your code and knowing your application goal could lead to an adequate answer ... or better, closer solution.

    Alain
    Last edited by Acetronics2; - 27th May 2023 at 09:17.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Feb 2022
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: (Picbasic Pro Compiler) Distinct management of two servos per timer(s) of 12F675?

    Bien le bonjour Alain et... salutations de Champignac


    Hello Alain.
    My application is to read two servo control signals from a classic radio -controlled receiver.
    These signals are "processed" and redirected to two outings.

    We find, on these outputs, the inverted signals, or not, depending on various possible combinations.

    A configuration jumper allows three possible modes (recorded in EEPROM).

    I note that for a condition giving a defined pulsout of 1 or 2 msec the servo is stable.
    But for pulsout "copying" or reversing the Pulsin values to outputs, they are no longer stable!
    It is therefore not the inversion calculation (3msec - Pulsin) which induces the problem. (Look at the PRG0 which does not include a reversal calculation but just a "copy" of the pulsin value.)

    Finally, note that if I connect the servos directly to the receivers' outputs, they remain stable. We cannot therefore incriminate an instability of the signals from the receiver!

    Thank you for your ideas.

    CODE: (PBP v2.4)

    Code:
    '**********************************************************************
    '   Programme: Test1.PBP   (c)RGL 05-2023
    '     ---> PIC 12F675
    '***********************************************************************
    ' PicBasicPro Compiler V:2.40    448 Words compiled
    
    '*** PIC Pinouts/Specifications
    '------------------------------------
    '       PIC 12F675  (Internal 4Mhz Osc) DEFINE OSC =Default.Value =4
    '                   __ __
    '             Vcc +|  U  |- Gnd
    '         (nc)GP5 x|     |< GP0 _Config Jumper
    ' _Horizontal GP4 >|     |> GP1 _Servo1 
    ' _Vertical   GP3 >|     |> GP2 _Servo2 
    '                   -----
    @ Device Pic12F675, intrc_osc, wdt_off, pwrt_on, mclr_off, protect_off
    
    DEFINE OSC 4    '10us Pulsout Unit: 100 = 1ms  @4Mhz
                    ' 1ms Pause Unit  :   1 = 1ms  @4Mhz
    
    CMCON  = 7   'Comparator Off
    ANSEL  = 0   'Set Port to Digital i/o         
    ADCON0 = 0   'All ADC Off
    
    TRISIO = %011001  ; 1=Input
    GPIO   = %00      ; Make all pins 0 except input pins
    
    OSCCAL = $38  ' $38=56d ' Also to be manually placed at 3FF Address (3438)!
    
    '*** In/Out pins ..................................................
                                                  'GND        pin8 - Gnd
     Input 0 : Symbol _Config     = GPIO.0    'Jumper        pin7 - In0
    Output 1 : Symbol _Servo1     = GPIO.1     'Servo1        pin6 - Out1
    Output 2 : Symbol _Servo2     = GPIO.2     'Servo2        pin5 - Out2
     Input 3 : Symbol _Vertical   = GPIO.3     'Vertical Position    pin4 - In3
     Input 4 : Symbol _Horizontal = GPIO.4     'Horizontal Position    pin3 - In4
    ;Input 5 : Symbol _xxx        = GPIO.5                pin2 - nc
    '                                       'Vcc        pin1 - Vcc
    '*** Variables
    
     Menu         VAR byte    'Program Mode index (0 to 3)
     Vertical    VAR word    'Vertical Position
     Horizontal  VAR word    'Horizontal Position
     RVertical   VAR word    'Reverse Vertical Position Value  (3msec - Vertical)
     RHorizontal VAR word    'Reverse Horizontal Value (3msec - Horizontal)
    
    '=== MAIN PROGRAM =====================================================
    Init:
    READ 0, Menu      'Read Eeprom when starting (Check Mode Prg)
    
    MainLoop:
    
     IF _Config=0 Then Gosub MODE    ' Enabled Mode Configuration Jumper
    
     Pulsin _Vertical,1,Vertical  'Read Vertical Position
      gosub Tri
     Pulsin _Horizontal,1,Horizontal  'Read Horizontal Position
      gosub Tri
    
    Goto MainLoop
    
    '=======================================================================
    ' --- SUBROUTINES ---
    '=======================================================================
    TRI:
    
     Select Case Menu
      Case 0
        Gosub PRG0
      Case 1        
        Gosub PRG1
      Case 2        
        Gosub PRG2    
      End Select
    Return
    '-------------------------------------------------
    MODE:  'Change and memorize the 3 Menu Program index (0 to 2)
    
     Menu = Menu + 1
     IF Menu > 2 Then Menu = 0
      WRITE 0,Menu 'Write to Eeprom @Addr.0 the menu index
      PAuse 1000   '1 sec
    Return
    '-------------------------------------------------
    PRG0:
    
     IF Horizontal <120 then '1ms (<1,2ms)
      Pulsout _Servo1,Horizontal
      Pulsout _Servo2,Vertical
     Else
       IF Horizontal < 170 then '1,5ms (<1,7ms)
        Pulsout _Servo1,100  '1ms
        Pulsout _Servo2,100  '1ms
       Else '2ms (>=1,7ms)
         Pulsout _Servo1,Vertical
         Pulsout _Servo2,Horizontal
       Endif
     Endif  
    Return
    '-------------------------------------------------
    PRG1:
    
      RHorizontal = 300-Horizontal  'Reverse Horizontal Pösition (3msec-Horizontal)
     
     IF Horizontal <120 then '1ms (<1,2ms)
      Pulsout _Servo1,RHorizontal
      Pulsout _Servo2,Vertical
       Else
       IF Horizontal < 170 then '1,5ms (<1,7ms)
        Pulsout _Servo1,200  '2ms
        Pulsout _Servo2,100  '1ms
       Else '2ms (>=1,7ms)
         Pulsout _Servo1,Vertical
         Pulsout _Servo2,Horizontal
       Endif
     Endif
    Return
    '-------------------------------------------------
     PRG2:
    
      RHorizontal = 300-Horizontal  'Reverse Horizontal Pösition (3msec-Horizontal)
      RVertical = 300-Vertical  'Reverse Vertical Position (3msec-Vertical)
     
     IF Horizontal <120 then '1ms (<1,2ms)
      Pulsout _Servo1,Horizontal
      Pulsout _Servo2,Vertical
       Else
       IF Horizontal < 170 then '1,5ms (<1,7ms)
        Pulsout _Servo1,100  '1ms
        Pulsout _Servo2,200  '2ms
       Else '2ms (>=1,7ms)
         Pulsout _Servo1,RVertical
         Pulsout _Servo2,RHorizontal
       Endif
     Endif
    Return
    '-------------------------------------------------
    
    '====  END OF PRG ===============================================

Similar Threads

  1. Replies: 2
    Last Post: - 28th May 2016, 14:09
  2. Experimenting with the PicBasic Pro Compiler
    By polymer52 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 17th May 2016, 19:17
  3. PicBasic Pro Compiler manual updated with bookmarks
    By mtripoli in forum Documentation
    Replies: 1
    Last Post: - 8th March 2011, 00:49
  4. Picbasic Pro compiler 2.60 error
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd January 2010, 05:55
  5. PicBasic Pro Compiler for 877A
    By iwill920ya in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st May 2004, 04:10

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