PDA

View Full Version : Troubled with Instant Ints and TMR2



Josuetas
- 3rd October 2007, 22:18
Hello....
I have been looking at this code all the day and cant find my mistake

i am using a 420Hz frequency as input to the Comparator in 16f628, the signal is correctly biased to 2.5v and Vref is set to Vcc/2.

So now... i am trying to sample this signal into a Bits array and then sending through serial port.



<font color="#000080"><i>;----[ Change these to match your LCD ]---------------------------------------
</i></font>LCD_DB4 <b>VAR </b>PORTA.6
LCD_DB5 <b>VAR </b>PORTB.6
LCD_DB6 <b>VAR </b>PORTB.5
LCD_DB7 <b>VAR </b>PORTB.4
LCD_RS <b>VAR </b>PORTA.0
LCD_E <b>VAR </b>PORTA.7
LCD_Lines <b>CON </b>2 <font color="#000080"><i>' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
</i></font>LCD_DATAUS <b>CON </b>50 <font color="#000080"><i>' Data delay time in us
</i></font>LCD_COMMANDUS <b>CON </b>2000 <font color="#000080"><i>' Command delay time in us


</i></font><b>INCLUDE </b><font color="#FF0000">&quot;LCD_AnyPin.pbp&quot; </font><font color="#000080"><i>; *** Include MUST be AFTER LCD Pin assignments ****
</i></font><b>INCLUDE </b><font color="#FF0000">&quot;DT_INTS-14628.bas&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;ReEnterPBP.bas&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;modedefs.bas&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;Elapsed_INT628b2.bas&quot;

</font><b>DEFINE </b>OSC 4
<b>DEFINE </b>HSER_RCSTA 90h <font color="#000080"><i>' Set transmit register to transmitter enabled
</i></font><b>DEFINE </b>HSER_TXSTA 24h <font color="#000080"><i>' Set baud rate
</i></font><b>DEFINE </b>HSER_BAUD 9600
<b>DEFINE </b>HSER_CLROERR 1

PinActivar <b>VAR </b>portb.0
PinDescuelgue <b>VAR </b>porta.5
PinPolaridad <b>VAR </b>porta.4
InZCD <b>VAR </b>porta.2
PinDTMF <b>VAR </b>portb.7
PinOffHook <b>VAR </b>portb.3
TMR2_clock <b>VAR WORD
</b>FlagSample <b>VAR BIT
</b>NumSamples <b>VAR BYTE
</b>Samples <b>VAR BIT </b>[124]
x <b>VAR BYTE

ASM
</b><font color="#008000">INT_LIST macro </font><font color="#000080"><i>; IntSource, Label, Type, ResetFlag?
</i></font><font color="#008000">INT_Handler TMR2_INT, _Sample, PBP, yes
endm
INT_CREATE </font><font color="#000080"><i>; Creates the interrupt processor
</i></font><b>ENDASM
</b><font color="#008000">@ INT_ENABLE TMR2_INT </font><font color="#000080"><i>; Enable Timer 1 Interrupts

;----[ Your Main program starts here ]----------------------------------------
</i></font>LoopCount <b>VAR WORD

</b>Config:
trisb.0=0
trisa.5=1
trisa.4=1
trisa.2=1
trisb.7=0
trisb.3=0
CMCON = 5
VRCON = %11101100
OPTION_REG = %00000000
T2CON = %00000000 <font color="#000080"><i>' TMR2 prescale 1:1
</i></font><b>PAUSE </b>500 : <b>LCDOUT </b>$FE,1 : <b>PAUSE </b>250
PR2 = 125 <font color="#000080"><i>' load tmr2 PR2 to reset every 1ms

</i></font>MAIN:
<b>HIGH </b>PINACTIVAR
<b>GOSUB </b>GETSAMPLE
<b>PAUSE </b>1000
<b>GOTO </b>MAIN

GetSample:
T2CON.2 = 1
NumSamples = 0
FlagSample = 0
<b>WHILE </b>FlagSample = 0
<b>WEND
HSEROUT </b>[<font color="#FF0000">&quot;:&quot;</font>,10,13]
<b>FOR </b>x = 0 <b>TO </b>119
<b>HSEROUT </b>[<b>DEC </b>Samples [x],10,13]
<b>NEXT </b>x
<b>RETURN

