get a sensor digital input to work on a pickit 2 16f690 lpc


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Jun 2011
    Posts
    19

    Default get a sensor digital input to work on a pickit 2 16f690 lpc

    First is it possible to run a low voltage digital sensor switch to work on this board and how?

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Hi Jasonstew,
    Please give a bit more detail, I am pretty sure the answer is yes. What voltage and type of sensor do you want? Digital or analog ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    As i said it will be a digital sensor and i believe the voltage is 5 volts, the same as the pickit 2

  4. #4
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Why would you think or wonder that it would not work?

    Have you tried it?? If so what problems did you encounter?

    As Archangel indicated you need to provide enough detail to back up your question.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  5. #5
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    I was just wondering how to use digital sensors on PIC's

  6. #6
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Can you give a specific part number of the sensor?
    or some example code that you have tried?

    I(we) are quite willing to helpl but need enough detail so that the question can be addressed.

    As you probably know, there are litterally hundreds of digital and analog sensors.
    Are you trying to sense light, temperature, sound, mass, movement?

    Here is an article showing how to interface with one or many "Dallas Semiconductor 1-wire Temperature sensors (DS18B20)"

    http://www.picbasic.co.uk/forum/cont...r-nine-of-them
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Well JasonStew,
    Digital is simple, if you have the 5 v it is a one and if not it is a zero, so set one of the ports to input, just for hoots I will say PortB.7 like so TRISB = %10000000 and now portb.7 is an input. Now really simple Psuedocode If Portb.7 = 1 then portb.6 = 1 and viola if portb.7 is switched on then it switches the output on portb.6 to on status. You see I set the other 3 usable ports on PortB as outputs in the tris statement. I think it causes less confusion if you get in the habit of using all 8 bits in your port and register declarations even when the port has "unimplemented" bits like the 4 lower bits(ports) in portb of the 16f690. When you setup the ports and tris registers, it seems counter intuitive but set the port register first then set up the tris register. That way any outputs are set to the desired state before they become outputs (THANKS BRUCE ).
    Last edited by Archangel; - 24th June 2011 at 17:04.

  8. #8
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Thank you I was successful with that now how would i do it with an analog sensor with similar voltages

  9. #9
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Also with the digital sensor program, the light turns on when the state changes, but won't shut off unless i push the button on the lpc. Why? Thanks again. This is the code:

    '-------------------------------< Blinky LED >------------------------------------
    '
    ' File name : BlinkyLed.bas
    ' Version : 1.0
    ' Company : Mister E
    ' Programmer : Steve Monfette
    ' Date : June 22, 2011
    ' Device : PIC16F690
    '
    '---------------------------------------------------------------------------------

    '---------------------------< Project description >-------------------------------
    '
    ' Beginner code example to blink a Led on PORTc.0 using:
    ' 1) PBPDEMO version
    ' 2) MicroCode Studio
    ' 3) PICKIT 2 Programmer
    '
    '---------------------------------------------------------------------------------

    '----------------------------< Hardware listing >---------------------------------
    '
    ' - Microchip Low Pin Count Demo Board
    ' - PIC16F690 installed
    ' - *** All jumper have to be installed ***
    ' - Target board will be powered by the PICKIT 2
    '
    '---------------------------------------------------------------------------------

    '
    ' Pic Configuration
    ' =================
    ' All PIC configuration fuses (Configuration bits) are listed in the
    ' C:\PBPDEMO\p16f690.inc file. Also see datasheet section 14.1
    '

    ' _INTRC_OSC_NOCLKOUT: Using Internal Oscillator
    ' _WDT_ON: Enable Watch Dog Timer
    ' _MCLRE_ON: Enable MCLR
    ' _CP_OFF: Disable Code Protection
    ' _CPD_OFF: Disable Data Code Protection
    ' _FCMEN_OFF: Disable Fail Safe Clock Monitor
    ' _IESO_OFF: Disable Internal/External switchover
    ' _BOR_ON: Enable Brown out detect
    ' _PWRTE_ON: Enable Power up Timer
    '
    OSCCON = %01110000 ' datasheet section 3
    ' -x-------- n/a
    ' --111----- IRCF<2:0> Internal Oscillator Frequency Select Bits (8MHz)
    ' -----xxxx- Read Only
    '
    DEFINE OSC 8 ' tells PBP we use a 8 MHZ clock

    '
    ' Hardware assignment
    ' ===================
    ' Here we assign Aliases to PORT pin
    ' this makes the code easier to read
    ' I'll use the Aliases name as written on the schematic
    '
    ' LEDs
    ' ----
    DS1 VAR PORTC.0
    DS2 VAR PORTC.1
    DS3 VAR PORTC.2
    DS8 VAR PORTC.7


    '
    ' Hardware configuration
    ' ======================
    '
    ' I/Os (Datasheet section 4.0 & above)
    ' ------------------------------------
    TRISA = 0 ' All PORTA I/O set as Output (When capable of)
    TRISB = 0 ' All PORTB I/O set as Output
    TRISC = 0 ' All PORTC I/O set as Output
    '
    ' ADCs (datasheet section 9)
    ' --------------------------
    ANSEL = %00000000 ' Set all pins digital

    ANSELH = %00000000
    WPUA = %00000011 ' Enable pullups for buttons
    WPUB = %00000000

    '
    ' Comparator (datasheet section 8)
    ' --------------------------------
    ' At Power On, the comparator are already disabled
    ' but let's play safe.
    '

    CM1CON0 = 0 ' Disable comparator 1
    CM2CON0 = 0 ' Disable comparator 2

    '
    ' Software/Hardware initialisation
    ' ================================
    PORTA = 0 ' clear PORTA output pins (0v)
    PORTB = 0 ' clear PORTB output pins (0v)
    PORTC = 0 ' clear PORTC output pins (0v)

    WHILE !OSCCON.2 : Wend ' Wait untill the internal OSC get stable

    i Var Byte
    '------------------------------< Main program >-----------------------------------
    '
    START:
    iF (PORTC.7= 1) THEN
    PORTC.0 = 1
    ELSEIF (PORTC.7 != 1) THEN
    PORTC.0= 0
    ENDIF
    PAUSE 1000
    PORTC.0=0

    GOTO Start





    '

  10. #10
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Hey Jason... Looks like you are making progress. At least you are getting LED's to blink, instead of fighting with compilers.

    I have not tried your example program above, but you might try reversing the order of your "IF" statements.

    your code:
    Code:
    START:
    iF (PORTC.7= 1) THEN 
    PORTC.0 = 1
    ELSEIF (PORTC.7 != 1) THEN
    PORTC.0= 0
    ENDIF
    PAUSE 1000 
    PORTC.0=0
     
    GOTO Start

    With the IF statements reversed:
    Code:
    START:
    IF PORTC.7 = 0 THEN
    PORTC.0= 0
     
    ELSEIF PORTC.7= 1 THEN 
    PORTC.0 = 1
     
    ENDIF
    PAUSE 1000 
    PORTC.0=0
     
    GOTO Start
    How about this...
    Code:
    Start:
    PortC.0=PortC.7
    Pause 1000
    goto Start
    If you are useing the LPC demo board the push button is tied to MCLR which is resetting your PIC each time you push it, thus causing the LED to go off because you set portC =0 in your program.

    In order to do something similar with an analog sensor you would configure the pin as an analog input instead of digital... I will try and dig up a simple analog example and post it.

    One good tool that I find helpful would be to search on 16F690 and just look at various examples and try to see what others have done. Also look through various code examples in the "WIKI" section at the top of the forum. You might also look over on the MELabs web site, where they have several code examples for various PIC functions.

    PS. instead of using the Quote function to display code in your posts... Move over to the next icon "#" which is used to post code examples.
    Last edited by Heckler; - 26th June 2011 at 04:54.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  11. #11
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    OK Jasonstew,
    Here is a code that makes "cylon" eye pattern, and speed will be controled by the rheostat on your board.
    Code:
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF 
    @ __config  MyConfig 
    
    DEFINE OSC 4
    DEFINE ADC_BITS 8
    DEFINE  ADC_CLOCK 1
    DEFINE ADC_SAMPLEUS 50
    PortA = 1
    PortB = 0
    PortC = 0
    TRISA = 1
    TRISB =%01010000
    TRISC = %00000000
    i var word 'locks up @ 255 with byte
    ANSEL = 1
    ANSELH = 0
    CM1CON0 = 0
    CM2CON0 = 0
    Backlight Var word
    
    
    main:
    
    
    ADCIN 0,BACKLIGHT
    
    for i = 1 to 255
    portC = i
    i=i  << 1 - 1
    pause backlight
    next i
    for i = 255 to 1 step -1
    i=i >> 1 + 1
    portc = i
    pause 25
    next i
    
    goto main
    end
    Do not make too much over the variable names, I recycled some code in this.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    Quote Originally Posted by Jasonstew View Post
    Also with the digital sensor program, the light turns on when the state changes, but won't shut off unless i push the button on the lpc. Why? Thanks again. This is the code:
    In your code, your TRISC line is not right, you must set some inputs there.... as it is right now, there's only OUTPUT. Change it to
    Code:
          ' 
          '  76543210
    TRISC = %10000000
          ' -1-------- PORTB.7 = INPUT
          ' --0000000- PORTB<6:0> = OUTPUT
    And then your main loop may looks like...
    Code:
    Start:
            IF PORTC.7 = 1 THEN
                    PORTC.0 = 1
                    ELSE
                            PORTC.0 = 0
                    ENDIF
            PAUSE 1000
            GOTO Start
    OR.. WAY easier
    Code:
    Start:
            PORTC.0 = PORTC.7
            PAUSE 1000
            GOTO Start
    In your code, you enable the Pull up on PORTA, there's no internal pull-up available for PORTC, so I hope you have one
    Last edited by mister_e; - 26th June 2011 at 09:31.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    mi pickit2 constantly gets busy after around 15 seconds and i am forced to recompile why?

  14. #14
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    That's because of your code in line 11.

    Just kidding, how could we possibly know what the problem might be from what you wrote? So now I am going to sound like a teacher and ask for at least a sentence for each of these topics. (Nah, a teacher would have asked for a paragraph on each)

    1. Gets busy? Busy doing what?

    2. 15 seconds after what?

    2. Recompile, what is forcing you to do this, and why?

    3. What are you doing to get here?

    4. Any errors?

    5. Any code?

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    6. Are you using the PICKIT 2 Standalone application, or the command line? If so, make sure you don't run 2 instances (or more) of the application.

    7. What if you change TRISA to...
    Code:
    TRISA = 255
    Last edited by mister_e; - 26th June 2011 at 16:31.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Jun 2011
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: get a sensor digital input to work on a pickit 2 16f690 lpc

    The problem was solved whjen i changed the code to portc.0 = portc.7. Thanks.

Members who have read this thread : 1

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