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


+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2022
    Posts
    51

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

    Hello to the community

    I used to control my servos with a PIC12F675 (internal 4MHz clock) with the PULSOUT command, renewed every 20 msec.

    However, I could see, with a logical analyzer, that the impulses were not always perfectly identical, thus causing a "dusy" of the servos.

    I could then hear that it was possible to control these servos using the Timer(s) of the PIC ... (?)
    Unfortunately, I know nothing about the use of these timer(s) and their configurations to use in PBP.

    Could a good soul provide me with a small explanatory program incorporating the elementary commands of configurations of the timer(s) to distinctly pilot two servos?

    I will assimilate it and then use it by completing it with my needs.

    Thank you in advance for your help.

    (User: PicBasicPro Compiler V:2.40)

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    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 " !!!
    *****************************************

  3. #3
    Join Date
    Oct 2011
    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?

    I would do it like this. Change PULSE_PIN for the second channel
    Code not tested but should give some idea how to use timer 1

    Code:
    PIE.0 = 1   'Enable timer 1 overflow flag
    T1CON = 0   'Timer 1 stopped, internal clock
    PULSE_OUT VAR WORD
    
    START:
    PULSE_OUT = 1500               'Servo center value
    PULSE_OUT = $FFFF - PULSE_OUT  'Timer 1 counts upwards
    TMR1H = PULSE_OUT.HIGHBYTE
    TMR1L = PULSE_OUT.LOWBYTE  'Set timer 1
    PULSE_PIN_1 = 1  'Start pulse
    T1CON.0 = 1    'Start timer 1
    WHILE PIE1.0 = 0 : WEND   'Wait for Timer 1 overflow
    PULSE_PIN_1 = 0    'End pulse
    T1CON.0 = 0      'Stop timer 1
    PIE1.0 = 0       'Reset overflow flag
       'wait 20ms .............................
    GOTO START
    Last edited by Ioannis; - 28th May 2023 at 19:31.

  4. #4
    Join Date
    Feb 2022
    Posts
    51


    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 ===============================================

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

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

    Hi,

    I have a big problem with your program ...

    What is it intended to do ??? ( Which inputs give which Outputs ??? ) or explain what you try to drive.

    Understand by that there's a problem related to input signals use ...

    try to write it down clearly on a paper ... there's some " overkill " in your program ... and it can be much, much, much simplified ...

    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

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

    Hi Alan.
    Thanks for your interest in my question.

    This is a system used in RC sailing to control the genoa of a radio-controlled sailboat.

    The sail is controlled by two winches.

    The RC Transmitter has :
    1) a three-position switch which determines the side on which the sail will be set (port or starboard).
    If the switch is in the middle position, the two winches each take up a specific end-of-travel position to make it easier to move the sail from one side of the boat to the other.
    2) A potentiometer that adjusts the tension of the sail's sheet.


    Finally, a small configuration jumper allows 4 different winch positioning configurations depending on how the sheeting circuits have been designed in the boat.

    A more detailed explanation can be found in the appendix.

    Note: In fact, the logic of my programme seems OK and the different servo winch positions obtained are correct. I just have a little instability in the positioning of the servos, which 'wiggle' a bit.

    RC Genoa Driver.pdf

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

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

    Hello,

    just one thing missing : which radio model and which channels are you using ( to know if the two channels used follow each other or if there's a time lag between them ... )
    ************************************************** ***********************
    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 " !!!
    *****************************************

  8. #8
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

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

    Hi Alan,
    The two channels follow each other:

    Switch on channel 7 and potentiometer on channel 8.
    The radio is a classic Robbe Promars.
    Thanks.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by zorgloub View Post
    Hi Alan,
    The two channels follow each other:

    Switch on channel 7 and potentiometer on channel 8.
    The radio is a classic Robbe Promars.
    Thanks.
    Ok, got it ...

    PBP can't read two channels following each other without missing the second one ... because PULSIN needs some little " re-arming " time ... ( I make it short )

    so, we must use a turnaround to achieve that ...

    Code:
        PULSIN _Vertical,1,Vertical
        RCTIME _Horizontal,1,Horizontal
    a look to the manual will give you the reason why ...

    and may be 1 unit @ 4 Mhz to add to Horizontal to be straight true ...

    So, here, you have to re-write your sampling part without any command between the two channels signals sampling commands ...

    Alain
    Last edited by Acetronics2; - 18th June 2023 at 09:22.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  10. #10
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

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

    Hi Alain,
    Thanks
    OK, I'll take it all back after the holidays

  11. #11
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

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

    Hi alan, here I am back from vacation
    I read your explanation relating to the "rearming-time" of two successive Pulsin.
    Note that here there is code between these two Pulsin (first the Gosub Tri, then the Gosub PRG n).
    These are not directly successive pulsin commands and this notion of "rearming-time" does not seem to explain the problem.

  12. #12
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

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

    The two PULSIN commands in the main loop are going to add jitter to the pulse output timing since the time is going to vary depending on the input pulse times.

  13. #13
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

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

    Apart from this problem, I did positioning stability tests with several servos.
    If a servo is not stable, it is because the value of the pulses is not constant.
    If the gap between these impulses (which is normally 20 msec) is not constant, this does not influence the servo at all!
    I did a test by alternating 20msec differences and 40 sec while sending constant pulses: the servo remains stable.

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 : 21

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