</b>Sample:
Samples [NumSamples] = CMCON.7
NumSamples = NumSamples + 1
<b>IF </b>NumSamples = 120 <b>THEN
</b>FlagSample = 1
T2CON.2 = 0
<b>ENDIF
</b><font color="#008000">@ INT_RETURN

</font></code></pre><!--EndFragment--></body>



My problem is that the frequency sample doesnt match, it seems like the interrupt period is not consecuent with my need..


I am using PR= 125, and with internal clock 4Mhz this should interrupt 0.000125s or 8000Hz.

This doesnt seemd to be the case. Please any advice on how to interrupt with this TMR2 each 125uS.

How can i confirm that my program is interrupting every 0.000125 Seconds?, maybe i am wrong somewhere else.

Thanks for any help

Archangel
- 3rd October 2007, 22:45
INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****
INCLUDE "DT_INTS-14628.bas" ' * * * * * this one * * * *
INCLUDE "ReEnterPBP.bas"
INCLUDE "modedefs.bas"
INCLUDE "Elapsed_INT628b2.bas" ' * * * * and this one * * * *

Are the files marked ' * * * * this one * * * * altered from Darrels originals ?

INCLUDE "DT_INTS-14.bas" ' Base Interrupt System

INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

Or did I miss one of Darrel's Masterpiece releases ?

mister_e
- 3rd October 2007, 23:13
is it me or you should use TMR2 instead of PR2?

Try TMR2=TMR2+138 (or something around it) and toggle a led to know what happen

i'm a bit rusty here... and i can't test it... damn!

mister_e
- 3rd October 2007, 23:27
Joe,
no you didn't miss something, probably because Josuetas got a error message about a wsave beyond ram end or something like that.

So my guess is that he comment out the offending line in those files and use a specific name for it.

Josuetas
- 3rd October 2007, 23:32
Joe S.

Modifications...
i have a DT for 628A since it needs bank modification from 877A.
In the second one i am modifing Elapsed to interrupt every 125us it is not meant for timing but for interrupting. All i did was modifing the timerconst to be $FFA7 in the case of 4Mhz Osc. I am not using this anyway you can see the TMR1 interrupt is not defined for elapsed interrupt, only TMR2.



mister_e

If i get this right, and from the datasheet the timer2 interrupts when Tmr2 reaches PR2 value, tmr2 "should" go to 0 after this, BUT it seemed not TO i had to turn TMR2= 0 in the interrupt routine, Otherwise i was getting weird interruptions (watched it on my osciloscope)




Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows ;)

mister_e
- 3rd October 2007, 23:35
oups... missed the Elapsed timer... i'll read the according posts/thread about it as i never used it.

