PDA

View Full Version : Pulsin to pulsout with up than 4MHZ crystal ?



RCtech
- 29th January 2006, 19:46
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.

Dave
- 30th January 2006, 13:01
RCtech , Yes you are correct. The commands resolution depends on the oscillator used. So you must multiply or divide the variable accordingly.

Dave Purola,
N8NTA

Acetronics2
- 30th January 2006, 14:33
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 ...

RCtech
- 31st January 2006, 03:40
Hi, RCTech

.../...The Valinpulse value will be the same for Pulsin and Pulsout.

Okay, i'm not totally wrong ;O)



@ 4Mhz, you write: Valinpulse var BYTE ....and @ 20 Mhz you MUST write : Valinpulse var WORD !!!
Whow, i didn't know that little difference !



.../...
Now, a little Trick seen nowhere :
Always Write : LOW PORTX.Y before a Pulsout statement .../...
Thanx, i'm just a little bit more intelligent than yesterday, many many thanx.
Now it's half past 3 AM : too late for me to do the tests but tomorrow probably, i'll post a feedback.

And.... Nice to see i'm not the only one froggy here !

Dave, i've tested with multiplying etc (just in case), but, today i'm sure it was a mistake because pulsin & pulsout have the same res. depending the X-tal used so if pulsin have a 5 times ratio at 20Mhz, then, the pulsout too and i don't need to do some corrections by calcs.

I'll come back on the forum tomorrow or next day to tell if it's okay.

RCTech

RCtech
- 3rd February 2006, 00:09
Back to confirm everything is okay, this stupid ''BYTEs'' are changed for ''WORDs'' now !

Thanx for your help.

modifyit
- 18th May 2006, 20:23
If you don't mind me asking what is your application for this?