Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2022
    Posts
    51

    Default Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)

    Hello to the Community.
    I am using PBP Compiler version 2.46
    I started by programming BasicStamp 2SX and then adapting the programs to fit into PiCs.

    I switched to Picaxe (also programmable in Basic) and am now trying to adapt my Picaxe program to fit into a Pic12F629.

    However, the compiler gives me errors that I don't understand
    For example, it mentions undefined symbol names that do not exist in the program: GO_DONE, ADRESH, ...
    What are these "extra tokens", ...?
    Can you help me?

    In appendix, print screen of the compiler errors and... the code.

    Thanks.

    CODE:
    -------------


    '----------------------------------------------------------------------------------
    ' SERVO_TR PIC01.bas - "ON/OFF" Servo - Servo "Tout ou Rien"
    ' Adaptation for PBP compiler v2.4x (DO..LOOP..Until not supported !)
    '
    ' V1.0 - 09/05/2022 - RGL
    '
    ' Moves a servo to two preset positions, depending on the state of a logic input
    ' Servo signals adjustable from 0.75 ms to 2.25 ms
    '----------------------------------------------------------------------------------
    '
    ' TWO POSITION SETTING PROCEDURE
    ' -----------------------------------
    ' - In Normal Mode (Input Mode=1), the LED is on.
    ' - Set the logic input (S_Pos) to 0V or 5V to select either servo position.
    '
    ' - In Configuration Mode (Input Mode=0), the LED is blinking.
    ' - The state of the S_Pos input will determine which position you are setting !
    ' - Turn the potentiometer in either direction: The servo follows the movement.
    ' - When the desired position is reached the LED goes out after a few seconds.
    ' - Then, return the configuration input to normal mode (High)
    ' The LED lights up again and the new position is stored in Eeprom.
    ' The system returns to Normal Mode with the new programmed position.
    ' - Do the same for the other position by changing the state of the S_Pos input.
    '----------------------------------------------------------------------------------
    'PotADC gives values from 0 to 255
    'ServoPos delivers pulse values from 75 to 225 (0,75msec to 2,25msec)


    ' Pic Specifications
    '--------------------
    @ Device Pic12F629, intrc_osc, wdt_off, pwrt_on, mclr_off, protect_off 'DIP8
    DEFINE OSC 4 ' 4Mhz Resolution=10µsec => 1 msec=100

    CMCON = 7 ' Comparator off
    'ADCON0 = 7
    'ANSEL = 0 ' Set I/O to digital

    ' __ __
    ' Vcc o| U |o Gnd
    ' NC GP5 x| |> GP0 Led
    ' Config. GP4 >| |> GP1 Servo
    ' Position GP3 >| |< GP2 Pot
    ' -----


    '*** In/Out pins ..................................................

    ' GND pin8 - Gnd
    Output 0 : Symbol LED = GPIO.0 'Led pin7 - Out0
    Output 1 : Symbol S_Out = GPIO.1 'Servo pin6 - Out1
    Input 2 : Symbol Potar = GPIO.2 'Pot pin5 - In2
    Input 3 : Symbol S_Pos = GPIO.3 'S_Pos pin4 - In3
    input 4 : Symbol Mode = GPIO.4 'Mode pin3 - In4
    ' pin2 -
    ' pin1 - Vcc


    '*** Variables .................................................. ..

    Position1 VAR BYTE 'W0 Position1 servo
    Position2 VAR BYTE 'W0 Position2 Servo
    PotADC VAR BYTE 'W1 Pot ADC Value
    NewADC VAR BYTE 'W1 New ADC Conversion
    _PotADC VAR BYTE 'W2 =PotADC/10
    _NewADC VAR Byte 'W2 =NewADC/10
    Pulse VAR BYTE 'W3 Pulse value to servo
    State VAR BIT 'W3 Normal/Configuration
    Flashing VAR word 'W4 Counter for Led Flashing Frequency
    Waiting VAR WORD 'b10-11 Counter for Validation Delay
    Space VAR WORD 'b12-13 Pause time between each servo pulse
    'depending on the length of the pulse,
    'to obtain a standard total Space of 20 msec.

    '*** Constants .................................................. ..
    FrBlink CON 2 'Flashing Frequency of the Led
    TValid CON 150 'Waiting Time for Validation

    '================================================= =================================
    INIT:

    Read 0,Position1 'Read Positions in Eeprom
    Read 1,Position2

    IF Position1<75 OR Position1>225 OR Position2<75 OR Position2>225 Then
    Position1= 180 'if values outside the limits of a servo
    Position2= 120 'Preset Values = 1.2msec, 1.8msec
    EndIF

    LET Flashing=0
    LET Waiting=0

    '---------------------------------------------------------------------------
    MAIN: 'Main Loop

    IF Mode = 1 Then 'NORMAL Mode
    High Led

    IF S_Pos = 0 Then 'Read the Desired Position
    Pulse = Position1
    Else
    Pulse = Position2
    EndIF
    GoSub UpdateServo 'Update the servo

    Else 'CALIBRATION Mode !
    State = S_Pos

    DO_CALIB:
    'DO Until Waiting = TValid 'Configuration Loop
    IF Waiting <> TValid Then
    GoTo Calib
    Else
    GoTo Out_Calib
    EndIF
    CALIB:
    'State = S_Pos
    ADCIN Potar,PotADC
    Pulse=PotADC*59/100+75 'Converting ADC to Pulse

    GoSub UpdateServo 'Update the servo

    _PotADC=PotADC/10 'Stabilisation of the inaccuracy
    _NewADC=NewADC/10 'of the Pot ADC reading

    IF _PotADC=_NewADC Then 'If Pot Position Unchanged
    Waiting = Waiting +1 'Increase Waiting Time (Until=TValid)
    Else
    NewADC=PotADC 'Reset of the Waiting Time
    Waiting=0
    EndIF

    Flashing = Flashing +1
    IF Flashing=FrBlink Then
    Toggle Led 'Blinking Led
    Flashing=0 'Reset cpt Led
    EndIF
    'LOOP 'Configuration Loop
    GoTo DO_CALIB

    Out_CALIB:
    GoSub Validation 'The position of the Pot is Stabilised
    EndIF
    GoTo Main 'Main Loop
    End
    '================================================= ================================
    ' --- SUBROUTINES ---
    '================================================= ================================

    UPDATESERVO:

    PulsOut S_OUT, Pulse 'ServoPos = pulse values from 75 to 225 (0,75msec to 2,25msec)
    Space = 2000 - Pulse '= 20msec - pulse duration
    PauseUs Space '
    Return
    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++

    VALIDATION: 'Storage of the New Position in Eeprom

    Low Led 'Waiting to Deselect Configuration Switch Mode !

    Do_Until:
    'DO
    'LOOP Until Mode = 1 'Mode=1 -->NORMAL Mode

    IF Mode <> 1 Then
    GoTo Do_Until 'Loop Until Mode = 1 !
    Else
    GoTo Out_Do_Until 'Mode = 1 = Mode NORMAL
    EndIF

    Out_Do_Until:

    High Led 'OK, Ready to return to Normal Mode

    IF State=0 Then 'New position Writing in Eeprom
    Position1=Pulse
    Write 0,Position1
    Else
    Position2=Pulse
    Write 1,Position2
    EndIF

    Flashing=0 : Waiting=0 'Reset Counters
    Return 'to Normal Mode

    '"== END OF PROGRAM ================================================== ==============


    Compiler ERRORS:

    Name:  Compiler Errors.jpg