Sorry :(

Josuetas
- 4th October 2007, 00:00
Ok i figured out a way to measure my interrupts.

The interrupt routine simply Toggles a pin of the micro on each interrupt and i measure such pin with my oscilloscope. The frequency of sampling is wrong.

Problems:

1. The TMR2 doesnt just go back to 0 after reaching PR2 value.. i had to set it to 0 otherwise i get unwanted interrupts.

2. I cant believe this to be impossible so i made a small RX int.... when i press "1" PR increases by one.. else it goes down one, so i can sweep controlling by my keyboard. RESULT: No No it doesnt work.... i never get to my 125us interrupt it suddenly jumps back to the lower frequency after a point.

Is 125us to much to ask for 4Mhz.. teorically i would say No.. 125 instructions are a lot of instructions... and i am only sampling at this point of my software so: what could be the problem?

I cant use other OSC since i am using internal OSC and A7 pin for other purpouses... Since i am only sampling would something like pauseuS 125 : sample work?... What should be the timing consideration in this case?

i still need someting like:



Sample:
pauseus 125
Samples [NumSamples] = CMCON.7
NumSamples = NumSamples + 1
IF NumSamples = 120 THEN return
goto Sample


How many instructions take this sub to work? i guess i have to take them into account for my timing to be correct!!!

Thanks on any help.. Interrupt 125uS 4Mhz still in need!!

mister_e
- 4th October 2007, 02:11
mmm, can you (or someone else) try the following for me? Try both with a 4 MHz and then with a 20MHz crystal. You just need to change the DEFINE OSC and the code will automatically change for you (config fuses, Prescaller and PR2). Sit a scope on PinActivar (PORTB.0) and measure the frequency. It has to be close of 4KHz

Code 1 with ON INTERRUPT


DEFINE OSC 4 ' select 4 or 20
PinActivar VAR portb.0

LoopCount VAR WORD
TMR2IF VAR PIR1.1

TRISB = 0
portb = 0
INTCON = %11000000
PIE1 = %00000010
PIR1 = %00000000
OPTION_REG = %00000000
PinActivar = 0

@ IF (OSC==20)
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
pr2 = 155
T2CON = %00000101 ' TMR2 Prescale 1:4
@ ELSE
@ __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
PR2 = 118
T2CON = %00000100 ' TMR2 prescale 1:1
@ ENDIF

ON INTERRUPT GOTO Sample

MAIN:
GOTO MAIN

disable
Sample:
TOGGLE PinActivar
tmr2if=0
resume
enable

Code 2, with DT-INT


DEFINE OSC 4 ' select 4 or 20

INCLUDE "c:\pbp_prog\Include_routines\DT_INTS-14.bas"
INCLUDE "c:\pbp_prog\Include_routines\ReEnterPBP.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR2_INT, _Sample, PBP, YES
endm
INT_CREATE
ENDASM
PinActivar VAR portb.0

TRISB = 0
portb = 0
OPTION_REG = %00000000

@ IF (OSC==20)
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
pr2 = 155 ' load tmr2 PR2 to reset every 125 uSec
T2CON = %00000101 ' TMR2 Prescale 1:4
@ ELSE
@ __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
PR2 = 118
T2CON = %00000100 ' TMR2 prescale 1:1
@ ENDIF

@ INT_ENABLE TMR2_INT
MAIN:
GOTO MAIN


Sample:
toggle pinactivar
@ INT_RETURN

i'm curious to knwo if there's any significant difference between the above, and how much. I feel them equal @20MHz, but some doubt on 4MHz.

Obviously this code don't do anything interesting... i'm just curious...

As i said, i can't check anything it here.

Darrel Taylor
- 4th October 2007, 07:31
Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows ;)

This page might explain it.
http://darreltaylor.com/DT_INTS-14/kudos.html
Especially the last paragraph.
<br>

Josuetas
- 4th October 2007, 15:29
So Darrel if i made this with just an ASM interrupt i would be able to get my 125uS since i wouldnt need the Reenter Context Saving...


BUT please o please can you help me?..

I use to get to this point where: i dont know any assembler!!!
even worst
A bit Array of 120 samples in Assembler .... mmm..... mmmmm....

By the way would you consider (in my case) the pauseus 125 Take Sample option?

Please some lead to solve this matter.

Thanks again

DJC

Josuetas
- 4th October 2007, 15:36
Code 1 with ON INTERRUPT


DEFINE OSC 4 ' select 4 or 20
PinActivar VAR portb.0

LoopCount VAR WORD
TMR2IF VAR PIR1.1

TRISB = 0
portb = 0
INTCON = %11000000
PIE1 = %00000010
PIR1 = %00000000
OPTION_REG = %00000000
PinActivar = 0

@ IF (OSC==20)
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
pr2 = 155
T2CON = %00000101 ' TMR2 Prescale 1:4
@ ELSE
@ __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
PR2 = 118
T2CON = %00000100 ' TMR2 prescale 1:1
@ ENDIF

ON INTERRUPT GOTO Sample

MAIN:
GOTO MAIN

disable
Sample:
TOGGLE PinActivar
tmr2if=0
resume
enable


Mister_E i am going to test with the ON INTERRUPT way because it might work better here, i am not doing much code between Samples so this could work fine. Thanks for the idea...

The DT option as you can read at Darrels link will not work either.

Darrel Taylor
- 4th October 2007, 17:01
>> So Darrel if i made this with just an ASM interrupt i would be able to get my 125uS since i wouldnt need the Reenter Context Saving...
Correct.

>> A bit Array of 120 samples in Assembler .... mmm..... mmmmm....
In ASM, you would just shift the bits into a byte var. After 8 bit's move to the next byte. After 15 bytes you're done.

>> By the way would you consider (in my case) the pauseus 125 Take Sample option?

YES!
Your program just sits in a loop anyways, waiting for the sample to finish.
No need to use interrupts, if it's not doing anything in the first place.

Or, you can still use the timer. Just poll the TMR2IF Flag.
<br>

