DIV32 calculation with PBP3 version 3.0.6.0


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    10

    Default DIV32 calculation with PBP3 version 3.0.6.0

    Hallo All Forum participants,

    Forgive me please for battling with the previous messages. At last here is my question.
    I am using a 12F683, Periperal interupt register flag and Timer1, to accumalate OSC ticks (4MHZ/4) in uSec's and then trying to converting the ticks to a new value. The number of uSec ticks is taken in a 1 mSec period. (1000). All my variables are word sized.
    Using the number of ticks, mutiplied with 1000, my calculation with DIV32 does not give the wanted result.
    I then tried the DIV32 sample from the manual.: 500 * 1000 = 500000, DIV32 100 should be 5000.
    With the above values from the manual the result is 65535.
    Is there perhaps some-one that can guide me in the right direction please.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: DIV32 calculation with PBP3 version 3.0.6.0

    works for me , why not post you code
    Warning I'm not a teacher

  3. #3
    Join Date
    Feb 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: DIV32 calculation with PBP3 version 3.0.6.0

    Hi Richard,
    Thanks for replying to my question.

    I use MPLAB IDE version 8.90.
    In my version of MPLAB IDE I could not find reference to PBPW
    Could the problem be related to PBPW ?
    Thanks again

    The code:
    '***********************************************
    '* Name : BALLISTIC SPEED INDICATOR *
    '* Author : Danie Joubert George South Africa *
    '* adaptation from existing program in Forum *
    '* Target : 12F683 with 4Mhz Internal Osc. *
    '***********************************************

    '* ALGORYTHM for measuring pulse width using CCP
    '* 1. Configure CCP to capture on rising edge
    '* 2. Enable ccp capture
    '* 3. Start TIMER1
    '* 4. Reconfigure CCP to capture on falling edge
    '* 5. Read and save timer values
    '* 6. Display timer value on Serial LCD

    ' Pin 1 = Pos 5V with 0.1uF cap to Gnd
    ' Pin 2 GPIO.5 = N/C - output
    ' Pin 3 GPIO.4 = N/C - output
    ' Pin 4 GPIO.3 = 10k resistor MCLR
    ' Pin 5 GPIO.2 = CCP1 Pulse input from Set/Reset NAND
    ' Pin 6 GPIO.1 = Serial out to display
    ' Pin 7 GPIO.0 = N/C - output
    ' Pin 8 = 0/Volt

    include "modedefs.bas" ';;; Include file for comms

    ';;; Configs for PBP3
    #CONFIG
    __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF
    #ENDCONFIG

    GPIO = %00000000 ';;; All inputs low
    CMCON0 = %00000111 ';;;' Value "7" Turn comparators off
    TRISIO = %00000100 ';;; GPIO.2/CCP1 = Input rest output
    OSCCON = %01100000 ';;; 4 M/Hz Osc
    ANSEL = %00000000 ';;; Set all digital

    define OSC 4
    DEFINE CHAR_PACING 10

    capture_int_flag VAR PIR1.5 ';;; Periperal interupt register flag - bit 5 (Input=GPIO.2)
    serial_out_pin var GPIO.0 ';;; Pin 7
    capture VAR WORD ';;; capture value
    pulse_width var word
    calc1 var word

    timer_high var word
    timer_low var word


    INTCON = 0 ';;; Interrupts off

    pause 1500 ';;; Give SERLCD a chance to start up

    SEROUT serial_out_pin,T9600,[$FE,$01] ';;; Set Baud rate and clear Display
    pause 50
    SEROUT serial_out_pin,T9600,[$FE,$80, " BALISTIC "] ';;; Text on first line of display
    pause 50
    SEROUT serial_out_pin,T9600,[$FE,$C0, " CHRONOGRAPH "] ';;; Text on second line of display
    pause 50

    measure:
    CCP1CON = %00000101 ';;; Configure capture mode for rising edge
    T1CON = %00000000 ';;; TIMER1 = OFF, prescale = 1, clock = Fosc/4,
    TMR1H = 0 ';;; Clear high byte of TMR1
    TMR1L = 0 ';;; Clear low byte of TMR1
    capture_int_flag = 0 ';;; Clear capture int flag bit
    calc1 = 0
    pulse_width = 0


    While ! capture_int_flag ';;; Wait here for capture on rising edge
    Wend

    T1CON = %00000001 ';;; TIMER = ON, prescale = 1, clock = Fosc/4

    capture_int_flag = 0 ';;; Clear capture interrupt flag bit
    CCP1CON = %00000100 ';;; Configure capture mode for falling edge

    While ! capture_int_flag ';;; Wait here until capture on falling edge
    Wend

    ' Falling edge detected
    capture.HighByte = CCPR1H
    capture.LowByte = CCPR1L ';;; works fine up to here

    calc1 = 500 * 1000 ';;; My own values just for testing first
    pulse_width = div32 100 ';;; this results is 65535

    SEROUT serial_out_pin,T9600,[$FE,$01] ';; Set Baud rate and clear Display
    pause 50
    SEROUT serial_out_pin,T9600,[$FE,$80, # capture] ';;; Display tick count on first line
    pause 100
    SEROUT serial_out_pin,T9600,[$FE,$C0, # pulse_width] ';;; test calculated pulse width on second line

    GOTO measure

    END

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: DIV32 calculation with PBP3 version 3.0.6.0

    at least one of the values in the calculation must be a var.

    eg
    Code:
     capture=500
     calc1 =  capture * 1000 ';;; My own values just for testing first
     pulse_width = div32 100 ';;; this results is correct
    ps when you post code use the code tags , the forum will mess things up format wise without them
    Warning I'm not a teacher

  5. #5
    Join Date
    Feb 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: DIV32 calculation with PBP3 version 3.0.6.0

    Richard,

    Thanks for reply. I will immediately try your suggestion and will report back.

  6. #6
    Join Date
    Feb 2009
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Re: DIV32 calculation with PBP3 version 3.0.6.0

    Richard, I used variables in the calculation as per your reply. The result now 100%. Thanks again, much appreciared

Similar Threads

  1. PBP3 version history?
    By mtripoli in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th November 2012, 17:33
  2. New PBP version - Gold version - Is it really worth it?
    By financecatalyst in forum General
    Replies: 20
    Last Post: - 8th October 2011, 02:34
  3. DIV32 Questions ...
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th November 2007, 01:49
  4. Div32
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd February 2007, 21:26
  5. DIV32 confusion
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th October 2005, 22:24

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