PIC16F877A, How to add timer delays on output?


Results 1 to 6 of 6

Threaded View

  1. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: PIC16F877A, How to add timer delays on output?

    Code:
    @ DEVICE pic16f877a,WDT_ON, PWRT_ON, BOD_ON
    DEFINE OSC 4
    define ADIN_RES 10
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    RLH VAR word
    SLM var word
    position var word
    COUNT1 VAR BYTE ' COUNTER FOR PORTD.5
    COUNT2 VAR BYTE ' COUNTER FOR PORTD.6
    TRISA = %00000011
    TRISB = %00000000
    TRISD.0 = %0
    TRISD.1 = %0
    ADCON0 = %11000101
    ADCON1 = %10000000
    low portd.7
    
    COUNT1 = 0
    COUNT2 = 0
    
    START:
    
    ADCIN 0 , RLH
    ADCIN 1 , SLM
    
    IF (PORTD.5=1) AND (COUNT1<50) THEN SKIP1 '50 LOOPS WILL BE ~1 SEC
    IF RLH =< 621 then
      high PORTD.5
      else
      low PORTD.5
    endif
    COUNT1 = 0
    
    SKIP1:
    IF (PORTD.6=1) AND (COUNT2<50) THEN SKIP2
    IF SLM => 621 then
        high PORTD.6
        position = 100
        else 
        low PORTD.6
        position = 170
    endif
    COUNT2 = 0
    
    SKIP2:
    
    PULSOUT PORTD.7, position
    pause 18
    COUNT1 = COUNT1 + 1
    COUNT2 = COUNT2 + 1
    GOTO START
    QUOTE]
    I made some assumptions here. I assumed if you wanted to keep them high, you didn't need to check the sensor readings.

    I used 50 for the loop count because of this: pulseout will be between 1-2 mSec, then an 18mSec pause. this is 19-20 mSec. * 5= .1sec * 10 = 1 sec. This won't be exact, but you can play with the numbers to get it right
    Last edited by cncmachineguy; - 2nd March 2011 at 20:35. Reason: added color
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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