Josuetas
- 4th October 2007, 17:45
I will keep working on the interrupt option... This is supposed to detect DTMF (we talk about it before) so for it to work in the background of anything else is the best choice.

Everything is so complicated in ASM!.. thanks god there is picbasic.

Darrel Taylor
- 4th October 2007, 20:21
Here's a quick untested stab at an ASM handler.

Change the Handler type to ASM

Samples VAR BYTE[15] BANK0 SYSTEM
SamplePTR VAR BYTE BANK0 SYSTEM
SamplesAddr CON EXT
@SamplesAddr = Samples
BitCount VAR BYTE BANK0 SYSTEM
ByteCount VAR BYTE BANK0 SYSTEM
FlagSample VAR BIT
TMR2ON VAR T2CON.2

;----[Start getting the 120 samples]------------------------------------------
GetSamples:
FlagSample = 0
SamplePTR = SamplesAddr
ByteCount = 15
BitCount = 8
PR2 = 125 : TMR2 = 0 : TMR2ON = 1
return

;----[TMR2 Handler]-----------------------------------------------------------
ASM
Sample
MOVE?BB SamplePTR, FSR ; Load FSR with pointer to array
MOVE?TT CMCON,7, STATUS,C ; Put sample in carry flag
rrf INDF, F ; Shift in the sample bit
decfsz BitCount, F ; Are all 8 bits in ?
goto Int_Done ; NO, done for now
MOVE?CB 8, BitCount ; Yes, reset bitcount
incf SamplePTR, F ; Point to next byte
decfsz ByteCount, F ; Are all 15 bytes done ?
goto Int_Done ; NO, done for now
MOVE?CT 1, _FlagSample ; Yes, Indicate - Samples Complete
MOVE?CT 0, _TMR2ON ; stop the timer
Int_Done
INT_RETURN
ENDASM

Josuetas
- 5th October 2007, 15:28
Your wish to help is INFITE and appreciated Darrel.

Thanks Again

Darrel Taylor
- 5th October 2007, 18:57
Ha!

You are using ....

LCD_AnyPin
Instant Interrupts
Elapsed Timer

and you showed your "Colors" when posting.

How could I possibly Not Help?? :)
<br>

Josuetas
- 5th October 2007, 20:56
Hey!!!!

Wait a second... your right!!

Soon i´ll end up looking like a mouse with a red Book in my hands!! :D

Josuetas
- 6th October 2007, 00:03
Hi Darrel

I made some tests on the ASM handler for my TMR2 interrupt, it works ALMOST fine.

Before posting i double checked this.

First The timer is interrupting correctly every 0.000125uS and taking the samples, how did i checked this? well first i used HSEROUT to my serial port of the whole sample and i got something. At the Same time i needed to check the timing, so i modified the handler to add a toggle of a pin in the uC after each Sample, then i measured it with the oscilloscope and got the correct frequency.




<html>
<head></head>
<body><!--StartFragment--><pre><code><font color="#000000"><b>CLEAR

DEFINE OSC </b>4
<b>DEFINE HSER_RCSTA </b>90<b>h </b><font color="#000080"><i>' Set transmit register to transmitter enabled
</i></font><b>DEFINE HSER_TXSTA </b>24<b>h </b><font color="#000080"><i>' Set baud rate
</i></font><b>DEFINE HSER_BAUD </b>9600
<b>DEFINE HSER_CLROERR </b>1


<b>LCD_DB4 VAR PORTA</b>.6 <font color="#000080"><i>;************LCD_AnyPin declarations
</i></font><b>LCD_DB5 VAR PORTB</b>.6
<b>LCD_DB6 VAR PORTB</b>.5
<b>LCD_DB7 VAR PORTB</b>.4
<b>LCD_RS VAR PORTA</b>.0
<b>LCD_E VAR PORTA</b>.7
<b>LCD_Lines CON </b>2
<b>LCD_DATAUS CON </b>50
<b>LCD_COMMANDUS CON </b>2000


<b>INCLUDE </b><font color="#FF0000">&quot;LCD_AnyPin.pbp&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;DT_INTS-14628.bas&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;ReEnterPBP.bas&quot;
</font><b>INCLUDE </b><font color="#FF0000">&quot;Elapsed_INT.bas&quot;


