Using A Ds18s20 And Servo


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25

    Default Using A Ds18s20 And Servo

    Hi everyone,
    I am having difficulties using the ds18s20 and servo together on the pic16f88.
    I find that i can't keep the 50Hz req for the servo except when its only running the servo code alone. The ds18s20 is working very well.
    What i am hoping to achieve here is when the temp moves either up or down the servo will move to try and maintain the correct temp.
    This also needs to be fast as there is more code to come.

    Regards
    Crazy Cooter
    Attached Files Attached Files
    IF ITS STOCK IT WONT ROCK

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


    Did you find this post helpful? Yes | No

    Talking Datasheets !!!

    Hi, Cooter

    Just find the conversion time of the 18B20 and that's all ...

    I committed that some years ago ... the servo opens and closes air vents for a "Corsair" model plane ...

    might suit your needs ... I wonder !

    Alain
    Attached Files Attached Files
    ************************************************** ***********************
    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
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks ACETRONICS for a speedy response. I will have a look at it tomorrow as its late here in Australia.

    Regards
    Crazy Cooter
    IF ITS STOCK IT WONT ROCK

  4. #4


    Did you find this post helpful? Yes | No

    Default real time servos with slow sensors

    I have some code that refreshes servos at 50 Hz and reads some DS1620 slow temperature sensors - they take 400 - 1000 mSecs about the same as the DS1820 I think. I do it with a loopcounter and issue the conversion request in one pass then 1000 mSecs later read the result. SOmething like

    MainLoop:
    LoopCtr + 1
    if LoopCtr > 50 then loopCtr = 0
    if LoopCtr = 1 then TempConversion
    if LoopCtr = 0 then ReadTemperature

    ServoCodeHere:
    Low ServoPin
    Pulsout ServoPin, ServoWidth
    Delay to give 20 mSec looptime
    Goto MainLoop

    TempConversion:
    Issue code to start the temperature conversion - don't wait for result
    Goto MainLoop

    ReadTemperature:
    Issue code to read most recent temperature conversion
    Goto MainLoop

    HTH
    Brian

  5. #5
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks Brian your code idea works a treat. So how come yours does and mine doesn't????? I just don't understand why not. The only issue now i have is the servo keeps resetting itself(matter of speach) goes in the direction i want holds for a second then rotates all the way back then rotates back to where it should be. I require the servo to stay put how do i go about this as my code does not do this when in my head it should. what am i doing wrong

    the code..

    Code:
    OSCCON = %01101000 'INTRC = 4 MHz
    TRISA = %11111111
    ANSEL = 0  'DISABLE ALL ADC
    CMCON = 7 'DISABLE ALL ANALOG COMPARATOR
    WHILE OSCCON.2=0:WEND 'STABILISE THE CLOCK
    ADCON1 = 1
    DEFINE OSC 4 
    PAUSE 1000
    '-------------------------------------------------------------------------------
    
    '-------------------------------------------------------------------------------
    DEFINE LCD_DREG         PORTB
    DEFINE LCD_DBIT         4 '4,5,6,7
    DEFINE LCD_RSREG        PORTB
    DEFINE LCD_RSBIT        3
    DEFINE LCD_EREG         PORTB
    DEFINE LCD_EBIT         2
    DEFINE LCD_BITS         4
    DEFINE LCD_LINES        2
    DEFINE LCD_COMMANDUS    2000
    DEFINE LCD_DATAUS       50
    pause 1000
    lcdout $fe, 1
    
    '-------------------------------------------------------------------------------
    ServoWidth var byte
    ServoPin Var PORTB.0
    ServoWidth = 1500
    DQ	VAR	PORTA.1			' One-wire data pin
    b3 var byte
    b3 = 1200
    temperature VAR	WORD			' Temperature storage
    count_remain VAR BYTE			' Count remaining
    count_per_c VAR	BYTE			' Count per degree C
    TEMP VAR WORD
    LoopCtr var byte
    '-------------------------------------------------------------------------------
    
    MainLoop:
    
    LoopCtr = LoopCtr + 1
    if LoopCtr > 50 then loopCtr = 0
    if LoopCtr = 1 then TempConversion
    IF TEMP > 24 THEN ServoWidth = ServoWidth - 1
    IF TEMP < 22 THEN ServoWidth = ServoWidth + 1
    if TEMP = 23 THEN ServoWidth = ServoWidth + 0
    if LoopCtr = 0 then ReadTemperature
    
    ServoCodeHere:
    Low ServoPin
    if ServoWidth = 1105 then high ServoPin ' servo stop
    if ServoWidth = 1895 then high ServoPin ' servo stop
    
    Pulsout ServoPin, ServoWidth
    'Delay to give 20 mSec looptime
    PAUSE 18
    Goto MainLoop
    
    TempConversion:
    'Issue code to start the temperature conversion - don't wait for result
     OWOut DQ, 1, [$CC, $44]       ' Start temperature conversion
    Goto MainLoop
    
    ReadTemperature:
    'Issue code to read most recent temperature conversion
    DS18S20WAITLOOP: OWIn DQ, 4, [count_remain]	' Check for still busy converting
    	IF count_remain = 0 Then DS18S20WAITLOOP
    OWOut DQ, 1, [$CC, $BE]		' Read the temperature
            OWIn DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE, Skip 4, count_remain, count_per_c]
            temperature = (((temperature >> 1) * 100) - 25) + (((count_per_c - count_remain) * 100) / count_per_c)
    TEMP = temperature / 100
        LCDOut $fe, 1, DEC (temperature / 100)," C"        
    
    
    Goto MainLoop
    Regards
    Crazy Cooter
    Last edited by lester; - 3rd April 2011 at 17:03.
    IF ITS STOCK IT WONT ROCK

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