16f677a to 12f683


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi Chris. I don't think you need to use an ADC input for duty cycle. In MEASUREFREQ below, I used the chip to detect a 3KHZ tone. In the WAITHERE and MEASUREDUTY routine, I used "pause 1" to measure a pulse width up to 255 ms. I don't know what frequencies you're working with but, unless they are really high, you may be able to use something like this.

    FREQ VAR BYTE
    DUTYCYCLETIMER VAR BYTE
    CLEAR 'CLEAR ALL VARIABLES

    MEASUREFREQ:
    Count GPIO.0, 10, FREQ
    IF FREQ > 25 AND FREQ < 35 Then DOSOMETHING 'LOOKING FOR 30 = 3KHZ
    GoTo MEASUREFREQ

    WAITHERE:
    IF GPIO.1 = 0 THEN WAITHERE 'WAIT FOR + PULSE TO MEASURE

    MEASUREDUTY:
    LET DUTYCYCLETIMER = (DUTYCYCLETIMER + 1)
    PAUSE 1
    IF GPIO.1 = 0 THEN FINISHED
    GOTO MEASUREDUTY

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    ANSEL configures A/D pins as digital or analog. CMCON0=7 disables analog
    comparators, and TRISIO is the TRIS reg on this one, so,
    Code:
    @ device  pic12F683, hs_osc, wdt_off, mclr_off, protect_off
    
    DEFINE OSC 20
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3      ' Frc clock
    DEFINE ADC_SAMPLEUS 20  ' sample time in uS
    
    'Variables
    PulseWidth VAR BYTE
    Freqtmp VAR BYTE
    Frequency VAR Word
    TRISIO = %00111011 ' all inputs except GPIO.2
    ANSEL = %00000011  ' GPIO.0, GPIO.1 = analog, rest digital
    CMCON0 = 7         ' comparator module disabled
    
    Loop: 
    'Read Input Variables
    ADCIN 0, PulseWidth 'Read analog in on GPIO.0
    ADCIN 1, Freqtmp    'Read analog in on GPIO.1
    Frequency = Freqtmp * 100 'Make Freq = 0-25,500hz in 100hz intervals
    
    'Send Pulse
    HPWM 1, PulseWidth, Frequency 'Send PWM with variable Duty and Frequency PinC.2 on 16f677A
    
    Pause 500
    goto Loop 'Do it forever
    Note: The minimum frequency with HPWM running at 20MHz is ~1,221hz, so
    you might get odd action on CCP1 once the A/D input falls below ~255mV.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Thank you, thank you.
    This is definitely what I was missing:
    TRISIO = %00111011 ' all inputs except GPIO.2
    ANSEL = %00000011 ' GPIO.0, GPIO.1 = analog, rest digital
    CMCON0 = 7 ' comparator module disabled

    So, the % thing simply sets each IO pin on or off explicitly? As in the the eighth position stands for IO0, the seventh for IO1, the sixth for IO2 etc? And since this PIC only has 6 useable IO pins, we only set the last six bits?
    Same for ANSEL?

    Holy Cow, I think I'm having an Ah Ha moment! And the decimal equivalent is
    1 + 2 + 8 + 16 + 32 = 59 ....??? So would it work if the setting was TRISIO = 59 ?

    Is it really that simple?

  4. #4
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    How does one come to the conclusion that CMCON = 7?
    Am I correct in saying that the reason it is seven is because there are only the last three bits in the CMCON register that sets this? Looking at the data sheet I see:
    7 6 5 4 3 2 1 0
    19h CMCON0 — COUT — CINV CIS CM2 CM1 CM0

    Actually, a better question for me is:
    is CMCON a common "register" in all the PICs that have comparators?

    Thanks for your time.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ChrisHelvey View Post
    How does one come to the conclusion that CMCON = 7?
    Am I correct in saying that the reason it is seven is because there are only the last three bits in the CMCON register that sets this? Looking at the data sheet I see:
    7 6 5 4 3 2 1 0
    19h CMCON0 — COUT — CINV CIS CM2 CM1 CM0
    YEP,
    %00000111 = 7 or I believe $07, I'm not real good with hex.
    Actually, a better question for me is:
    is CMCON a common "register" in all the PICs that have comparators?
    Very likely, but I would never accuse all PICs of being the same about anything. The data sheet is your friend
    JS
    Last edited by Archangel; - 25th July 2007 at 06:19.
    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.

Similar Threads

  1. 12F683 2 x PWM Outputs
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 23rd July 2021, 20:20
  2. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 17:38
  3. New project help rapidfire on 12f683
    By thm ov3rkill in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 27th December 2008, 19:59
  4. 12F683 Programmer
    By Red_Stafford in forum Schematics
    Replies: 9
    Last Post: - 2nd October 2008, 21:44
  5. 12F683 HPWM Usage
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2007, 02:16

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