</font><b>PinActivar VAR porta</b>.3
<b>PinDescuelgue VAR porta</b>.5
<b>PinPolaridad VAR porta</b>.4
<b>InZCD VAR porta</b>.2
<b>PinDTMF VAR portb</b>.7
<b>PinOffHook VAR portb</b>.0


<b>Samples VAR BYTE</b>[15] <b>BANK0 SYSTEM
SamplePTR VAR BYTE BANK0 SYSTEM
SamplesAddr CON EXT
</b><font color="#008000">@SamplesAddr = Samples
</font><b>BitCount VAR BYTE BANK0 SYSTEM
ByteCount VAR BYTE BANK0 SYSTEM
FlagSample VAR BIT
TMR2ON VAR T2CON</b>.2



<b>NumSamples VAR BYTE
ComIn VAR BYTE

x VAR BYTE </b><font color="#000080"><i>'Counter Byte

</i></font><b>ASM
</b><font color="#008000">INT_LIST macro </font><font color="#000080"><i>; IntSource, Label, Type, ResetFlag?
;INT_Handler RX_INT, _Hablar, PBP, yes
</i></font><font color="#008000">INT_Handler TMR2_INT, Sample, ASM, yes
</font><font color="#000080"><i>;INT_Handler TMR1_INT, _ClockCount, PBP, yes
</i></font><font color="#008000">endm
INT_CREATE </font><font color="#000080"><i>; Creates the interrupt processor
</i></font><b>ENDASM
</b><font color="#000080"><i>;@ INT_ENABLE RX_INT ; Enable Timer 1 Interrupts
;@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
</i></font><font color="#008000">@ INT_ENABLE TMR2_INT </font><font color="#000080"><i>; Enable Timer 1 Interrupts

</i></font><b>Config</b>:
<b>trisb</b>.0=0
<b>trisa</b>.5=1
<b>trisa</b>.4=1
<b>trisa</b>.2=1
<b>trisb</b>.7=0
<b>trisb</b>.3=0
<b>trisa</b>.3=0
<b>CMCON </b>= 5
<b>CMCON</b>.5 = 1 <font color="#000080"><i>'INVERTIDO
</i></font><b>VRCON </b>= %11101100
<b>OPTION_REG </b>= %00000000
<b>PAUSE </b>500 : <b>LCDOUT </b>$FE,1 : <b>PAUSE </b>250
<b>HSEROUT </b>[<font color="#FF0000">&quot;7&quot;</font>]
<font color="#000080"><i>'gosub ResetTime
'gosub StartTimer
;@ INT_DISABLE TMR1_INT ; Enable Timer 1 Interrupts
;@ INT_DISABLE RX_INT ; Enable Timer 1 Interrupts
'HPWM 1,127,420
</i></font><b>LOW PinDTMF
HIGH PinOffHook
main1</b>:
<b>GOSUB GetSamples
WHILE FlagSample </b>= 0
<b>WEND
GOTO main1


MAIN</b>:
<b>HIGH PinActivar
GOSUB GetSamples
WHILE FlagSample </b>= 0
<b>WEND
HSEROUT </b>[<font color="#FF0000">&quot;:&quot;</font>,10,13]
<b>FOR x </b>= 0 <b>TO </b>14
<b>HSEROUT </b>[<b>BIN8 Samples</b>[<b>x</b>],10,13]
<b>NEXT x
PAUSE </b>5000
<b>GOTO MAIN


</b><font color="#000080"><i>;----[Start getting the 120 samples]------------------------------------------
</i></font><b>GetSamples</b>:
<b>FlagSample </b>= 0
<b>SamplePTR </b>= <b>SamplesAddr
ByteCount </b>= 15
<b>BitCount </b>= 8
<b>PR2 </b>= 125 : <b>TMR2 </b>= 0 : <b>TMR2ON </b>= 1
<b>RETURN

