PDA

View Full Version : DIV32 calculation with PBP3 version 3.0.6.0



daan.joubert
- 1st January 2017, 13:33
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.

richard
- 1st January 2017, 13:50
works for me , why not post you code

daan.joubert
- 1st January 2017, 19:46
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

richard
- 1st January 2017, 21:41
at least one of the values in the calculation must be a var.

eg


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

daan.joubert
- 1st January 2017, 21:54
Richard,

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

daan.joubert
- 3rd January 2017, 08:08
Richard, I used variables in the calculation as per your reply. The result now 100%. Thanks again, much appreciared