Newbie problem with 12c671

Hi,

I am trying to modulate a serial pulse from my PC but the results seem a little delayed, for example if I transmit 0x20 onto PORTA, bit 3 thus:

+----+----+----+----+----+----+ +----+----+ | | | | | | | | ------+ +----+ +-------- A i get this out on PORTA, bit 0: B +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ----------+ +-+ +-+ +-+ +-+ +-+ +-+ +--------+ +-+ +--------

The gap between the signal changing on porta (A), and the software detecting it and pulsing bit 0 (B)seems unduly long. it is certainly more than one run through of the main loop..

I have a suspision it is to do with the A to D converters, but I'm a little concerned about interrupt on change..

Any Ideas??

Reply to
Jonathan Campbell
Loading thread data ...

snipped-for-privacy@teknowledge.co.uk (Jonathan Campbell) wrote in news: snipped-for-privacy@posting.google.com:

Don't know how exact your timing diagrams are, but that delay looks suspiciously like one half-period of the frequency you're outputting on port B. Some code would help, but it looks like when you enable the square-wave output on port B you're starting off in the low phase rather than the high phase.

Reply to
Eric Bohlman

It's not a big program, and I'm trying to do it without interrupts. Anyway, Here's the code:

{ LoadOscCal (); /* set bank 1 registers set RP0 */ STATUS |= 0x20 ; ADCON1 = 0x07 ; /* all outputs digital */ INTCON = 0x00 ; /* disable all interrupts */

/* set bank 0 registers */ STATUS &= ~0x20 ; ADCON0 = 0x00 ; TRISA = 0x0C ; /* set the ports */ /* start the main loop */ MainLoop:

if (PG.B3) { PG.B0 = 1 ; for (Wait = 0; Wait < 4; Wait++) ; /* these delays need to be changed */ PG.B0 = 0 ; for (Wait = 0; Wait < 4; Wait++) ; } if (PG.B2) { PG.B5 = 1 ; for (Wait = 0; Wait < 20; Wait++) ; PG.B5 = 0 ; } goto MainLoop ; }

#pragma asm RbAddr=_TOPROM+1 LoadOscCal: movlw RbAddr>>8 movwf PCLATH call RbAddr bsf STATUS,RP0 movwf OSCCAL bcf STATUS,RP0 clrf PCLATH MRET 0 LOCSavePC=$ org RbAddr retlw 0xff org LOCSavePC #pragma asmend

Reply to
Jonathan Campbell

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.