</b><font color="#000080"><i>;----[TMR2 Handler]-----------------------------------------------------------
'ASM
'Sample
' MOVE?BB SamplePTR, FSR ; Load FSR with pointer to array
' MOVE?TT CMCON,7, STATUS,C ; Put sample in carry flag
' rrf INDF, F ; Shift in the sample bit
' decfsz BitCount, F ; Are all 8 bits in ?
' goto Int_Done ; NO, done for now
' MOVE?CB 8, BitCount ; Yes, reset bitcount
' incf SamplePTR, F ; Point to next byte
' decfsz ByteCount, F ; Are all 15 bytes done ?
' goto Int_Done ; NO, done for now
' MOVE?CT 1, _FlagSample ; Yes, Indicate - Samples Complete
' MOVE?CT 0, _TMR2ON ; stop the timer
'Int_Done
' btfsc PORTA, 3 ; Toggle porta.3 to check Interruption on OScilloscope
' goto Int_DNZ ; this really looks stupid.. longer than the rest of the
' goto Int_DZ ; routine :P
' Int_DZ
' bsf PORTA, 3
' goto Int_Done1
' Int_DNZ
' bcf PORTA, 3
' Int_Done1
' INT_RETURN
'ENDASM

</i></font><b>ASM
</b><font color="#008000">Sample
MOVE?BB SamplePTR, FSR </font><font color="#000080"><i>; Load FSR with pointer to array
</i></font><font color="#008000">MOVE?TT CMCON,7, STATUS,C </font><font color="#000080"><i>; Put sample in carry flag
</i></font><font color="#008000">rrf INDF, F </font><font color="#000080"><i>; Shift in the sample bit
</i></font><font color="#008000">decfsz BitCount, F </font><font color="#000080"><i>; Are all 8 bits in ?
</i></font><font color="#008000">goto Int_Done </font><font color="#000080"><i>; NO, done for now
</i></font><font color="#008000">MOVE?CB 8, BitCount </font><font color="#000080"><i>; Yes, reset bitcount
</i></font><font color="#008000">incf SamplePTR, F </font><font color="#000080"><i>; Point to next byte
</i></font><font color="#008000">decfsz ByteCount, F </font><font color="#000080"><i>; Are all 15 bytes done ?
</i></font><font color="#008000">goto Int_Done </font><font color="#000080"><i>; NO, done for now
</i></font><font color="#008000">MOVE?CT 1, _FlagSample </font><font color="#000080"><i>; Yes, Indicate - Samples Complete
</i></font><font color="#008000">MOVE?CT 0, _TMR2ON </font><font color="#000080"><i>; stop the timer
</i></font><font color="#008000">Int_Done
btfsc CMCON,7 </font><font color="#000080"><i>; Toggle porta.3 to check Interruption on OScilloscope
</i></font><font color="#008000">goto Int_DNZ </font><font color="#000080"><i>; this really looks stupid.. longer than the rest of the
</i></font><font color="#008000">goto Int_DZ </font><font color="#000080"><i>; routine :P
</i></font><font color="#008000">Int_DZ
bcf PORTA, 3
goto Int_Done1
Int_DNZ
bsf PORTA, 3
Int_Done1
INT_RETURN
</font><b>ENDASM

Hablar</b>: <font color="#000080"><i>' FUNCION DE INTERRUPCION DEL PUERTO SERIE, RECIBE CORRECTAMENTE TODOS LOS DATOS
</i></font><b>WHILE PIR1</b>.5 <font color="#000080"><i>' If RCIF is set, then read RCREG until it's clear
</i></font><b>ComIn </b>= <b>RCREG
WEND
HSEROUT </b>[<b>ComIn</b>]
<font color="#008000">@ INT_RETURN

</font></code></pre><!--EndFragment--></body>
</html>



Then here is what i got from my Serial Port


11111110
00000011
11111000
00011111
11000000
01111111
00000000
11111110
00000111
11110000
00011111
10000000
11111111
00000000
11111100


My first impression GREAT!! but nono. Why? because The fecuency sampled is 420Hz, considering 0.000125 samples per second the period of the signal should be (1/420Hz)/0.000125uS = 19 samples aproximately. From what i am getting you can see that the period is around 15 samples, which means 533,3 Hz.

So i Though maybe the comparator is not working correctly...but... Another modification to the handler to make porta.3 follow the comparator output showed this picture. Its a DTMF code not the 420Hz i used as sample.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2071&amp;stc=1&amp;d=119162448 4" width="160" height="98" />

So the Comp is working fine, and the sampling is being done a the correct frequency.
Here i took the 420Hz Comparator Output.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2072&stc=1&d=1191624933" width="160" height="98" />

Could it be... this is my last one... that something is wrong with the Handler... maybe between Byte changes a bit is missing? Obviously i have no idea of what you did there, BY THE WAY you will laugh at my ASM code to check things at porta.3 it has to be awful !!:D. It works but is longer than the sampling part.

