View Full Version : pulse simulation
nicolasronan
- 13th August 2006, 14:04
hello
i want simulate a cycle rpm sensor for automotive.
http://www.geea.org/IMG/swf/capteur_vitesse_6.swf
the frequency must be able.
i ve test this code (!!! it s not the same cycle of the picture)
' _!-!_!-!__!--!_!-!_!-!
' pic16F877
' Variable
W0 var word
W1 var word
i var byte
up var PORTB.4
dn var PORTB.5
w0=0
i=0
'DN Define frequency down button
'UP Define frequency up button
PO con 3 ' Define pulse output pin
low PO ' Initialize output polarity
inc:
If (up = 1) Or (W0 = 10000) Then decr ' Increment freq on button
W0 = W0 + 10
decr:
If (dn = 1) Or (W0 = 0)Then pulse ' Decrement freq on button
W0 = W0 - 10
pulse:
for i =1 to 38
Pulsout 3,W0 ' Generate pulse
Pause W0/100 ' Intra-pulse delay
next i
Pulsout 3,W0
W1=W0*2
Pause W1/100
Pulsout 3,W1
Goto inc ' Forever
this code is ok but not optimized with button
how do? use pulsout or pwm?
thank
Acetronics2
- 13th August 2006, 14:52
Hi, Nicolas
Use DT interrupts !!! ... it's not so difficult to use.
http://www.picbasic.co.uk/forum/showthread.php?t=3251
or a little trick I discovered :
insert " DEFINE INTHAND _INC" at the top of the program ... This places a "GOTO _INC" at location 00004 of the ASM program.
Now trim the interrupt register ( INTCON) to allow an " interrupt on PortB Change "
Place a correct preset value for W0 ... 0 is not a good value !!! ( in "decr:" nor !!! )
Place a "GOTO PULSE " before "inc"
Think to re-enable interrupts, placing " INTCON.7 = 1" just past "pulse" label
last, change "GOTO inc" to "GOTO pulse"
That should go at first...
Next step will be to use BUTTON instead of IF-THEN ... just to use the Auto-repeat feature ...
One more step ...
Have a look to Motorola ( yessss ... Freescale !!! ) "TPUPN xx" Application Notes ...
really Great !!!
http://www.bgsoflex.com/megasquirt.html
Alain
nicolasronan
- 13th August 2006, 15:53
how place a "GOTO _INC" in microcode studio.
interrupt register ( INTCON) to allow an " interrupt on PortB : INTCON=00001000 , it s ok?
thank
nicolasronan
- 13th August 2006, 16:01
if i use
ASM
GOTO_INC
ENDASM
it 's ok?
Acetronics2
- 13th August 2006, 16:22
and how to place it in location 4 ????
D.E.F.I.N.E. !!!!!
Alain
nicolasronan
- 13th August 2006, 21:01
sorry bur i dont understand how use interrupt on a port.
i m bad
nicolasronan
- 13th August 2006, 21:42
I work but it is hard
this code work
' pic16F877
'cycle = !-!_!-!_!-!_!-!_!-!__!--!_
' i use lcd just to see W0
' Define LCD registers and bits
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 8
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE OSC 4 ' use 20 MHZ oscillator
INCLUDE "modedefs.bas" ' Include serial modes
W0 var word
W1 var word
i var byte
up var PORTB.4
dn var PORTB.5
rst var portb.6
b0 var byte
PO var portb.3 ' Define pulse output pin
'initialisation
ADCON1 = %0000111
TRISA = %1
w0=100
i=0
B0=0
Low PO ' Initialize output polarity
intcon=%0001000
On Interrupt Goto bouton ' Define interrupt handler
INTCON = $90 ' Enable INTE interrupt
'*********************
pulse:
for i =1 to 5
Pulsout 3,W0 ' Generate pulse
pause W0/100 ' Intra-pulse delay
next i
Pulsout 3,W0
W1=W0*2
Pause W1/100
Pulsout 3,W1
'visualisation sur LCD
Lcdout $FE,$C0,"W0 = ",dec W0," "
Goto bouton
'*********************
inc:
W0 = W0 + 10
goto pulse
'*********************
decr:
W0 = W0 - 10
goto pulse
'*********************
reset:
w0 = 100
goto pulse
'*********************
bouton :
disable
button up,1,0,0,b0,1,inc 'si bouton1 sur port1=1 aller à calibration
button dn,1,0,0,b0,1,decr 'si bouton1 sur port1=1 aller à calibration
button rst,1,0,0,b0,1,reset 'si bouton1 sur port1=1 aller à calibration
enable
goto pulse
but why on the piture the period after double pulse the low period its not equal w0?
nicolasronan
- 14th August 2006, 09:11
help please
Acetronics2
- 14th August 2006, 12:57
PAUSE Missing after PULSOUT 3, W1
Goto Pulse instead of Goto Bouton ---- mais à quoi servent donc les interruptions ???
et on termine en plaçant la visualisation dans le programme d'interruption juste AVANT le Enable !!! ( ça évite les affichages Ollé, Ollé ...)
Alain
nicolasronan
- 14th August 2006, 13:23
to simplify :no button
' pic16F877
'cycle = !-!_!-!_!-!_!-!_!-!__!--!_
' i use lcd just to see W0
' Define LCD registers and bits
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 8
DEFINE LCD_RSREG PORTE
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTE
DEFINE LCD_EBIT 1
DEFINE OSC 4
INCLUDE "modedefs.bas" ' Include serial modes
W0 var word
W1 var word
i var byte
up var PORTB.4
dn var PORTB.5
rst var portb.6
b0 var byte
PO var portb.3 ' Define pulse output pin
'initialisation
ADCON1 = %0000111
TRISA = %1
w0=1000
i=0
B0=0
Low PO ' Initialize output polarity
'*********************
pulse:
for i =0 to 5
Pulsout 3,W0 ' Generate pulse
pause W0/100 ' Intra-pulse delay
next i
I=0
Pulsout 3,W0
W1=W0*2
Pause W1/100
Pulsout 3,W1 'double pulse ok
pause W0/100
'visualisation sur LCD
Lcdout $FE,$C0,"W0 = ",dec W0," "
Goto PULSE 'repeat cycle
I want a double pulse in end cycle but before new cycle , i want simple pediod low but it not equal w0!!!
nicolasronan
- 14th August 2006, 13:29
I remove lcd and it s ok
nicolasronan
- 14th August 2006, 13:59
now, the interruption does not work.
they are detected but not the button pressed and w0 pass to 0
' pic16F877
'cycle = !-!_!-!_!-!_!-!_!-!__!--!_
' i use lcd just to see W0
DEFINE OSC 4
INCLUDE "modedefs.bas" ' Include serial modes
W0 var word
W1 var word
i var byte
up var PORTB.4
dn var PORTB.5
rst var portb.6
b0 var byte
PO var portb.3 ' Define pulse output pin
OPTION_REG = $7f
'initialisation
ADCON1 = %0000111
TRISA = %1
w0=100
i=0
B0=0
Low PO ' Initialize output polarity
INTCON.0 = 0 'Clear Port Change Interrupt Flag bit
On interrupt goto bouton ' Define interrupt handler
INTCON =%10001000 'Enable RBIE
'*********************
pulse:
for i =0 to 5
Pulsout 3,W0 ' Generate pulse
pause W0/100 ' Intra-pulse delay
next i
Pulsout 3,W0
W1=W0*2
Pause W1/100
Pulsout 3,W1
pause W0/100
Goto pulse
'*********************
inc:
'Lcdout $FE,$C0,"INC"
W0 = W0 + 1
W1=W0
resume
goto pulse
'*********************
decr:
W0 = W0 - 1
W1=W0
goto pulse
'*********************
reset:
w0 = 100
W1=W0
goto pulse
'*********************
DISABLE
bouton :
INTCON.0 = 0 '
if PORTB.4=0 THEN goto inc 'not detect
if PORTB.5=0 THEN goto decr 'not detect
if PORTB.6=0 THEN goto reset 'not detect
GOTO PULSE
ENABLE
Acetronics2
- 14th August 2006, 17:55
do not mix resume and goto's ...
a clear algorithm could help you.
Alain
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.