It is currently 16 Dec 2017 14:19

All times are UTC + 1 hour




Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Word
PostPosted: 27 Aug 2008 20:03 
Offline

Joined: 30 Jun 2008 07:10
Posts: 15
Hi Dany
Thanks for your replies. I try and change it.


Last edited by DDJ on 28 Aug 2008 06:42, edited 1 time in total.

Top
 Profile  
 
 Post subject: CCP
PostPosted: 27 Aug 2008 20:09 
Offline

Joined: 30 Jun 2008 07:10
Posts: 15
Dany
Would it not be easier to use the CCP module here? I have never worked with it, but from a few posts it seems less complicated. What do you think ? The CD4093 puts out square wave pulses. Is it easy to measure these with CCP ?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: 27 Aug 2008 23:29 
Offline

Joined: 01 Dec 2004 22:29
Posts: 2734
Quote:
By saying I have to do it the hard way round, is that with a counter


No.The Counter command makes counting pulses easy.I think Dany has answered you question about your code.

_________________
Regards Charlie M.


Top
 Profile  
 
 Post subject: It works !
PostPosted: 28 Aug 2008 06:39 
Offline

Joined: 30 Jun 2008 07:10
Posts: 15
Thanks Dany, I changed the byte type to word and it works. Thanks again to everyone who helped me. This forum is really great.
sub procedure LCD_BarGraph_Draw(dim Row as byte, dim Column_Start as byte, dim Column_End as byte, dim Value as word)


Top
 Profile  
 
 Post subject: Re: CCP
PostPosted: 28 Aug 2008 09:34 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3730
Location: Nieuwpoort, Belgium
DDJ wrote:
Dany
Would it not be easier to use the CCP module here? I have never worked with it, but from a few posts it seems less complicated. What do you think ? The CD4093 puts out square wave pulses. Is it easy to measure these with CCP ?
Thanks
Well, I have never worked with the CCP either, it is on my list to try it out... :D

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
PostPosted: 26 Jul 2011 22:03 
Offline

Joined: 26 Jul 2011 21:48
Posts: 6
Hi am just new here , i have a problem i have the easy pic 5 , and mikrobasic v5.1 and i want to use the example pulsein_demo but it wont work what do i wrong can someone help me ,and whit the other example of the lcd thats works
then i get some text , but whit the pulsein_demo i get no text , thanks


Top
 Profile  
 
PostPosted: 14 Aug 2011 15:11 
Offline

Joined: 26 Jul 2011 21:48
Posts: 6
hi i have try to make the pulsein_demo works on the pic16F887 and the easypic 5 in mikrobasic 5.1 and its works now continuously if you push the button D0 three times the display show 3 , and if you push him 5 times he shows 5 .
but how can i make this to also counts the pulses , if i connect my rc reciever and i go whit the stick up and down its dont change , what do i wrong , can you guys help me ,thanks

here mij code :
'(*
' * Project name:
'
' * Copyright:
'     (c) mikroElektronika, 2006
' * Revision History:
'     20050914 (MJ):
'       - initial release.
' * Description:
'     This code demonstrates using Pulse-In Function for counting pulses in given
'     time period. This a blocking call. This demo waits for input signal
'     (high level) to start counting pulses. It counts pulses for 1000 miliseconds.
'     Then it prints results on LCD which is connected on PORTB.
' * Test configuration:
'     MCU:             P16F887
'     Dev.Board:       EasyPIC5
'     Oscillator:      HS, 8.000 MHz
'module pulsein_demo.mbas
'     SW:              mikroBasic v5.0 or higher
' * NOTES:
'     Prototype:
'       function Pulse_In(dim byref port as byte, dim pin, state as byte, dim duration as word)as word
'
'     PORT  - assigns port for pulse-in function
'     PIN   - assigns pin for pulse-in function
'     STATE - defines logical state for counting pulses (LOW = 0 or HIGH = 1)
'     DURATION - Time in ms during which the pulses are being count
'
'     This function returns number of pulses in given time (DURATION), on given
'       PORT and PIN.
'     Tested on EasyPIC3 with P16F877A. With few modification it can be used
'       with almost every PIC MCU.
' *)
program pulsein_demo

dim LCD_RS as sbit  at RB4_bit    ' Lcd module connections
    LCD_EN as sbit  at RB5_bit
    LCD_D4 as sbit  at RB0_bit
    LCD_D5 as sbit  at RB1_bit
    LCD_D6 as sbit  at RB2_bit
    LCD_D7 as sbit  at RB3_bit

    LCD_RS_Direction as sbit at TRISB4_bit
    LCD_EN_Direction as sbit at TRISB5_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit         ' End Lcd module connections

