pattern gen

Status
Not open for further replies.

ppcv

New Member
Hi everyone

I need to generate the pattern across the portB -mentioned in the look up table at 67Khz frequency.

With the below when montired in the oscillscope - the frequecy was hardly 100Hz. Do i need to add more delay or increase the counter value to get the pattern generated at 67Khz frequency.

Can anyone help me on this??

-
LIST p=16F876A ;tell assembler what chip we are using
include "P16F876A.inc" ;include the defaults for the chip
;----------------------
#define CONF1 _CP_OFF & _DEBUG_OFF & _CPD_OFF
#define CONF2 _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

__CONFIG CONF1 & CONF2
;---------------------
cblock 0x20 ;start of general purpose registers
count ;used in table read routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
;-------------------------

LEDTRIS Equ TRISB ;set constant for TRIS register
;---------------------------
org 0x0000 ;org sets the origin, 0x0000 for the 16F876A
;-----------
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F876)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
bcf STATUS, RP0 ;select bank 0

;------------------

Start clrf count ;set counter register to zero
Read movf count, w ;put counter value in W
call Table

call Delay
incf count, w
xorlw d'14' ;check for last (14th) entry
btfsc STATUS, Z
goto Start ;if start from beginning
incf count, f ;else do next
goto Read

Table ADDWF PCL, f ;data table for bit pattern
retlw b'00000000'
retlw b'10000010'
retlw b'10000011'
retlw b'10000010'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00110100'
retlw b'00110001'
retlw b'01100000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'10000010'
retlw b'10000011'
retlw b'00000000'
retlw b'10000010'


Delay movlw d'2' ;delay 250 ms (4 MHz clock)

movwf count1
d1 movlw 0xC0
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+1
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00
;------------------------------
end
 

You need to massively reduce the delay, for a start try removing it all together, and see how fast it works then - that will give the maximum possible speed.
 
pgen

Hello Nigel

Thanks. Yes, the pattern is generating at 14Mhz. But i am not able to see the pattern which mentioned in the lookup table.

To achieve the desired 67K frequency - if i add delay in between pattern - will this work.

pl. advice. and I am not able to open the first link of the website given by you.
 
Re: pgen

ppcv said:
Hello Nigel

Thanks. Yes, the pattern is generating at 14Mhz. But i am not able to see the pattern which mentioned in the lookup table.

It's not going to be anywhere near 14MHz!.

Assuming you are running the PIC at 20MHz each instruction cycle is 200nS (5MHz), most commands take one instruction cycle, with program jumps taking two cycles.

To achieve the desired 67K frequency - if i add delay in between pattern - will this work.

Add a delay where it was before, but considerably shorter.

pl. advice. and I am not able to open the first link of the website given by you.

The two links are the same, the first is via a web forwarding service, the second direct.
 
pgen

Hi
Sorry it was 1Mhz.
To achieve with 67K of the look up table pattern - it will be great help for me if you could send me the modifications/rectifications in the coding and oblige.
 
Without a delay, you should still see the pattern, but at a higher frequency. If you can't even see the pattern, then the code is fundamentally wrong in the first place.
 
Re: pgen

ppcv said:
Hi
Sorry it was 1Mhz.
To achieve with 67K of the look up table pattern - it will be great help for me if you could send me the modifications/rectifications in the coding and oblige.

You just need a much shorter delay, it's quite simple to work out how long (ignoring any extra delays introduced by the rest of the program). To find the time for one wavlength simply divide 1 by the frequency, so 1/67000=15uS. So the total time for one wavelength is only 15uS.

This is for a full wavelength, so the time per sample is 15/number of samples. Your number of samples isn't very clear?, you check for d'14', yet there are 22 samples in the table?.

Anyway, I'll assume 15 sample, which gives a time of 1uS per sample - which is very short!.

Try replacing your Delay routine with this:

Code:
Delay
       Nop
       Nop
       Return

Which allows for the 400nS 'Call' as well.

But I don't really see how the code with no delay could reach 1MHz?, still try this delay routine and see what you get.

BTW, what is the table supposed to be?, it looks a pretty boring waveform!.
 
Hi

Thanks.Below is the modified code. With debugger stop watch- each pattern cycle is taking 15us. But need to check in oscilloscope.
The waveform is given input to transistors.
can u assist me in getting the patterns at 67K/70K frequency.

-----
LIST p=16F876A ;tell assembler what chip we are using
include "P16F876A.inc" ;include the defaults for the chip
;----------------------
#define CONF1 _CP_OFF & _DEBUG_OFF & _CPD_OFF
#define CONF2 _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

__CONFIG CONF1 & CONF2
;---------------------
cblock 0x20 ;start of general purpose registers
count ;used in table read routine
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc
;-------------------------

LEDTRIS Equ TRISB ;set constant for TRIS register
;---------------------------
org 0x0000 ;org sets the origin, 0x0000 for the 16F876A
;-----------
;this is where the program starts running
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F876A)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf LEDTRIS
bcf STATUS, RP0 ;select bank 0

;------------------

Start clrf count ;set counter register to zero
Read movf count, w ;put counter value in W
call Table

call Delay
call Delay1
incf count, w
xorlw d'22' ;check for last (22nd) entry
btfsc STATUS, Z
goto Start ;if start from beginning
incf count, f ;else do next
goto Read

Table ADDWF PCL, f ;data table for bit pattern
retlw b'00000000'
call Delay1

retlw b'10000010'
call Delay1
retlw b'10000011'

retlw b'10000010'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00110100'
retlw b'00110001'
retlw b'01100000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'00000000'
retlw b'10000010'
retlw b'10000011'
retlw b'00000000'
retlw b'10000010'

Delay
Nop
Nop
Nop
Nop
Nop
Nop

Return

Delay1
Nop
Nop
Return

;------------------------------
end
[/quote]
 
ppcv said:
Thanks.Below is the modified code. With debugger stop watch- each pattern cycle is taking 15us. But need to check in oscilloscope.
The waveform is given input to transistors.
can u assist me in getting the patterns at 67K/70K frequency.

If each pattern cycle takes 15uS, then it's already running at 67KHz.

I'm a bit puzzled about your reference to feeding transistors, I'd presumed you were feeding a digital to analogue converter, perhaps using an R2R ladder network?.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…