It is currently 19 May 2012, 18:15





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
 PIC timing 
Author Message
Post PIC timing
Okay, I was curious about the actual speed my controller
is running at, so I ran the following loop on it. If I'm not mistaken,
I've set OSCCON to 8MHz, so at 4 clock/instruction I should see
0.5 uS pulses. My scope on RB4 shows pulses 5uS wide!

I'm out by a factor of 10. What have I not taken into account?


#include <p16F690.inc>
__config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF &
_CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)

Org 0
goto Start
Org 4
goto ISR
ISR
retfie

Start movlw 0x71 ;b'01110001'
BANKSEL OSCCON
movwf OSCCON

; initialize any register that might affect I/O
BANKSEL IOCB
clrf IOCB
clrf WPUB
clrf ANSEL
clrf ANSELH

BANKSEL TRISA
clrf TRISA ; PORTA all output
clrf TRISB ; PORTB all output
clrf TRISC ; PORTC all output

BANKSEL SSPCON
bcf SSPCON, 5

;=== run timing loop ===
BSF PORTB,4
BCF PORTB,4
goto $-2
end


30 Dec 2007, 16:06
Post Re: PIC timing
"randy.day" <randy.day@shaw.cax> wrote in message
news:nTedj.29074$DP1.13331@pd7urf2no...
> Okay, I was curious about the actual speed my controller
> is running at, so I ran the following loop on it. If I'm not mistaken,
> I've set OSCCON to 8MHz, so at 4 clock/instruction I should see
> 0.5 uS pulses. My scope on RB4 shows pulses 5uS wide!
>
> I'm out by a factor of 10. What have I not taken into account?
>
>
> #include <p16F690.inc>
> __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF &
> _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
>
> Org 0
> goto Start
> Org 4
> goto ISR
> ISR
> retfie
>
> Start movlw 0x71 ;b'01110001'
> BANKSEL OSCCON
> movwf OSCCON
>
> ; initialize any register that might affect I/O
> BANKSEL IOCB
> clrf IOCB
> clrf WPUB
> clrf ANSEL
> clrf ANSELH
>
> BANKSEL TRISA
> clrf TRISA ; PORTA all output
> clrf TRISB ; PORTB all output
> clrf TRISC ; PORTC all output
>
> BANKSEL SSPCON
> bcf SSPCON, 5
>
> ;=== run timing loop ===
> BSF PORTB,4
> BCF PORTB,4
> goto $-2
> end
>
>

The "goto $-2" takes two instruction times.
I make it as, (in 0.5uS steps and 0V,5V) ...
5-0-0-0-5-0-0-0-5-0-0-0-5-0-0-0-5 ...
I.e. 2uS repetition (500kHz), at a 1:3 duty cycle with 8MHz clock=2 mips.


30 Dec 2007, 16:06
Post Re: PIC timing
"randy.day" <randy.day@shaw.cax> wrote in message
news:nTedj.29074$DP1.13331@pd7urf2no...
> Okay, I was curious about the actual speed my controller
> is running at, so I ran the following loop on it. If I'm not mistaken,
> I've set OSCCON to 8MHz, so at 4 clock/instruction I should see
> 0.5 uS pulses. My scope on RB4 shows pulses 5uS wide!
>
> I'm out by a factor of 10. What have I not taken into account?
>
>
> #include <p16F690.inc>
> __config (_INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF &
> _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF)
>
> Org 0
> goto Start
> Org 4
> goto ISR
> ISR
> retfie
>
> Start movlw 0x71 ;b'01110001'
> BANKSEL OSCCON
> movwf OSCCON
>
> ; initialize any register that might affect I/O
> BANKSEL IOCB
> clrf IOCB
> clrf WPUB
> clrf ANSEL
> clrf ANSELH
>
> BANKSEL TRISA
> clrf TRISA ; PORTA all output
> clrf TRISB ; PORTB all output
> clrf TRISC ; PORTC all output
>
> BANKSEL SSPCON
> bcf SSPCON, 5
>
> ;=== run timing loop ===
> BSF PORTB,4
> BCF PORTB,4
> goto $-2
> end
>
If you are only measuring the part of the pulse that is high, it appears it
should be 0.5 us. Check if your scope has a X10 horizontal magnification
switch (my old Leader has a knob on the inside of the Variable Possition
control (horizontal position) that is labeled, "PULL X10 MAG". Inadvertantly
activating that control can throw you off.

By the way, goto takes 2 instruction cycles, so you may be getting a 0.5 us
high pulse, followed by a 1 us low pulse.

Richard


30 Dec 2007, 16:06
Post Re: PIC timing
Richard Seriani wrote:

[snip]

> If you are only measuring the part of the pulse that is high, it appears it
> should be 0.5 us. Check if your scope has a X10 horizontal magnification
> switch (my old Leader has a knob on the inside of the Variable Possition
> control (horizontal position) that is labeled, "PULL X10 MAG". Inadvertantly
> activating that control can throw you off.

ROFL! That's EXACTLY what it was! :D

I just got the scope last week as my early xmas present.
I'm going to be giggling over this for the rest of the night...

> By the way, goto takes 2 instruction cycles, so you may be getting a 0.5 us
> high pulse, followed by a 1 us low pulse.

Yep. The on/off ratio was correct, but it was all
*stretched* by a factor of 10, which seemed
suspicious on a base-8 micro, but I *never* would
have spotted that. :)

Cheers mate! You made my day!


30 Dec 2007, 16:06
Post Re: PIC timing
"Randy Day" <randy.day@shaw.cax> wrote in message
news:4775A903.97662200@shaw.cax...
> Richard Seriani wrote:
>
> [snip]
>
>> If you are only measuring the part of the pulse that is high, it appears
>> it
>> should be 0.5 us. Check if your scope has a X10 horizontal magnification
>> switch (my old Leader has a knob on the inside of the Variable Possition
>> control (horizontal position) that is labeled, "PULL X10 MAG".
>> Inadvertantly
>> activating that control can throw you off.
>
> ROFL! That's EXACTLY what it was! :D
>
> I just got the scope last week as my early xmas present.
> I'm going to be giggling over this for the rest of the night...
>
>> By the way, goto takes 2 instruction cycles, so you may be getting a 0.5
>> us
>> high pulse, followed by a 1 us low pulse.
>
> Yep. The on/off ratio was correct, but it was all
> *stretched* by a factor of 10, which seemed
> suspicious on a base-8 micro, but I *never* would
> have spotted that. :)
>
> Cheers mate! You made my day!

Randy,

Glad to be able to help. Thanks for letting me know.

Happy New Year.

Richard


30 Dec 2007, 16:06
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © phpBB Group, phpBB SEO.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.