dim text as string [16]           ' Variable text is of string type

dim counter,
    msec,
    num_impulse as word
    txt         as char[10]
dim tmp as word                               ' Temporary variable
    old as byte
sub procedure interrupt
   counter = counter + 1                               ' Increment value of counter on every interrupt
   if counter = 1 then                        ' Has 1ms elapsed?

     counter = 0

     msec = msec + 1                                ' Increment msec on every 1 ms
   end if
   TMR0 = 0
  INTCON = 0x20                    ' Clear the TMR0IF flag  Enable TMRO interrupt

end sub

sub function Pulse_In(dim byref port as byte, dim pin, state as byte, dim duration as word)as word
                              ' Previous pin state value

  tmp  = 0                                    ' Clear temporary variable
  msec = 0

  while TestBit(port, pin) = state            ' Wait for pulses

  wend                                        ' Note that the program will stop here
                                              '   if there are no pulses

                                   ' Note that the program will stop here
    while TestBit(port, pin) <> state           ' Wait for rising (falling) edge

    wend                                           '   if there are no pulses

                                ' Clear number of ms
  old  = TestBit(port, pin)                   ' Get current pin state

                                              '   if there are no pulses
  while duration > msec                       ' Check if duration is reached
     if (TestBit(port, pin)) <> old then     ' Check if pin state has changed

       tmp = tmp + 1

        old = TestBit(port, pin)              ' Get current pin state
     end if
  wend

    result = (tmp >> 1) + 1                   ' Assign result value
end sub

main:
  OPTION_REG = 2                           ' Assign prescaler to TMR0 (1:8)

  PORTB = 0xFF
  TRISB = %0000000
  ANSEL = 0
  ANSELH = 0
  PORTD = 0
  TRISD = %1000000


   Lcd_Init()                      ' LCD display initialization
  Lcd_Cmd(_LCD_CURSOR_OFF)        ' LCD command (cursor off)
  Lcd_Cmd(_LCD_CLEAR)             ' LCD command (clear LCD)

   text = "Puls meting"       ' Define the first message
  Lcd_Out(1,1,text)               ' Write the first message in the first line
   text = "Tijd : "       ' Define the first message
  Lcd_Out(2,1,text)               ' Write the first message in the first line


    while 1
  counter = 0
  TMR0  = 0
  INTCON = 0xA0                                ' Enable TMRO interrupt

 msec = 0                                    ' Clear msec
 num_impulse = 0                             ' Clear num_impulse


  CM1CON0.C1ON  = 0                                ' Comparators off
  CM2CON0.C2ON = 0



  num_impulse = Pulse_In(PORTD, 0, 1, 1000)   ' Count HI pulses on PORTD.0, for 1000ms

  WordToStr(num_impulse, txt)                 ' Convert results to string for LCD output
   'WordToStr(num_impulse, txt)                 ' Convert results to string for LCD output
  Lcd_Out(2,6, txt)               ' Write the first message in the first line Lcd_Out(2, 1, txt)

  wend                                        ' Wait forever (stop)
end.


Top
 Profile  
 
PostPosted: 14 Aug 2011 19:50 
Offline

Joined: 26 Jul 2011 21:48
Posts: 6
hi i have use you example and make it to use for the pic16F887 , whit the easypic5 and mb5.1 .
its not counting the time between the pulses because if i change my stick of my receiver nothing is gone change .
here is the code :
'(*
' * Project name:
'
' * Copyright:
'     (c) mikroElektronika, 2006
' * Revision History:
'     20050914 (MJ):
'       - initial release.
' * Description:
'     This code demonstrates using Pulse-In Function for counting pulses in given
'     time period. This a blocking call. This demo waits for input signal
'     (high level) to start counting pulses. It counts pulses for 1000 miliseconds.
'     Then it prints results on LCD which is connected on PORTB.
' * Test configuration:
'     MCU:             P16F887
'     Dev.Board:       EasyPIC5
'     Oscillator:      HS, 8.000 MHz
'module pulsein_demo.mbas
'     SW:              mikroBasic v5.0 or higher
' * NOTES:
'     Prototype:
'       function Pulse_In(dim byref port as byte, dim pin, state as byte, dim duration as word)as word
'
'     PORT  - assigns port for pulse-in function
'     PIN   - assigns pin for pulse-in function
'     STATE - defines logical state for counting pulses (LOW = 0 or HIGH = 1)
'     DURATION - Time in ms during which the pulses are being count
'
'     This function returns number of pulses in given time (DURATION), on given
'       PORT and PIN.
'     Tested on EasyPIC3 with P16F877A. With few modification it can be used
'       with almost every PIC MCU.
' *)
program pulsein_demo

