PBP projects for R/C models


Closed Thread
Results 1 to 40 of 772

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Servo Tester

    Quote Originally Posted by thronborg View Post
    I made a servotester that output a puls from 0.5mS to 2.5mS (Its more than i need)
    I have a pot that give an input of 0 to 255.

    Q1: How do i get the Pot in one direction 0, to be 0.5mS and in the other direction 255 to be 2.5mS?
    That depends on your code for the servo tester. You will probably get more response if you either explain what you are doing, or post your code so far.

  2. #2
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Reading a potentiometer

    thronborg,

    You might find the code examples in post #374 helpful. This dates back to August 2010 when I was first incorporating a pot into my system.

    Ken

  3. #3
    Join Date
    Mar 2011
    Location
    Bangkok Thailand
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Re: PBP projects for R/C models

    Hello
    Actually i have this code for display the value on a LCD. Now i want the value of 0 to be 1mS puls and 255 to be 2mS puls.

    Se attached drawing.
    Code:
    ' Name        : ServoTester.pbp
    ' Compiler    : PICBASIC PRO Compiler 2.6
    ' Assembler   : PM or MPASM
    ' Target PIC  : PIC16F690 or similar type compatible with LAB-X20 board
    ' Hardware    : LAB-X20 Experimenter Board
    ' Oscillator  : 4MHz external crystal
    ' Keywords    : ADCIN, LCDOUT
    ' Description : PICBASIC PRO program to read pot and display on LCD.
    '                        FUNKAR ROR EJ
    
    ' Define LCD pins
    Define LCD_DREG  PORTC   'LCD data port
    Define LCD_DBIT  0       'LCD data starting bit 0 or 4
    Define LCD_RSREG PORTC   'LCD register select port
    Define LCD_RSBIT 4       'LCD register select bit
    Define LCD_EREG  PORTC   'LCD enable port
    Define LCD_EBIT  5        'LCD enable bit
    
    ' Allocate variables
    x Var Byte
    
       ANSEL = %00000100    ' Set PORTA.2 analog, rest digital
       ANSELH = %00000000
       Pause 100            ' Wait for LCD to start
    
    mainloop:
       Adcin 2, x           ' Read ADC value on AN2 (PORTA.2)
       Lcdout $fe, 1, "Pot1 = ", #x ' Send value to LCD
       Pause 50            ' Do it about 10 times a second
       Goto mainloop        ' Do it forever
       End[/I][/I]
    Hope this help
    Thronborg

    Servo Tester.pdf
    Last edited by ScaleRobotics; - 12th March 2011 at 16:53.

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default Re: PBP projects for R/C models

    Ken, take a look at this Electronics with Micro-controllers
    Why pay for overpriced toys when you can have
    professional grade tools for FREE!!!

  5. #5
    Join Date
    Mar 2011
    Location
    Bangkok Thailand
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Servo Tester now works with Potentiometer and LCD

    Thank's, now i start to understand a little bit more. Its running fine but i got the feeling that i had to much code.

    Actually i dont know why i had the ANSEL, ANSELH and ADCON, it seems to work without them. Any ideas?


    '************************************************* ***************
    '* Name : NimSer.BAS *
    '* Date : 3/3/2011 *
    '* Notes : Move Servo 1 to 2mS depend on POT value *
    '* Show valu in mS on LCD display *
    '* For standard servo settings 1-2mS set LOW_servo con 100 *
    '* and HIGH_servo CON 200 *
    '************************************************* ***************
    'Define OSC and ADC
    DEFINE OSC 4 ' Set internal Oschillator to 4Mhz
    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 2 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    ' Define LCD pins
    Define LCD_DREG PORTC 'LCD data port
    Define LCD_DBIT 0 'LCD data starting bit 0 or 4
    Define LCD_RSREG PORTC 'LCD register select port
    Define LCD_RSBIT 4 'LCD register select bit
    Define LCD_EREG PORTC 'LCD enable port
    Define LCD_EBIT 5 'LCD enable bit


    TRISA = %00001001 ' RA0 = A/D input
    ADCON1.7 = 0 ' RA.1 = +Vref, Set PORTA analog and left justify result
    PORTb.6 =0 ' Prepare RB0 for high-going pulseout

    ANSEL = %00000100 ' Set PORTA.2 analog, rest digital
    ANSELH = %00000000

    ' Variables
    outpuls VAR WORD ' Variable for the calculated puls out in mS
    POT_POS VAR BYTE ' Pot position CC=0, CCW=255
    LOW_servo con 60 ' Min Servo pulse 60= 0.6mS 100=1mS
    HIGH_servo CON 200 ' Max Span from LOW_servo to HIGH_servo
    ' Span 100 gives 100+100 = 200=2mS
    Pause 500 ' Wait for LCD to start

    MainLoop: ' The Loop start here!
    ADCIN 0,POT_POS ' Read A/D channel 0 to variable SVO_POS
    outpuls =LOW_servo + (POT_POS *HIGH_servo/255) 'Calculate the outpuls in mS
    Lcdout $fe, 1, "POT_POS= ", #POT_POS ' Display POT Valu between 0-255 on line 1
    LCDOut $fe,$C0, "Puls= ",DEC (outpuls/100),".", DEC2 outpuls,"mS"' Display pulswith in mS on line 2

    PULSOUT portb.6 ,outpuls ' Move servo on pin
    PAUSE 20 ' Constant 20mS pulses(low) between outpuls
    GOTO MainLoop ' Forever
    End


    Name:  Pot to Servo and LCD.jpg
Views: 3818
Size:  182.3 KB
    Last edited by thronborg; - 15th March 2011 at 02:02.

  6. #6
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Question What is it with PAUSE??

    Hello, I am back with a robocar - PBP question. I wish I had the will power to really study this.

    My robocars use HPWM to control the steering and to drive the Electronic Speed Control => DC motor for the wheels. I am trying to calibrate this command given different little cars.

    Before the "main:" label I placed some code to make the wheels turn and steer. I discovered that HPWM rides through the PAUSE command sometimes and not other times. It depends on what code precedes the HPWM commands. Immediately below is a case that works. Below that is a case that does not. By not work, I mean the wheels just do not move.The only difference is the presence of the WHILE loop at the beginning.

    The WHILE loop at the front checks the power status of the radio transmitter. If channel3 (PORTC.4) is pulsing the radio is receiving a signal from its transmitter. This works. It gives me an opportunity to put the car down on the floor.

    What'z up here with HPWM and PAUSE???

    -----THIS WORKS: Turn OFF the transmitter and the wheels move---------------

    switchtoPIC = 2
    WHILE switchtoPIC >= 2
    COUNT channel3,65,switchtoPIC
    HIGH portc.0
    WEND

    HPWM 1, Left, 50
    HPWM 2, Forward, 50
    pause 1000

    HPWM 1, HalfLeft, 50
    HPWM 2, HalfForward, 50
    pause 1000

    HPWM 1, Straight, 50
    HPWM 2, brake, 50
    pause 1000

    main:

    ------THIS DOES NOT WORK. THE WHEELS DO NOT MOVE until main: ----------

    HPWM 1, Left, 50
    HPWM 2, Forward, 50
    pause 1000

    HPWM 1, HalfLeft, 50
    HPWM 2, HalfForward, 50
    pause 1000

    HPWM 1, Straight, 50
    HPWM 2, brake, 50
    pause 1000

    main:

  7. #7
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Question Want to see the asm code?

    Would it help if I were to show you the assembly language code for the above two compilations?

    Ken

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

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