Pulsin to pulsout with up than 4MHZ crystal ?
Hello members.
I'll try to explain my problem in a comprehensive english but don't blame me if my language is not perfect, English is not native for me.
Well, i just wanna do that :
Pulsin a value on a pin and pulsout this value on another pin.
it's okay with a 4Mhz crystal but not with another one :O(
Here is my code :
-=-=-=-=-=-=-=-=-=-=-=-=-=
@ device PIC16F871, HS_osc, wdt_off, pwrt_off, protect_off, bod_on, lvp_off, cpd_off, wrt_off, debug_off
ADCON1 = 7 'Need this to turn off ADC
DEFINE NO_CLRWDT 1 'Do not auto insert watchdog timer
Define OSC 20 'Not important to define in this case but i want
Clear
TRISA = %11111111 'Pins A are in input mode
TRISC = %00000000 'Pins C are in Output mode
PORTC = %00000000 'Clear Port C
Init:
PULSIN PORTA.2,1,ValInPulse 'Measure the pulse who vary from 1ms to 2ms
PULSOUT PORTC.5, ValInPulse 'Output the pulse
GOTO Init 'Do it always
-=-=-=-=-=-=-=-=-=-=-=-=-=
And now, here is is what i don't understand :
I know Pulsin and pulsout depend from the crystal, so, if the pulsin have a 5 times higher resolution with à 20MHZ crystal, it's the same for the pulsout (?) I think i don't have to multiply or divide the pulsin value before i output it via PORTC.5...
May be someone could explain ?
Thanx.
Pulsin and Pulsout Mysteries
Hi, RCTech
Assuming DEFINE OSC doesn't interfere with osc speed for pulsin and pulsout, result won't be the same @ 4Mhz and @ 20 MHz. ratio will be 5 , as you tell.
The Valinpulse value will be the same for Pulsin and Pulsout.
Now, as RC is in your pseudo ... RC pulses values are ~ 80 to 220 @ 4Mhz and 400 to 1100 @ 20 Mhz ... okay, but...
@ 4Mhz, you write: Valinpulse var BYTE ....and @ 20 Mhz you MUST write : Valinpulse var WORD !!!
and I didn't see that in your code ...
Also take care, if you ever use DEFINE PULSIN_MAX to allow for the full signal ( 0 AND 1 state duration = full period )
Now, a little Trick seen nowhere :
Always Write : LOW PORTX.Y before a Pulsout statement ... many ununderstandable bugs come from here !!! ( explanation is in High capacitive loads behaviour of PICs ... and the Pulsout way of work )
Alain
30 years of R/C ...