neazoi
Advanced Member level 6
- Joined
- Jan 5, 2008
- Messages
- 4,157
- Helped
- 13
- Reputation
- 26
- Reaction score
- 15
- Trophy points
- 1,318
- Location
- Greece
- Activity points
- 37,198
; counter variable
CNT EQU 16 ; uS delay. Modify this, to change frequency
Loop
movlw 1 ; Turn on Port A
movwf PORTA ;
movlw CNT
call MDELAY ; CNT uS delay
movlw 0 ; Turn off the LED on Port A
movwf PORTA ;
movlw CNT
call MDELAY ; CNT uS delay
goto Loop
; delay for w uS. Set the w register to the desired delay value
MDELAY:
MOVWF CNT ;LOAD DELAY TIME
COUNT: NOP ;TWO NO OPERATIONS
NOP ;TO OBTAIN THE DELAY
DECFSZ CNT,1 ;DECREMENT THE COUNTER
GOTO COUNT ;GOTO COUNT IF NOT FINNISHED
RETURN
end
hello,
The code in post #6 will give HZ not Khz..
with FOSC=4MHz cycle=1µS
you can not get 135 or 137 Khz..
you need to use a higher frequency like 16Mhz => cycle 0.25µS
F=136Khz => 1000000/136000 => 7.353 µS
you need to spend around
29 cycles of MCU to get 137Khz
or 30 cycles to get 133Khz
or 28 cycles to get 142Khz
Use a quartz of 16Mhz for PIC16F84
or you can use a litle PIC DIP8 as PIC12F1840 ,with internal Fosc 16Mhz ( use LATA instead of PORTA)
i did a test for 1Mhz output with this PIC **broken link removed**
and with PLL FOSC=64MHz !
View attachment 108862
// 133430Hz
_asm {
movlb 2
ICI:
bsf LATA,4,0 // 0,25 0,25
nop // 0,25 0,50
nop // 0,25// 0,75
nop // 0,25// 1,00
nop // 0,25// 1,25
nop // 0,25 1,50
nop // 0,25 1,75
bcf LATA,5,1 // 0,25 0,25
nop // 0,25 2,25
nop // 0,25 2,50
nop // 0,25 2,75
nop // 0,25 3,00
nop // 0,25 3,25
nop // 0,25 3,50
bcf LATA,4,0 // 0,25 0,25
nop //0,25 0,50
nop //0,25 0,75
nop //0,25 1,00
nop //0,25 1,25
nop //0,25 1,50
nop //0,25 1,75
bsf LATA,5,0 // 0,25 0,25
nop //0,25 2,25
nop //0,25 2,50
nop //0,25 2,75
nop //0,25 3,00
nop //0,25 3,25
nop //0,25 3,50
BRA ICI //0,5 4,00
} // fin de zone asm
// boucle indefiniment au dessus !
Quadrature output..
do you means 2 outputs with depahasage 90 between them.
and same frequency!
like this , on pin RA4 and pin RA5?
Code:// 133430Hz _asm { movlb 2 ICI: bsf LATA,4,0 // 0,25 0,25 nop // 0,25 0,50 nop // 0,25// 0,75 nop // 0,25// 1,00 nop // 0,25// 1,25 nop // 0,25 1,50 nop // 0,25 1,75 bcf LATA,5,1 // 0,25 0,25 nop // 0,25 2,25 nop // 0,25 2,50 nop // 0,25 2,75 nop // 0,25 3,00 nop // 0,25 3,25 nop // 0,25 3,50 bcf LATA,4,0 // 0,25 0,25 nop //0,25 0,50 nop //0,25 0,75 nop //0,25 1,00 nop //0,25 1,25 nop //0,25 1,50 nop //0,25 1,75 bsf LATA,5,0 // 0,25 0,25 nop //0,25 2,25 nop //0,25 2,50 nop //0,25 2,75 nop //0,25 3,00 nop //0,25 3,25 nop //0,25 3,50 BRA ICI //0,5 4,00 } // fin de zone asm // boucle indefiniment au dessus !
if not egnouh accurate, you can use PLL .. so 64MHz
cycle=1/16 of µS
just a suggestion
you will never get it exact you will always be an instruction
cycle or more out, use a DSS, it be better and more stable
the PIC clock is not very stable. and it could be any thing
unless you adjust it some how.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?