New and looking for help


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2010
    Posts
    2

    Default New and looking for help

    Hello Everybody,

    I have written a program for a PIC 16F685. I can't get it to work. It should read the pressure from a sensor (it does), indicate via LCD the voltage as converted (it does), light up an led for on pressure, high pressure, or low pressure (it does), and then move a servo accordingly (the servo buzzes but no consistant movement). I have read several books and still dont' understand the a/d conversion commands I simply copied them, perhaps there is my problem but I can't figure out how to get it fixed. If I play around with the commands, or the Physical and porgrammed location of the servo, I can sometimes get the servo to work, but then the LED's stop working. After a week of trying to figure it out it is time to humbly admit defeat and ask for help. I will eventually want to add a couple buttons to control the logic, but I need to get this workign first. Any help is greatly appreciated, and below is my current code:

    '************************************************* ***************
    '* Name : pressure reader.BAS *
    '* Author : [Leon Wilde ] *
    '* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 8/23/2009 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    Include "modedefs.bas"
    ' variables
    res var word ' a/d converter result
    volts var word ' result of converersion in mV
    width var word
    servopos var word
    conv con 19 '5000/256=19.53, take 19
    TRISA = 1 ' RA0 (an0) is input
    TRISB = 0 ' RB AS OUTPUT
    TRISC = 0
    LED1 var portB.6
    LED2 VAR PORTB.5
    LED3 VAR PORTB.4
    servo var portb.7
    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    ADCON1 = 2 ' PORTA is analog
    clear
    SERVOPOS = 150
    pause 10




    'initialization

    for width = 1 to 100
    pulsout portC.6, SERVOPOS
    pause 10
    next
    pause 10



    serout portc.7, 2400, [12,1,14] ' CLEAR SERIAL LCD

    start:

    PAUSE 10
    for width = 1 to 100
    pulsout portC.6,servopos
    pause 10
    next
    LED1 = 0
    LED2 = 0
    LED3 = 0

    PAUSE 10





    ' START A/C CONVERSION

    ADCIN 0, res ' Read channel 0 to res



    'WAIT UNTIL CONVERSION IS COMPLETE

    VOLTS = RES * CONV

    serout portc.7, 2400, [12,1,14]
    serout portc.7, 2400, ["V=", #VOLTS]

    if volts < 1040 Then goto tooshallow

    IF VOLTS > 1066 THEN goto toodeep

    goto goodpressure

    PAUSE 1000
    GOTO start

    tooshallow:
    LED1 = 1
    servopos = 50
    goto start

    goodpressure:
    LED2 = 1
    servopos = 100
    goto start

    toodeep:
    LED3 = 1
    servopos = 150
    goto start

    end

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    No expert, but I think your problem is in the servo drive timing. A standard RC servo requires a pulse between 1ms and 2ms (1.5ms represents centre stick) repeated every 20ms. It looks like you are simply sending a value of 50 or 100 which is on the limits or outside its range, and you are not repeating this within the 20ms time frame.

    There are plenty of examples on the forum for servo drivers, have a go at getting your hardware working with one of those and then use that as the driver for your project.

    Here are some examples:
    http://www.rentron.com/servo.htm
    http://www.rentron.com/SerialServo.htm
    Last edited by malc-c; - 13th March 2010 at 08:12.

  3. #3
    Join Date
    Aug 2005
    Location
    down south
    Posts
    90


    Did you find this post helpful? Yes | No

    Default

    this is something I did for the grand kids one day (just grab the file had not recheck
    to make sure it still works)
    thought it mite help you it uses a A/D to drive a servo
    remember I'm not a pro. just a hobbyist
    Code:
    '****************************************************************
    '*  Name    : LIGHT BOX.BAS                                      *
    '*  Author  : grounded                                   *
    '*  Notice  : Copyright (c)   *
    '*          : All Rights Reserved                               *
    '*  Date    : 3/12/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : IF YOU SHINE A LIGHT ON THE PHOTO CELL THE BOX OPENS                                               
    '*          : AND STAYS OPEN UNTIL THE LIGHT IS REMOVED                                              
    '****************************************************************
      pic16f676   'fuses set in inc file
    'INTRC_OSC_NOCLKOUT, WDT_ON, MCLR_OFF,
    'CPD_OFF, BOD_OFF, PWRT_ON,PROTECT_OFF
    DEFINE OSC 4
    DEFINE ADC_BITS 10 
    DEFINE ADC_CLOCK 3 
    DEFINE ADC_SAMPLEUS 50						
    Pause 7000                 'DELAY TO LET STABILIZE AFTER POWER UP & MODE 
    CMCON = 7                   'COMPARATOR OFF
    VRCON = 0                   'VOLTAGE REF. DISABLE	
    TRISA = %00001101           'MAKE A.2 & A.3 INPUTS
    TRISC = %00000011		    'MAKE .C.0,C.1 PORTC INPUTS
    ANSEL = %00000001           'PORTA.0 A/D IN,RST DIGITAL
    ADCON0.7 = 1                'RIGHT JUSTIFY FOR 10 BIT 
    OPTION_REG=%01000000        'RAISING EDGE/WEAK PULL UP  
    WPUA = %00000000            'NO WEAK PULLUPS  
    
    SYMBOL ADC  =PORTA.0         'ADCIN
    SYMBOL LDR  =PORTA.1         'PHOTO POWER
    SYMBOL PIR  =PORTA.2         'PIR TRIPS HIGH
    SYMBOL MODE =PORTA.3         'MODE BUTTON
    SYMBOL smA   =PORTA.4        'SERVO CONTROL OUTPUT
    SYMBOL LED  =PORTA.5         'WALKTEST AND POWER LED
    
    SYMBOL DIPB =PORTC.0         'DIP SWITCH 2 N/A
    SYMBOL DIPA =PORTC.1         'DIP SWITCH 1 N/A
    SYMBOL DPO  =PORTC.2         'DIP SWITCH POWER N/A
    SYMBOL RL   =PORTC.3         'N/A REMOTE LIGHT  N/A
    SYMBOL CPO  =PORTC.4         'CAM POWER BUTTON  N/A
    SYMBOL RC   =PORTC.5         'RECORD BUTTON     N/A
    '****************************SET UP VARIBLES***************************
     
    NIGHT VAR WORD:NIGHT=0        'LDR/ADCIN VAR FOR LIGHT SENSOR
    '********************************TURN EVERYTHING OFF*********************
    ADC=0:LDR=0:PIR=0:MODE=0:smA=0:LED=0:DIPA=0:DIPB=0:DPO=0:RL=0:CPO=0:RC=0 
    
     '************************************ CAL MODE*******************
     led=1 :pause 3000 :led=0
    IF MODE=0 Then GoTo  CAL  'IF MODE BUTTON =0 THEN GOTO LRD CAL MODE
    GoTo MAIN                  'SKIP CAL MODE  GO MAIN
    CAL:
    LDR=1:Pause 250           'TURN LDR/ADCIN POWER ON
    
    LED=1:Pause 250:LED=0:Pause 250
    LED=1:Pause 250:LED=0:Pause 1000  ' FLASH YOUR IN CAL MODE
    TEST:
    NIGHT=0
    LED=0
    ADCIN 0,NIGHT          'CHECK AN# READ AN1 & STORE IN NIGHT VAR
     
     IF NIGHT=<200  Then LED=1   'IF LED IS ON THEN IT'S LIGHT ENOUGHT TO OPEN BOX
     Pause 250
     
     IF MODE =0 Then GoTo main    'LEAVE CAL MODE 
     
     GoTo TEST                   'LOOP AND CHECK FOR LIGHT AGAIN
     
     
    main:
    
    asc var word : asc=70
    ldr=1
    NIGHT=0
    LED=0
    ADCIN 0,NIGHT          'CHECK AN# READ AN1 & STORE IN NIGHT VAR
     
    pause 250 
    if night =< 200 then goto open
     goto main
    
    
    open
    
    PULSOUT SMA,asc
    PAUSE 18 
    
    ASC=ASC+1
    
     if ASC=>240 THEN PAUSE 2000: GOTO shut
    GOTO open 
     shut:
     NIGHT=0
     pause 20
    ADCIN 0,NIGHT          'CHECK AN# READ AN1 & STORE IN NIGHT VAR
     pause 20
    if night => 200 then goto close
    goto shut
    close
     led=0
    PULSOUT SMA,asc
    PAUSE 18 
    
    ASC=ASC-1
    '
     if ASC=<65 THEN PAUSE 2000: GOTO main
    GOTO close
    Last edited by grounded; - 13th March 2010 at 12:58.
    " be nice it's people like me that make people like you look smart"
    yes I read the datasheet, of the 300 pages I understood 10

  4. #4
    Join Date
    Mar 2010
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks, guys, now to add some buttons and play with the logic portion

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