16f628a as a Timing Generator

Status
Not open for further replies.

Breixo

New Member
Hi to all,

I wish to implement a Timing Generator with a 16F628A. The premises are:

- uC Oscillator (4 to 20 MHz)
- 1 Master Signal of 400kHz
- 2 Binary signals at 10kHz, based in Master Signal
- 4 signals with a programmable timing of 10 to 20 us, each one in each of the four Binary Signals states.
- 1 Reset signal af the final of each binary state
- Communication with other uC (future)

At the moment, I've obtained 400kHz in pin RB3 using PWM mode and TMR2 but I'm clogged and I don't know how to follow.

I don't want to abuse so I don't hope for code (well, if there's some example, it will be welcome, of course), but I need some suggestions as how can I to implement that to follow.

breixo

P.S. Any interrupt driven routine?
 
Well I don't know about anyone else, but I don't have much of a clue about exactly what you want?.
 
hi,

As Nigel points out we need more information on what you are trying to achieve.

Looking at your description, I could come up with a dozen different answers, probably all well off target.

Try to describe what you are trying do in a more precise way, also give an example of what is the purpose/usage of the output is going to be.

I am sure many of us would like to help you.

EricG
 
Hi Nigel,

First of all, my gratefulness by your wonderful PIC Tutorial. Well, what I want?, "technically", I want a "small push". I'm a newbie and that's my first attempt in the PIC field and my head is saturated of interrupts, timers, etc.
After to surf the net and to reread some docs, I thing that my doubts could be summarized in three questions:

a) Can I use an interrupt service inside another one interrupt service?
b) Are interrupts prioritized?
c) Where can I have a good Interrupt Manager in assembler?

Thanks and sorry for my ugly English,

Breixo
 

Basically no! - which is why it's important to keep ISR's as short as possible.

b) Are interrupts prioritized?

No, at least not on 16F devices.

c) Where can I have a good Interrupt Manager in assembler?

You write it yourself, it's not at all complicated - although you can do many things with a PIC without using interrupts at all.
 
Breixo said:
Hi Nigel,
a) Can I use an interrupt service inside another one interrupt service?

No, although it is possible, it is not recommended and normally not required.

b) Are interrupts prioritized?
No, not on the 16 series. Each interrupt sets a bit (in INTCON or PIR) and you have to check the bits to find out what caused the interrupt request.
c) Where can I have a good Interrupt Manager in assembler?
If you have MPLAB installed have a look in C:\Program Files\Microchip\MPASM Suite\Template\Code or where ever you installed it and you will find f628temp.asm . This is a template for the 16F628 and includes the concept saving code required.

Thanks and sorry for my ugly English,

It's better than my [insert any language except English].

Mike.
 
Hi,

Thanks to all for your interest. Well, I wish to make a "programmable" timing for a Range-Gated Radar Sensor, that's, the sensor has the possibility to analyze what's happen inside each range. Each range is determined by the 2-bit Binary Counter Signals BIN0-1. After each range, a RST Signal discharges a hold capacitor and the four RGE1-3 Signal are the Sample Gates. All signal are referenced to the main clock CLK400K (400KHz) but if the PIC implementation has syncronism problems, all signals (including the main clock) can restart each Range cycle as is indicated in the red circle, for instance (See attachment).

This PIC Timing Generator will be connected to other PIC that basically has two functions, one is to enable it and the other one is to send it new parameters for the RGE1-3 sample signals. Others functions of the main PIC are related with radar signals.

At the moment, I've obtained the main clock of 400kHz using PWM mode and Timer1, and the 2-Bit Binary Counter using Timer0 and the clock of 400kHz wiring RB3/CCP1 to R4/T0CKI, so I've Timer2 to implement the RGE1-4 Signals and because each of these signal aren't simulateous, I think that I can calculate a common RGE signal and redirect it to its respective output and here I'm stopped. I let the RST signal at the final.

Am I in the good way?
Are there better ways?
Any suggestion to implement the common Range Signal?

Thanks to all,


P.S. I had thought that a Timing Generator would be easy to introduce to me in the PICs but I did not have thought with the interruptions . By the way, I have not found in Internet any similar applicación.
 

Attachments

  • timing.jpg
    173.5 KB · Views: 374
I don't fully understand what you are trying to do.
Can you answer a few questions.
Are all the waveforms on you diagram outputs?
Are they all required?
What is a range?
What is the time from the start of a range to the range pulse?
What defines the length of the range pulse?

To do the above timing with a pic is pushing it. Your CCP code has only 10 instructions in which to change the CCP mode to produce the 400kHz waveform with a 16MHz crystal (12.5 with a 20MHz).

If on the other hand the 400kHz signal is not required and is just your way of describing it and the 4 range signals are the only outputs then a pic can do it.

A better description of what you are trying to do would help.

Mike.
 