Views: 187
Size:  47.4 KB

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


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)

    I switched to Picaxe (also programmable in Basic) and am now trying to adapt my Picaxe program to fit into a Pic12F629.
    a Pic12F629 has no adc module ADCIN Potar,PotADC is never going to fly use a Pic12F675

    also if you post code please put it in code tags Name:  Screenshot 2022-05-10 082543.jpg
Views: 191
Size:  68.0 KB

  3. #3
    Join Date
    Feb 2022
    Posts
    51


    Did you find this post helpful? Yes | No

    Default Re: Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)

    Hi Richard,
    Thank you for your quick reply !
    I had indeed noticed this small difference between a 12F629 and a 675 and that's why I have these two components in stock!
    Inattention error !
    It's getting late !
    OK, the compiler doesn't give any more errors.

    For the code tags, I had searched in the multitude of icons, without success.
    I'll keep this in mind for the next few times.
    Good night.

    Sincerely

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)

    It's been quite a few years since I played with PICAXE, but what I do remember is that to configure the TRIS Registers, with PICAXE an Output = 1, but with PBP an Output = 0; they're backwards.

    Second, with PBP you configure PORT related registers with the PORT -- TRISA = xx, ANSELA = xx... With PICAXE you have a generic PORT register that covers pretty much every PORT pin in one fell swoop (OUTPUT 0, INPUT 1, etc.). In other words, there may be some major changes you need to make to your code.

    I found when folks try to help me by handing me answers, I get past the immediate situation, even if I have no clue why the suggestion worked. When folks tell me where to find the answers myself, I can get past my current dilemma, but I then know where to look the next time I run into a challenge. May I suggest spending some quality time with the PBP3 Reference Manual, a free download from the ME Labs web site.

    My personal journey started with PICAXE about 11 years ago. After about 2 years I upgraded to PBP3. I've since plunged into the dark side with MPLABX. My advice is to download the PBP3 Reference Manual and spend time learning the PBP way of doing things.

  5. #5
    Join Date
    Feb 2022
    Posts
    51


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Adapting a PICAXE program to PBP, to program a PIC (compiler Errors)

    Hi MpgMike
    Indeed, there are several peculiarities to take into consideration when switching from Picaxe (or Basic Stamp) to a Pic.
    But they are well documented in the Reference Manual which I consult if necessary.

    I personally avoid using the registers that handle i/O and Directions.

    I write in clear text in my program, which is then very readable, definitions like this:
    Output 0 : Symbol LED = GPIO.0 'Led - pin7 - Out0

    In the case of my present application, it was a stupid error of inattention because, indeed, the Pic12F629 does not have an ADC contrary to the 12F675!
    This indeed caused incomprehensible compiler errors.

    Thanks.

Similar Threads

  1. Compiler (PBP v2.50C) errors
    By droptail in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th November 2021, 00:57
  2. 2 didit up down counter using 16F628A program errors
    By raybel in forum FAQ - Frequently Asked Questions
    Replies: 15
    Last Post: - 27th September 2020, 16:30
  3. Upgraded to PBP v2.60 and I can't program
    By FireHawk in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th May 2010, 17:55
  4. Replies: 1
    Last Post: - 23rd May 2009, 10:22
  5. In what order do we construct a PBP program?
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th October 2008, 09:18

Members who have read this thread : 1

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