serial communication time
Hi Guys & Girls!
my serial data transfer between two pics 16F628A works for starters. BUT: in my program theres at high engine speeds only 0.4 ms or less to send the data from one pic to another.
The action my receiving PIC makes is triggered by an external interrupt that means after that theres hardly time to get the data. On the other hand it doesn´t matter if it misses the data for a few cycles because at high engine speeds the data update could wait . I think it is sufficient to transmit that data every 0.1 sec.
Yes: baud rate 9600, 4 Mhz crystal, data: one word. Input Frequency 3 Hz - 600 Hz
Does this work?
on Interrupt goto ISR
main:
serin2 blah blah
isr:
pulsout 7, 50, 1
something like that
I will show the program when i´m back home
AH: one BIG Problem too:
when using a 2-channel oscilloscope it shows a Delay between input signal and output signal
of about 0.5 ms more than expected. this makes the whole action too slow!!!
Maximum accepted delay between input trigger and output pulseout could be 0.1 ms.
is the only way to handle those timecritical events by assembler? please say no....
Mugel
USART please but how to use ?
oha,
1 ms for Data transfer is way too much. And recieving data (no sending!) in the background seems the only thing to do
'************************************************* *******************************************
' 16F628A 10 Mhz crystal 15pf capacitors
' damn program should blink an LED every time a pulse goes into RB.0
' later a value should be serial loaded and set a delay before the blink pulse
'************************************************* *******************************************
'
' DEFINITIONS
DEFINE OSC 10
CMCON=%00000111
inputData var word ' variable to receive data into
pulseWidthVar var word
' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = 1 ' RB0 is Input others output
on interrupt goto ISr
INTCON.1 = 0 ; Clear External Interrupt Flag
INTCON.4 = 1 ; Enable External Interrupt
main:
Portb.7 = 0
serin2 portB.0,16468, [inputData] 'for the future to load a value
pulseWidthVar = inputData
goto main
disable
ISR:
portb.7 = 1 'blink LED 0.02 sec one time when RB.0 goes high
pauseus 500
portb.7 = 0
INTCON.1 = 0 ; Clear External Interrupt Flag
RESUME 'resume main program
Enable 'Enable interrupts
END ' End of program
In my picbasic pro book from Dogan Ibrahim it says " USART is very complicated"
and that did not encourage me.
Because I use only 16F628A , maybe with 10Mhz that should do.
How could I use the Usart . I think those 16F628A have one....
Precise Problem definition
Ok. To make it clear I want This:
http://www.sportdevices.com/ignition/ignition.htm
but want to do that myself AND by using Picbasic Pro (Full version 2.5). I don´t want to write Asm because I´m unable to do so.
Although I know this could be done with 1 simple PIC I´m willing to take 2 of them or 3 if necessary for Picbasic Pros sake.
Those smart Guys that programmed ignitions don´t even give you the ASM code, only Hex.
Further I need this circuit and software etc. modified for different engines . For that I bought the PBP software.
I know You Guys could programm something like I need in 5 minutes or less but I need something in simple structure so I can handle the software and necessary changes.
My actual problem is the fact that my serial pic to pic communication is far to slow AND the com routine seems to delay the interrupt action by about 1ms which is inacceptable.
Hope this made everything clear.
thanks for your interest.
serial communication speed? Parrallel communication !
Hi .
Ok maybe I´m not software-smart enough to get my data sending/recieving problem as fast as needed.
So I try to switch to parallel communication.
I like the instruction:
PortB = VAR (byte)
the only problem is the fact that I need Portb.0 for the external interrupt so I will take the PIC16F873 which has more pins. Still need the ZIF socket for my programming adapter.
I will tell how that works.
To Skimask:
yes you are right about your detonation assumptions.
Know a bit about engines myself : http://www.davidpower.de/fotos_mot.htm
Debug Problem only last Digit changing
Hi Skimask,
I did as You told but now my LCD shows
cnt=252 or cnt=253
thats the only change
Any hint?
Greetings from a desperate mechanical engineer
Works now but waaaaay too slow
Hi Skimask,
I changed my program into this:
'
' DEFINITIONS
Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 4
DEFINE DEBUGIN_REG PORTB
DEFINE DEBUGIN_BIT 1
DEFINE DEBUGIN_MODE 0 '1 = Inverted, 0 = true
DEFINE DEBUGIN_BAUD 2400
Cnt VAR Word ' Cnt is a word variable
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = %11111101 ' RB1 is Input others output
cnt = 0
main:
debugin [cnt]
LCDOUT $FE,2 ' Home cursor
LCDOUT "CNT=", DEC3 Cnt
goto main
goto main
END ' End of program
Now it works but only with this Baud rate of 2400.
BUT I WANT a Baud rate of ONE ZILLION or so.
seems I´m still at the beginning.
Or is it possible to run the data transfer in the background using some asm code ?
Greetings from Mugel
Input Delay and my other new friends
Hi Skimask,
I try to answer with a minimum of translation losses....(Reminds me of principal Skinner, hehe)
1. Input is a 50% Duty cylce with 1/2 frequency of the magnetic/Hall pickup from the distributor because the Duty cycle varies sometimes with the frequency. So I took a 4027 to cut it in Half and got a nice constant 50/50 square signal. Makes 6Hz up to 300Hz. Thats my 1/2 frequency range. Threfore I have to multiply my VAR CNT by 2 to get the real freq, If I want to.Now I can handle this Input(my Variable CNT) mathematically like i want or need.
The easy thing is: we need this Input Variable only changed every 0.1 sec. thats fast enough.When the engine runs with constant speed for example for 1 minute we dont even need to change the Input variable because theres no difference.Thats the task of my first pic including sendig (by DEBUG)this Variable or the calculatet Delay (variable name and task is the same here) to PIC #2.
2. PIC #2 reacts when the RB0 pin shows a change fromlow to high. thats the same Input signal from our Distributor but the original frequency . The signal has to be changed into a square signal by a comparator or Schmitt-trigger.But here we need the precise starting point. After that a delay (Stored in the Var DELAY and calculated before depending on the input VAR CNT ) is startet ("ON Interrupt "or an asminterrupt handler needed here )
to get the right time for the Ignition action. This could be in the simplest way 10° befor OT at low speeds and 40° at high engine speeds (rotations per minute, Input signal fromthe distributor stored in VAR CNT). As you can see, even if you want a constant ignition action say 20° before OT the time of the delay after the delay starting signal (50° before OT = constant) the delay is reciprocal to the engine speed and reciprocal to VAR CNT.
3. Ignition action is a simple Output signal from the pin we choose (here PORTB.7) of 1ms high. This is send to the ignition coil driver wich switches 10Amps and 12Volts.The End of the 1ms is The Ignition timing point.
4.Due to PICs internal and software delays we need a correction factor for the VAR DELAY depending on Engine speed. Once we got this I´m happy. maybe in a list with just 10 points from low engine speeds to high speeds. Cranking is another thing because theres no constant cranking speed so the VAR DELAY has to be calculated for every cranking speed.
From 1000/min up we need only 10 different pre-ignition values, maybe 1000-1500,1500-2000 and so on. BUT: VAR DELAY would be different for a constant ignition timing for 1000/min or 1500/min.
If I can make anything more clear I will do so.
Transmission speed: The calculated VAR DELAY has to be sent from PIC1 to PIC2 (The ignition action PIC) .
BUT I put in a PIC#3 thats just for control purposes to check the VAR DELAY thats sent.
At the time theres no calculation OF The VAR DELAY and I´m sending just the "rough data VAR CNT". Calulation code is implemented after the transmission works.
Now: How will I send a WORD Variable fromPIC to PIC at Engine speeds of 8000/min? just 0.2 ms left. Or its done in the background with the famous USART registers which I try to use with DEBUG .......