Hi Pommie,
Pommie said:
Are all the waveforms on you diagram outputs?
Yes.
Pommie said:
Are they all required?
Yes, I generate the 400KHz from the PIC's Crystal Oscillator (10 MHz ->416.666kHz, if I find 9.6MHz ->400kHz almost exact). This clock will be the Pulse Repetition Frequency or time between radar's burst, so, all the rest of signal are referred to it.
Pommie said:
What is a range?
Sorry, that's a jargon word from radar technology. Range is the distance from a target object such as a hole in golf, an object being tracked by radar, a military target. (From Wikipedia English).
Pommie said:
What is the time from the start of a range to the range pulse?
Here is where I stopped. I need to count the 400kHz steps from the begining of each range (signal range low->blind) ...
Pommie said:
What defines the length of the range pulse?
... and launch a high level gate of 15 to 20uS to listen the echoes.
The low and high of these range signal should be fixed "manually" with a resolution based in the 400kHz period. Later could be adjusted automatically.
Pommie said:
To do the above timing with a pic is pushing it. Your CCP code has only 10 instructions in which to change the CCP mode to produce the 400kHz waveform with a 16MHz crystal (12.5 with a 20MHz).
Yes, it was easy to use the PWM Mode but now I'm thinking that perhaps I had to preserve the PWM mode to generate the reach pulses. My inexperience in the use of the PICs is what it makes me have too much doubts.
Pommie said:
If on the other hand the 400kHz signal is not required and is just your way of describing it and the 4 range signals are the only outputs then a pic can do it.
As I say above, it's the "mother of the signals".
Pommie said:
A better description of what you are trying to do would help.
I don't know if that will be enough. This is my first incursion in the PICs and in a English forum and probably I have been mistaken thinking that a timing would be easiest with the resources of a PIC.
If I don't receive other suggestions, my last bullet will be to use the PIC of "crude" way by means of combinations of delays.

My apollogies to disturb to all of you and thank you very much for your interest.

Breixo
 
It's still not clear if the 400KHz signal is needed by another part of the circuit or just as a timing reference. If as you state all the signals are required by other parts of the circuit then I think this cannot be done with a 628. Actually, the timing diagram you posted above could be generated but varying the delays wouldn't be possible.

Mike.
Edit, if a pause is allowed after range 4 but before the start of the next range 1, then it can be done.
 
Last edited:
Hi Mike,

Yes, the 400kHz are the "carrier" so it's needed to send the burst signal and to translate the received echoes to an audio frequency.
Pommie said:
Edit, if a pause is allowed after range 4 but before the start of the next range 1, then it can be done.
Yes, moreover, a pause is allowed at the final of each range. After all, each cycle range can be considered independent.

Thanks,

Breixo
 
I got a little time today so thought I would give this a go. It's a long time since I did any cycle counting like this.
This is not very elegant but will work.

This will only work with a 16MHz crystal.
Variable "Start" contains the delay before the range signal.
Variable "Length" contains the length of the range signal.
Both these variables are multiples of the 400KHz signal and so a value of 3 will be 3 whole cycles of the 400KHz signal.
RB7 = 400KHz
RB6 and RB5 = bin0 and bin1
RB4 = RST
RB3 = Range 1
The bin1 and bin0 outputs can be generated by changing the various values in ranges 2-4.
You could repeat this code 4 times to give the four range signals as required.
Code:
Start		movlw	b'00000000'	;	bit 7 is the 400KHz signal
		movwf	PORTB		;1
		goto	$+1		;3
		movlw	b'10010000' 	;4	reset is bit 4
		nop;			;5
		movwf	PORTB		;1	set 400K bit and reset bit
		call	delay4		;5
Loop		clrf	PORTB		;1
		call	delay4		;5	
		bsf	PORTB,7		;1
		nop			;2
		decfsz	StartDelay,F;	;3 or 4
		goto	Loop		;exit on 5
StartPulse	movlw	b'00001000'	;5	set the range bit
PulseLoop	movwf	PORTB		;1	range bit is bit 3
		call	delay4
		bsf	PORTB,7		;1
		nop			;2
		decfsz	Length,F	;3 or 4
		goto	PulseLoop	;5
ExitPulse	nop			;5
		clrf	PORTB
; add another loop here to complete the 50uS if needed.

hang	goto	hang

delay4		return

The numbers are clock cycle counts. To generate 400KHz bit 7 has to be toggled every 5 clock cycles.

Hope that makes sense.

Mike.
 
Hi, Pommie,

First of all, thank you for your answer. Second, sorry for my delay but I've had left a side, momentarily, this design and now I retake it.

The fact is that you demostrate me that this timing can be implemented in a very simple way that it seems to cover my necessities. Nevertheles, I'm an illiterate in assembler and I'm unable to implement the BIN0 and BIN1.

If you see the timing picture I've attached, the hierarchy of the signals is 400KHz->BINx->RANGEx->RESET

Can you give me the last push?


Breixo

P.S. Please, I hope that you don't think that I want that you make my work (Well, with exception of this routine, of course! ). As a hobbyst, I use PICbasic, but in this part of the design the PICbasic is too slow. The rest of the design is another PIC to process the results of a Range Gated Ultra Wideband Radar Sensor that I'm desinging, too.
 
Hi, Pommie,

Finally, I got it!. Thanks to your code I think I could follow my design.

Thank you very much and best regards,

Breixo
 
Hi,
blueroomelectronics said:
Breixo, what did you use to draw your timing diagram?
I've used Proteus. After to make an emulation with primitives I put the results in a Graphic, after I export it, a little make-up and that's all.

Regards,
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…