dim LCD_RS as sbit  at RB4_bit    ' Lcd module connections
    LCD_EN as sbit  at RB5_bit
    LCD_D4 as sbit  at RB0_bit
    LCD_D5 as sbit  at RB1_bit
    LCD_D6 as sbit  at RB2_bit
    LCD_D7 as sbit  at RB3_bit

    LCD_RS_Direction as sbit at TRISB4_bit
    LCD_EN_Direction as sbit at TRISB5_bit
    LCD_D4_Direction as sbit at TRISB0_bit
    LCD_D5_Direction as sbit at TRISB1_bit
    LCD_D6_Direction as sbit at TRISB2_bit
    LCD_D7_Direction as sbit at TRISB3_bit         ' End Lcd module connections

dim counter,
    msec,
    num_impulse as word
    txt         as char[10]

sub procedure interrupt
   inc(counter)                               ' Increment value of counter on every interrupt
   if counter = 1 then                        ' Has 1ms elapsed?
     counter = 0                              ' Clear the counter
     inc(msec)                                ' Increment msec on every 1 ms
   end if
   TMR0 = 5
   ClearBit(INTCON, T0IF)                     ' Clear the TMR0IF flag
   SetBit(INTCON, T0IE)                       ' Enable TMR0 interrupt
end sub

sub function Pulse_In(dim byref port as byte, dim pin, state as byte, dim duration as word)as word
dim tmp as word                               ' Temporary variable
    old as byte                               ' Previous pin state value

  while TestBit(port, pin) = state            ' Wait for pulses
  wend                                        ' Note that the program will stop here
                                              '   if there are no pulses

  while TestBit(port, pin) <> state           ' Wait for rising (falling) edge
  wend                                        ' Note that the program will stop here
                                              '   if there are no pulses

  tmp  = 0                                    ' Clear temporary variable
  msec = 0                                    ' Clear number of ms
  old  = TestBit(port, pin)                   ' Get current pin state

  while duration > msec                       ' Check if duration is reached
     if (TestBit(port, pin)) <> old then      ' Check if pin state has changed
        inc(tmp)                              ' Increment number of pulses
        old = TestBit(port, pin)              ' Get current pin state
     end if
  wend

    result = (tmp >> 1) + 1                   ' Assign result value
end sub

main:
  OPTION_REG =  1                             ' Assign prescaler to TMR0 (1:8)
  TRISB  = $00                                ' Designate PORTB as output
  PORTB  = $FF                                ' Initialize PORTB

  TRISD  = $FF                                ' Designate PORTD as input (for signal)

  counter= $00                                ' Initialize the counter
  TMR0  = 5
  INTCON = $A0                                ' Enable TMRO interrupt
  'ANSEL = 0
  ANSELH = 0
  msec = 0                                    ' Clear msec
  num_impulse = 0                             ' Clear num_impulse

  ADCON1 = $FF                                ' PORTB all digital
  CM1CON0 = $06                                ' Comparators off
  CM2CON0 = $06
  CM2CON1 = $06
 
  Lcd_Init()                             ' Initialize LCD connected to PORTB
  Lcd_Cmd(_LCD_CURSOR_OFF)                          ' Send command to LCD "clear display"
  Lcd_Cmd(_LCD_CLEAR)                     ' Send command "cursor off"


  Lcd_Out(1, 1, "Waiting...      ")           ' Print txt to LCD
  num_impulse = Pulse_In(PORTD, 0, 1, 1000)   ' Count HI pulses on PORTD.0, for 1000ms
  WordToStr(num_impulse, txt)                 ' Convert results to string for LCD output
  Lcd_Out(1, 1, "Number of pulses")           ' Print txt to LCD
  Lcd_Out(2, 1, txt)                          ' Print number of pulses to LCD
  while 1 = 1
  wend                                        ' Wait forever (stop)
end.


its a good example but to measuring the time of the pulses of rc receivers the time of 1ms a time is to big because
1ms - 1.5ms - 2ms the max of the difference of the pulses is 1 ms that he max can display but not between them
how can this so be make that the counting of ms becomes of 100us thank you for your help


Top
 Profile  
 
PostPosted: 23 Nov 2017 13:12 
Offline

Joined: 09 Apr 2011 01:35
Posts: 5
Good morning, Marko.
I'm trying to download the PulseIn example, but it's giving error.
Can you help me?
I'll be very grateful!!
Thank you very much


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: