Menu

signal pulsin and then tansmit value via usart, not getting anything

Help
2015-02-25
2015-02-28
<< < 1 2 (Page 2 of 2)
  • tony golding

    tony golding - 2015-02-27

    thanks bill and kent.

    after finally getting progress made on this with good results its nice to see that we can alter the available features if they need to be tweeked to our needs, not something ive done before and a new concept that will get used more at some point im sure.

    as the whole pulsin was the key issue for moving some of my code over it can at least now allow me to move forward and get started on that some point soon.

    thankyou for the examples they are a great reference and help.

    tony

     
  • William Roth

    William Roth - 2015-02-28

    Another (and probably better) method to detect the duration of a pulse is to use Timer1. A High signal starts the timer and a Low signal stops the timer. With an 8MHz clock and a timer Prescaler value of 2, each timer tick is 1 microsecond.

    I did this using a PIC18F690 but should work fine on any PIC with Timer 1. I think this is better than counting instruction cycles like the first example. This should be as accurate as the clock source with an uncertainty of about 1 - 2us. The Macro will measure pulses from about 8us to 65,535 microseconds with good accuracy. With an input signal of 1ms it consistently reads between 999 and 1000us. Note that I used a macro instead of a sub.

    ; Measure Positive Pulse Width Test Code
    ; Using Timer 1
    
     #chip 16F690,8
    
     ;USART settings
     #define USART_BAUD_RATE 9600
     #define USART_BL0CKING
     DIR PORTB.7 OUT
    
      ;Input Pin and Direction
      #define InPin PORTC.6
      Dir InPin In
      Dim Time_us As WORD
    
      ;Init timer and clear value to zero
      InitTimer1 Osc, PS1_2
      ClearTimer 1
    
     ; Main Program starts here
     Do
        Pulse_In (InPin, time_us)
        HserPrint time_us
        HserPrintCRLF
     Loop
    
     macro Pulse_In (Pin, Variable)
         ;Make sure the pin is not already high
         Wait Until Pin = OFF
    
         ;Start timer on signal high
         Wait Until Pin = ON
         StartTimer 1
    
         ;Stop timer on signal low
         Wait Until Pin = Off
         StopTimer 1
         variable = Timer1
         ClearTimer 1   
    
     end macro
    
     
<< < 1 2 (Page 2 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.