PDA

View Full Version : Timing on the 12F675



abbtech
- 23rd April 2010, 03:29
I am using PicBasic Pro with the 12F675. I am using the internal 4MHz oscillator and seem to be having some issues.

I will need to create 30KHz, 33KHz, 36KHz, 38KHz, 40KHz and 56KHz. 38KHz is the most important and the one that I am working with first. I would like to make a 13uS on and 13uS off square wave.

If I run just a tight loop turning the output on and off the output is about 4.4uS on and 4.4uS off. Does this sound correct?

I tried to use pauseus 13 thinking that I would get a 13uS pause but it created about a 25uS pause. pauseus 1 still causes a 25uS pause. Is there that much overhead in turning the pin high and low.

Here is what I am trying.

freq38K:
HIGH IrLed
PAUSEUS 13
LOW IrLed
PAUSEUS 13
GOTO freq38k

mackrackit
- 23rd April 2010, 03:43
You might try


GPIO = %xxxxxxxx

Make the x's 0 or 1. 1 being high.

Kamikaze47
- 23rd April 2010, 06:22
If the frequency needs to be accurate you would be much better off using a timer interrupt.

Acetronics2
- 23rd April 2010, 07:24
Hi,

as the Holy Manual states ...

min PAUSEUS @ 4 Mhz is ... 19µs ...

soooo .... toobad !

Now, for this " universal IR Tx " ...the use of a Xtal looks compulsory !

Alain

PS: an assembler stubb would be useful here ...



;-------------------------------------------------------------
; Code generated by PDEL ver 1.0 on 23/04/2010 at 09:01:45
; Description: Waits 13 cycles
;-------------------------------------------------------------
PDelay movlw .2 ; 1 set number of repetitions
movwf PDel0 ; 1 |
PLoop0 clrwdt ; 1 clear watchdog
decfsz PDel0, 1 ; 1 + (1) is the time over?
goto PLoop0 ; 2 no, loop
return ; 2+2 Done
;-------------------------------------------------------------



Code requirements
-----------------
- Declaration of PDel0 (register)
- 1 stack level

Example of use
--------------
call PDelay ; Delay 13 cycles (including call+return)

sayzer
- 23rd April 2010, 08:00
http://www.rentron.com/Infrared_Communication.htm



PROCESSOR 12c508
#include "p12c508.inc"
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC
#DEFINE PORT B'11111101'
MOVF OSCCAL
MOVLW PORT
TRIS GPIO

BEGIN
BCF GPIO, 1 ;1uS
NOP ;2uS each nop is 1uS long
NOP ;3uS
NOP ;4uS
NOP ;5uS
NOP ;6uS
NOP ;7uS
NOP ;8uS
NOP ;9uS
NOP ;10uS
NOP ;11uS
NOP ;12uS
NOP ;13uS
NOP ;14uS
NOP ;15uS
NOP ;16uS
NOP ;17uS
NOP ;18uS
NOP ;19uS
BSF GPIO, 1 ;1uS Begin HIGH duty cycle
NOP ;2uS
NOP ;3uS
NOP ;4uS
NOP ;5uS
GOTO BEGIN ;2uS (26uS total for 38KHz)
END

Bruce
- 23rd April 2010, 17:14
Something like this is easier with PBP.

This is in an include file;


' IR carrier generator routines. Freq.inc.

Cycles VAR BYTE ' Number of carrier cycles

GOTO OverFreq ' jump over pulse routines

' Generate "Cycles" number of 40kHz pulses
ASM
_Pulse40
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
decfsz _Cycles,f ; + 1uS = 10S
goto _Pulse40 ; + 2uS = 12uS
return ; Return to caller
ENDASM

' Generate "Cycles" number of ~38.4kHz pulses
ASM
_Pulse38
bcf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
goto $+1 ; + 2uS = 11uS
goto $+1 ; + 2uS = 13uS
bsf IRTX,PIN ; 1uS, LED=on
goto $+1 ; + 2uS = 3uS
goto $+1 ; + 2uS = 5uS
goto $+1 ; + 2uS = 7uS
goto $+1 ; + 2uS = 9uS
nop ; + 1uS = 10uS
decfsz _Cycles,f ; + 1uS = 11S
goto _Pulse38 ; + 2uS = 13uS
return ; Return to caller
ENDASM

OverFreq:
Create one for whatever IR carrier freq you need, and just call them like this with PBP;


@ #define IRTX GPIO ; Define port to use for IR out
@ #define PIN 2 ; Define port pin to use for IR out

INCLUDE "Freq.inc" '

GPIO.2 = 1 ' IR LED off -----|<|----/\/\/\----+5
TRISIO.2 = 0 ' Output for IR signal
CMCON = 7 ' Comparators disabled
ANSEL = 0 ' A/D disabled

Main:
Cycles = 60 ' min 1, max 255
CALL Pulse38
GOTO Main

END
At 4MHz you won't be spot-on for every carrier frequency, but it will be close enough to work with pretty much any off-the-shelf IR receiver.

Mike, K8LH
- 23rd April 2010, 18:06
Have you considered using an 8-pin 12F683 and generating a 38-KHz PWM signal output in the background? Use a interval counter and turn the PWM output on or off at the correct intervals by setting the CCPR1L duty cycle register to 50% or 0%.

Regards, Mike

abbtech
- 26th April 2010, 23:34
Thanks for all the help and suggestions.

Bruce, I tried your suggestion and it works great!

Regards,

Alan Parekh

(http://hackedgadgets.com)