PBP projects for R/C models


Results 1 to 40 of 772

Threaded View

  1. #11
    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: 3883
Size:  182.3 KB
    Last edited by thronborg; - 15th March 2011 at 03:02.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 13:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 12: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, 20:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2005, 00:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 17:24

Members who have read this thread : 2

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