revolution counter


Closed Thread
Results 1 to 30 of 30

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    OOo I get the digital part now, no need for ADC.
    I have never used interrupt, can you explain the code snippet you provided above?


    should this work?

    Mainloop:

    'Calculate the distance
    Output_Pot = PortB.3

    if OldOutput_Pot == Output_Pot then
    goto Mainloop
    endif
    if OldOutput_Pot != Output_Pot then
    counter = counter +1 'If oldOutput_pot is different then Output_pot
    OldOutput_Pot = Output_Pot
    if counter =4 then
    Revolution = Revolution + 1
    counter =0
    endif
    endif

    lcdout $FE,1, "Counter:",dec counter
    lcdout $FE,$C0, "Revolution:",dec Revolution
    pause 150

    GOTO Mainloop
    end

    ken

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    still nothing showing on the lcd...

    k

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Well, then get rid of the digital inputs and make sure the LCD is working in the first place...

    And besides, in the beginning of the program, OldOutput_Pot = 0 and Output_Pot = 0 therefore, they're both equal and Mainloop keeps executing! Unless you've preset one or the other to a different value...

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    I got the circuit working now without the ADC, thats the one I will use.
    BUT,I also tried the ADC, it only works in 10 bit mode when I try the 8 bit mode, nothing appears on the LCD. Here the progrm, but before here is the two lines I changed for the 8 bit mode:

    ADCON1 = %10000010
    Define ADC_BITS 8 ' Set number of bits in result

    why is this happening?

    INCLUDE "modedefs.bas" 'Includes supoprt for PicBasic language
    @ DEVICE pic16F88, INTRC_OSC, CCPMX_ON
    OSCCON=$60 ' use internal 4MHZ osc

    ANSEL = 0
    CMCON = 7 ' Turn OFF the comparators so pins can be used as digital I/O-pins
    ADCON1 = %00000010 ' Analog to digital configuration register (ADCON)
    ' Set PORTA to digital

    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    ADCON1 = %10000010 ' Analog to digital configuration register (ADCON)
    ' Set PORTA to digital

    '/////////////////////////
    '// LCD configuration //
    '/////////////////////////

    DEFINE LCD_DREG PORTB ' Set LCD Data port
    DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 0 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits) '4 therefore put wire at 4, 5, 6 and 7 of LCD
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2500
    DEFINE LCD_DATAUS 250
    DEFINE CHAR_PACING 2000
    pause 1000


    '/////////////////////////
    '// PIN configuration //
    '/////////////////////////

    TRISA = %11100111 ' Set PORTA to all input
    TRISB = %00001100 ' Set PORTB to all output
    PortA = 0

    '///////////////////////////////////////////////
    '// Variable Declaration and initialization //
    '///////////////////////////////////////////////
    Output_Pot var byte
    OldOutput_Pot var byte
    Revolution var word
    counter var byte

    revolution = 0
    Output_Pot = 0
    OldOutput_Pot = 0
    counter = 0

    'Get initial value
    'ADCON0.2 = 1 'Start Conversion
    ADCIN 1, OldOutput_Pot 'analog pin 1 (RA1) get the 8 bit result
    pause 50
    if OldOutput_Pot > 512 then
    OldOutput_Pot =1
    else
    OldOutput_Pot =0
    endif

    Mainloop:

    'ADCON0.2 = 1 'Start Conversion
    ADCIN 1, Output_Pot 'analog pin 1 (RA1) get the 8 bit result
    pause 50

    'Calculate the distance
    if Output_Pot > 512 then
    Output_Pot =1
    else
    Output_Pot =0
    endif

    if OldOutput_Pot == Output_Pot then
    goto Mainloop
    endif
    if OldOutput_Pot != Output_Pot then
    counter = counter +1 'If oldOutput_pot is different then Output_pot
    OldOutput_Pot = Output_Pot
    if counter =4 then
    Revolution = Revolution + 1
    counter =0
    endif
    endif

    lcdout $FE,1, "Counter:",dec counter
    lcdout $FE,$C0, "Revolution:",dec Revolution
    pause 150


    GOTO Mainloop
    end

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by lerameur View Post
    BUT,I also tried the ADC, it only works in 10 bit mode when I try the 8 bit mode, nothing appears on the LCD. Here the progrm, but before here is the two lines I changed for the 8 bit mode:
    Did you set it for left justify or right justify? Makes a difference...

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    it is in the code above:

    with this it works:
    ADCON1 = %00000010
    Define ADC_BITS 10 ' Set number of bits in result


    but not:

    ADCON1 = %10000010
    Define ADC_BITS 8 ' Set number of bits in result

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Right, with one you're putting the 10 bit value (justified left) into a byte, with the other, you're putting the 10 bit value (justified right) into a byte, trying to stuff 10 bits into a spot for 8 bits.
    So, with one, you get the lower 8 bits of the 10 bits, with the other you get the upper 8 bits of the 10 bits.
    Which one is it? That's for you to figure out....(hint: if you use a word variable for reading, you'll figure it out quickly if you also use the LCD to display that value)

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 07:14
  2. Counter not counting !!!
    By lerameur in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 20th February 2009, 23:15
  3. Replies: 42
    Last Post: - 14th January 2008, 12:38
  4. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 06:02
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27

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