Hope you can give me any ideas.

Darrel Taylor
- 6th October 2007, 02:53
I think I see the confusion. It depends on how you line up the bytes.

For Binary arrays, they go from Right To Left.

Here's the results again ...<table border=1><tr><td align=center>
11111110
00000011
11111000
00011111
11000000
01111111
00000000
11111110
00000111
11110000
00011111
10000000
11111111
00000000
11111100
</td></tr><tr><td align=left>Correct way.<br>4 bytes Aligned right to left<br>
<pre> 00011111111110000000001111111110<br> |------ 19 -------|</pre>
</td></tr><tr><td>Wrong way.<br>4 bytes Aligned left to right <br>
<pre> 11111110000000111111100000011111<br> |---- 14 ----|</pre>
</td></tr></table>

HTH,

Josuetas
- 6th October 2007, 05:41
Doh!
Doh!
Doh!
A whole day looking a that :D

Darrel this is the next question (i havent even look through it), now i have an array of 15 bytes, but i see it has a pointer EXT, is there a way to point to each Bit of this array? i am going to do some math to each bit now and this would be useful.

Something else, this project is short in code Space since i only have 2k of my 628A (no16F88 around here) removing ReEnter could save me 150 instructions? the fact is this piece of code is like 780 words already and i havent done anything :P.

Anyway tomorrow i´ll do the short math, i´ll begin to cry when the word count reaches 1800.

