12f675 programming question


Closed Thread
Results 1 to 4 of 4
  1. #1
    puggy's Avatar
    puggy Guest

    Post 12f675 programming question

    this program is used in a metal detector. An analog signal goes into pin 6 of the 12f675. the way the program should work is that if a button is being pressed a 5V signal will be sent to pin 4. After every a/d pin 4 is checked to see if there is a digital 1 or 5V. If so then the value stored in ADRESL from the a/d should be stored in temp (variable stored in memory). when the button is not pressed the program will take the new data from ADRESL and subtract the value stored in temp from it. after this subtraction if the carry bit in the status register is clear the pic will turn on pin 5 and then turn it off which makes a wave that can be heard throw a speaker.

    here is my code

    list p=12F675;
    #include <p12F675.inc>

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF

    #define boy D'255';
    #define man 0x20;
    temp EQU 0x21

    bcf STATUS,RP0
    clrf GPIO
    movlw 07h
    movwf CMCON
    movlw 85h
    movwf ADCON0
    bsf STATUS,RP0
    movlw 02h
    movwf ANSEL ;sets pin 6 as analog input
    movlw 0Ah
    movwf TRISIO ;sets pin 4 and 5 as outputs 6 as input
    bcf STATUS,RP0

    ad
    movlw 87h
    movwf ADCON0
    adfinish
    btfsc ADCON0,1
    goto adfinish

    btfsc GPIO,GPIO3 ;tests if button is pressed
    goto reference

    movlw 0FFh
    bsf STATUS,RP0
    andwf ADRESL,1
    bsf STATUS,C
    bcf STATUS,RP0
    movlw temp
    bsf STATUS,RP0
    subwf ADRESL,1
    btfsc STATUS,C ;check if signal is greater than 0
    goto ad ;no metal perform next A/D

    on
    ;turn pin on
    bcf STATUS,RP0
    movlw 04h
    movwf GPIO
    call delay;

    ;turn pin off
    movlw 00h
    movwf GPIO
    call delay
    goto ad

    reference
    bsf STATUS,RP0
    movf ADRESL,0
    bcf STATUS,RP0
    movwf temp
    goto ad


    delay;

    movlw boy;
    movwf man;
    loop;
    decfsz man,f;
    goto loop;
    return;

    end

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


    Did you find this post helpful? Yes | No

    Default

    and the question is ???
    Steve

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

  3. #3
    puggy's Avatar
    puggy Guest


    Did you find this post helpful? Yes | No

    Default

    the program is not working. ill use a function generator to simulate the analog input. ill tie pin 4 high and let it run for a few seconds. then ill remove the 5V connection to pin for so when i adjust the amplitude on the function generator a sound should come out of a speaker connected to the output pin 5. but there is no sound coming out. im just wondering if any one sees any silly mistakes or has an idea to change a portion of my code

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


    Did you find this post helpful? Yes | No

    Default

    o.k if i understand you want to measure the amplitude of an incoming frequency right?

    in this case a/d conversion time will gives you some crazy results. Also it depend on which part of your frequency cycle the A/D take the voltage measure too... so in this case you can monitor and compare few reading and take the highest one BUT

    I suggest you to convert frequency to voltage. You can do it simple with an OP-AMP as a full-wave rectifier and put an capacitor to the output to get *clean* voltage.

    regards
    Last edited by mister_e; - 30th November 2004 at 23:44.
    Steve

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

Similar Threads

  1. Still 12F675 question
    By F1CHF in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th August 2009, 21:09
  2. 12F675, MPLAB programming question
    By EASY in forum General
    Replies: 0
    Last Post: - 2nd April 2006, 19:28
  3. Normal programming question
    By stevenlkz in forum General
    Replies: 4
    Last Post: - 13th June 2005, 14:59
  4. 12f657 programming question
    By puggy in forum General
    Replies: 3
    Last Post: - 8th October 2004, 16:28
  5. 12f675 internal osc question.....
    By Gabe@SPdFtsh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th January 2004, 06:33

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