SteveB
- 6th October 2007, 06:44
...is there a way to point to each Bit of this array?
Melanie has provided the answer. See 3. How can I reference a BIT in a BYTE ARRAY? in her very helpful Bits, Bytes Words and Arrays Post (http://www.picbasic.co.uk/forum/showthread.php?t=544).

Thanks again Melanie. :D

SteveB

Josuetas
- 6th October 2007, 15:53
Thanks Steve i will be using it.

On the other hand.

Darrel this link
http://www.picbasic.co.uk/forum/showthread.php?t=3891#LAB ...

Its the post about the EXT modifier, i have been using it as a label to create tables in codespace in the past, BUT: right now i am using 628A wich doesn´t support READCODE instruction, can i still use it to create a table in codespace? if so (i guess i can) how can i read it?. It is a 14 bits x 120 Word, since the device is 14 bit i guess i could store each word in a memory space? kind of like the code to store strings in codespace? I havent been able to use the last one since i dont know how the data would be stored as Words and not as strings. Again ignorant about asm:(.

This is my table



</i></font><b>ASM
</b><font color="#008000">DataTable
DW 11111111111111b
DW 01010111111111b
DW 00000101010101b
DW 00000001010101b
DW 10101000000101b
DW 11111000000000b
DW 01111110000000b
DW 01011110101000b
DW 00000111101010b
DW 10000011111010b
DW 11100001111110b
DW 11111001011111b
DW 01111000010111b
DW 00011100010111b
DW 10000110000101b
DW 10000110000001b
DW 11100010100001b
DW 01110011100000b
DW 00111011111000b
DW 00011101111000b
DW 10001101111110b
DW 11000100011110b
DW 11100100011111b
DW 01110010000111b
DW 00111010000111b
DW 10011011100001b
DW 10001111100001b
DW 11001101100001b
DW 01100101111000b
DW 00110000111000b
DW 00110000011000b
DW 10011010011110b
DW 11001010001110b
DW 01001110000110b
DW 01100111000111b
DW 00110111100111b
DW 10110001100011b
DW 11010001110001b
DW 11001000111001b
DW 01001100011001b
DW 00101110011000b
DW 10110110011100b
DW 10110111001100b
DW 11010011001110b
DW 01001001100110b
DW 01001001100111b
DW 00101100110011b
DW 10110100110011b
DW 11110110110001b
DW 11010010011001b
DW 01000010011001b
DW 00001011001100b
DW 10101111001100b
DW 10111101101100b
DW 11110101100110b
DW 01010100100110b
DW 00000000110110b
DW 00001010110011b
DW 10101010010011b
DW 11111111011011b
DW 01111111011001b
DW 01010101001001b
DW 00000001001101b
DW 10000000101100b
DW 11101000100100b
DW 11111010110110b
DW 01111110110110b
DW 00010110110010b
DW 00000111010011b
DW 10000011010011b
DW 11100001001011b
DW 01111001001001b
DW 01111100101101b
DW 00011100101101b
DW 10000110101100b
DW 11000110110100b
DW 11100011110100b
DW 01111011010010b
DW 00111001010010b
DW 10011101000010b
DW 10001100001011b
DW 11000100001011b
DW 01100010101011b
DW 00110010101101b
DW 00111010111101b
DW 10011011110101b
DW 11001111010100b
DW 11000101010100b
DW 01100101010010b
DW 00110000000010b
DW 10111000001010b
DW 10011010101011b
DW 11001110101011b
DW 01001111111111b
DW 00100111111101b
DW 00110001111101b
DW 10110001010101b
DW 11011000010100b
DW 01001000000000b
DW 01001110000000b
DW 00100110100010b
DW 10110110101010b
DW 11110011101010b
DW 11010011111111b
DW 01001001111111b
DW 00001101011111b
DW 10101100010101b
DW 10110100000101b
DW 11110110000101b
DW 01010010000000b
DW 01001011100000b
DW 00001011101010b
DW 10101101111010b
DW 11111101111010b
DW 11110100111111b
DW 01010000011111b
DW 00000010010111b
DW 10001010000101b
DW 10101010000101b
DW 11111111100001b
</font><b>ENDASM

mister_e
- 6th October 2007, 16:45
There's still the 128 Byte EEPROM on board option... but it's way too limited.

LOOKUP(2)?

External EEPROM?

Josuetas
- 6th October 2007, 16:51
Eproom will store the strings of my LCD, and i would need 256 Bytes to store this table in Eproom vs the posible 120 "SemiWords" of codeSpace.

Thanks for your concern

And.. no external component.. i am looking for a low budget device here, also low Real State.

Archangel
- 6th October 2007, 23:40
Doh!
Doh!
Doh!
A whole day looking a that :D

Darrel this is the next question (i havent even look through it), now i have an array of 15 bytes, but i see it has a pointer EXT, is there a way to point to each Bit of this array? i am going to do some math to each bit now and this would be useful.

Something else, this project is short in code Space since i only have 2k of my 628A (no16F88 around here) removing ReEnter could save me 150 instructions? the fact is this piece of code is like 780 words already and i havent done anything :P.

Anyway tomorrow i´ll do the short math, i´ll begin to cry when the word count reaches 1800.
Hi Josuetas,
16F648A is the same chip with 2X the codespace and similar price, uses same data sheet too, but you get 4K instead of 2K.
JS

Josuetas
- 7th October 2007, 01:21
You cant imagine how nice it would be for me to find one around here!

The fact is that 648A is sold out, today i went looking for it with no success.

Not finding supplies around here really makes me sad.

So it seems i will have to upgrade the uC to something like 876A, easily found here. Though more expensive. Its sad because 876A is not improving anything for me, maybe just the speed, but even there i will have to use an external OSC ($$).

What i really need here is 16F88, int OSC 8 Mhz always better than 4 Mhz and 4K memory should be enough.

I am from Colombia South America by the way... wanna switch? ;)


Leaving this discussion Aside... i am not done with 628A you know? i havent reached 1800 words (where i will cry) right now i just need to store the table in code space... do you know the way? the solutions about this given in the forum use READCODE wich 628A cant execute.

Archangel
- 7th October 2007, 04:55
Aside from lack of PICs, oh and that thing about the cartels . . .I hear Colombia has many nice things, great coffee, emeralds, cattle ranches, I knew a girl from there who went back and became Miss Colombia, and she was cute too !, but no I am too old to make that big of a change. I did not know from where you are hailing, will U S Suppliers not ship to Colombia? I do not know of any techknowlegy restrictions regarding shipping to your Country, You might check with www.Mouser.com

Josuetas
- 7th October 2007, 06:23
No complains... it would take like two weeks for that pic to arrive here, and would cost me around 45 dolars (Shipping). Its not that i cant find pics here... there are just not all the ones i want.. switching to 876 its possible but... we are forgetting the real problem... nOT THE PIC!!... i need to store and retrieve that table!!! it has to be pretty simple.. REMEMBER 628 still has free code space.

By the way every one seems to know someone from Colombia... i´ve had more foreign Girlfriends than girls from here.. although yes YES... women here are hot hot. I was kidding about switching i´ve been to many places and i wouldnt.... but the invite is still on the table you MUST visit us :D... someday...