Sub-Microsecond Pulse Generation

Go To Last Post
73 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello dear all,
I have a question on possibility of generating 500 ns pulses (actually four 500 ns pulses with a delay of 500 ns between each two of them, as shown in the picture attached!). I'm now using an Atmega16, but I guess it's not possible to do such thing and have such tight pulses using this chip. maybe I should use an external high frequency crystal? or should I change my chip to some other chips like ATtiny 26 o ATtiny15 which feature high speed timers.
I also wanted to know If it's possible to do such thing using only one chip.
by the way, should I basically use the PWM mode or there's other ways to do so?
I'll very thankful if anybody can help me.

cheers,
Arvin

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A cycle on a 16MHz AVR is 62.5ns isn't it? I make 8 of those in 500ns. So I guess the question is whether you can wiggle the wire in 8 cycles? Gut feeling says yes.

BTW not sure if you could actually use PWM on a timer with a 25% duty cycle?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This would be a completely hardware solution for the ATmega16. So no problem with a clock of 4, 8, 12 or 16 MHz. Take a look at the PWM modes of ATmega16.

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for your replies. I think I should use all the four PWM channels of ATmega16 to have the four pulse-trains, right?
but still question remains, since the pulse duraion is only 8 cycles, is it possible to write a program for it without making any troubles? (I'm using BASCOM-AVR).

by the way, has anybody done some thing like this before? I mean generating synchronous phase shifted pulses? if so please inform me :)

cheers,
Arvin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well if you soft code it you'll probably want to work in Asm in fact so you can count exact cycles. But if you use timer-PWM then whether you set up the registers to do it in Asm, C, Pascal, Forth or BASIC makes no difference. Once the process starts it has nothing to do with the efficiency of the language compiler's code generation it all happens "hands off" in the timer's hardware.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I think I should use all the four PWM channels of ATmega16 to have the four pulse-trains, right?

I don't think the ATmega16 is good enough for the strict timer PWM solution - the 8-bit timers have a fixed TOP giving an output frequency of F_CPU/(N*256) where N is the prescaler. You can not reach 500KHz with this. Newer AVR:s, e.g., ATmega48,88,168 have more flexible 8-bit timers.
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm guessing that you want to do more than just output a neverending stream of unchanging pulses. What do you need to be able to alter in this pulse string? Phase? Pulse width? Pulse rate?

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

the 8-bit timers have a fixed TOP giving an output frequency of F_CPU/(N*256) where N is the prescaler. You can not reach 500KHz with this.

But many of the 8-bit timers (though not all) have CTC mode with toggle-on-compare-match. For such short durations, though, you cannot afford to interrupt each time to count the pulses to turn them off. [Note that at least one of the AVR model lines--AT90PWMx?--has a counting feature for PWM cycles.]

But for this short a time, just use a string of ASM NOP CBI, and SBI.

Oops, just looked at the timing diagram. I thought it was 4 pulses and stop on one I/O pin. I just looked at the document, and it is 4 separate clocks 90 degrees out of phase, with a 25% duty cycle.

Lessee--if you run a Tiny25 at 20MHz, then each clock is 50ns. If you can afford the 500ns to be +100ns (giving 600 on and 1400 off, 30% duty cycle instead of 25%) then just let the Tiny25 do its thing. Still one I/O left over for on/off control.

If these edge relationships and duty cycle are "strict", then I can only see it being down with 4 PWMs with synchronized clocks (and I don't know if any of the centipedes will synchronize that many.) AT90PWM3 could do 3 of them, I think.

There is always good-old-fashioned logic, with a binary counter and a few AND gates. Or new-fangled programmable logic.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Duh--since we are grabbing whatever resources are needed, of COURSE one could meet that timing exactly with an AVR--but it would take the whole AVR.

Let's use our Tiny25 again, and run it at a sedate 8MHz to make typing easier. We'll say that we'll save PB2 for INT0 for On/Off control, and PB0-PB1-PB3-PB4 are our outputs.

; FOR 8MHZ, 125NS PER CLOCK, FOUR CLOCKS PER PHASE
	LDI	R16, 0x1b
	OUT	DDRB, R16	; PB0,1,3,4 as  outputs
; do further setup for PB2 On/Off control via INT0 ISR.

; SET THE PATTERNS FOR THE FOUR PHASES
	LDI	R16, 0X01
	LDI	R17, 0X02
	LDI	R18, 0X08
	LDI	R19, 0X10
...
THE_LOOP:
	OUT	PORTB, R16
	NOP
	NOP
	NOP
	OUT	PORTB, R17
	NOP
	NOP
	NOP
	OUT	PORTB, R18
	NOP
	NOP
	NOP
	OUT	PORTB, R19
	NOP
	RJMP	THE_LOOP
...

That can be the whole program, I think, if you don't need on/off control and the 8MHz internal oscillator is close enough. With a crystal you kinda run out of pins. No real problem for a one-off; instead of a US$1.00 Tiny25 use $1.25 Tiny2313 or $1.50 Mega48.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems clear that you are not going to do anything else with your AVR except make the pulse train.

Using bits 0..3 of PORTB, this looks extensible for up to 8 pulses.

        .include "2313def.inc"
        ldi    r16,0x0f
        out    DDRB,r16
        rjmp   start
loop:   out    PORTB,r16
        nop               ;add more nops for >16MHz
        add    r16,r16
        andi   r16,0x0f
        brne   skip
start:  ldi    r16,1
skip:   rjmp   loop

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You win Lee.

I need a 16MHz clock. Your method could even use a LDI R16,0x10 etc instead of one NOP and still work at 8MHz.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm, but why use a software solution for a modern AVR (tiny24, 25, 2313 etc.) which can do it all in hardware? Only the old AVRs have fixed top values for the PWM modes.

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Hmmm, but why use a software solution for a modern AVR (tiny24, 25, 2313 etc.) which can do it all in hardware? Only the old AVRs have fixed top values for the PWM modes.

You cannot generate the pulse train in the OP's attachment, 4 separate pins, with any AVR unless 4 timers can be locked together, and I don't think there are any models that are. Perhaps with cycle counting and initial values. But that takes one of the centipedes, much more expensive than dedicating a Tiny25 or Tiny2313 or Mega48.

Quote:

I need a 16MHz clock. Your method could even use a LDI R16,0x10 etc instead of one NOP and still work at 8MHz.

Note that with my NOPs, I'm only really using half the processor. On/Off control, for example, could take the place of the NOPs.

Now, the next thing that OP will want to do is to vary the duty cycle and/or period. Then use Jesper's mini-DDS approach (I forget what it is called) and a lookup table for the port values.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Multiple counter/timers using the same prescaler setup values can be synchronized in AVRs that have a register like the ATmega88 GTCCR – General Timer/Counter Control Register (TSM bit). However, if any running timer/counter setup is manipulated by software, the synchronization will probably be lost. Another drawback is all the synchronous counters are lumped together in one prescaler reset bit, while the asynchronous counter has an individual prescaler reset bit. This means all the synchronous timer/counters will have their prescalers held in reset for a period of time, even any other synchronous timer/counters that you are not trying to synchronize with TSM. It is not quite being locked together, but under limited controlled circumstances it can emulate being locked together.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Multiple counter/timers using the same prescaler setup values can be synchronized in AVRs that have a register like the ATmega88 GTCCR ...

Agreed on all points--but OP wants to synchronize 4 pins. Do the centipedes let you sync more than 2? Yep--"Timer/Counter 0, 1, 3, 4, and 5 share the same prescaler module, ..." and there is a reset. And 1,3,4,5 are 16-bit timers; should have full capability. So then we'd have to pre-load 1,2,4, & 8 into the TCNTn registers, sync the prescalers, and "go", right?

I kinda like the $2 Tiny25/Tiny2313 solution rather than the 100-pin surface-mount Mega640 at $12/qty. 1. ;)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

[edit]Never mind![edit]

Last Edited: Mon. Mar 17, 2008 - 10:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Oops, I forgot the other drawback. If you set CLKio/1 (No prescaling) then the prescaler reset doesn't do anything useful.
The TSM bit is still useful allowing you stop the counting while you clear (or preload) all TCNTx.
Still need an AVR with enough PWM outputs and enough timers that share a prescaler. On the other hand, if the error from not having a common prescaler is predictable and can be compensated for, then many smaller AVR:s should also work.

Note that a single 16-bit timer with two pwm outputs can generate, e.g., the 1st and the 4th signal in the OP:s pdf, one non-inverting and one inverting.
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you really hate efficient small processors :) and don't mind waiting for the availability barrier to be broken, it looks like an Xmega would do it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

If you really hate efficient small processors Smile and don't mind waiting for the availability barrier to be broken, it looks like an Xmega would do it.

Yeah, the port-DMA, if it will do what I think it will, should do it nicely. Function-generatores, here we come... And for waveforms, stream the DAC(s)!

But for this, I posted the complete Tiny25 program already. ;)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You cannot generate the pulse train in the OP's attachment, 4 separate pins, with any AVR unless 4 timers can be locked together, and I don't think there are any models that are.

Right! I knew I was wrong but I didn't know why. Thank you Lee for being patient.

Well, but I still think it is possible to generate the pulses by a complete hardware solution with 2 timers and 4 dual AND gates.

Timer0 generates a square wave with a duty cycle of 50% (OC0A) and a corresponding inverted square wave (OC0B)

Timer1 generates the same 2 squarewaves but shifted by 90°comparing to the Timer0 waves.

The 4 waves are fed into 4 dual AND gates and on the gate outputs you see the demanded signals.

Regards
Sebastian

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Quote:
You cannot generate the pulse train in the OP's attachment, 4 separate pins, with any AVR unless 4 timers can be locked together, and I don't think there are any models that are.

Right! I knew I was wrong but I didn't know why.


Note that I took that back: one can sync the times on the centipedes of Mega128-class.

If you are going to add the external logic, then why not just use a counter chip with the gates behind it? The only AVR involvement, then, might be to provide the clock for the counter chip. Four states, give it a 2MHz clock, and only need logic on the low two bits, right?

O1 = Output 1; B0 = Bit 0; etc.

O1 = NOT B0 AND NOT B1
O2 = B0 AND NOT B1
O3 = NOT B0 AND B1
O4 = B0 AND B1

lEE

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not use a 4017 or a 4022 or similar, clocked with a with a 2 MHz clock and with the Q4 tied to reset? Outputs Q0 to Q3 is what youre looking for. Should work fine.

Felipe Maimon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S-Sohn wrote:
Quote:
You cannot generate the pulse train in the OP's attachment, 4 separate pins, with any AVR unless 4 timers can be locked together, and I don't think there are any models that are.

Right! I knew I was wrong but I didn't know why. Thank you Lee for being patient.

Well, but I still think it is possible to generate the pulses by a complete hardware solution with 2 timers and 4 dual AND gates.

Timer0 generates a square wave with a duty cycle of 50% (OC0A) and a corresponding inverted square wave (OC0B)

Timer1 generates the same 2 squarewaves but shifted by 90°comparing to the Timer0 waves.

The 4 waves are fed into 4 dual AND gates and on the gate outputs you see the demanded signals.

Regards
Sebastian

You are likely to get glitches in the signals doing it this way.

One solution that comes to my mind is to use 4 bits of a 74HC164 shift register along with one gate of a 74HC27 for feedback.

But, again, the OP needs to clarify if he really just wants to generate a neverending pulse train with no variation whatsoever. I have to believe he also wants to modify this pulse train in some way. If so then this becomes an entirely new problem.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
You are likely to get glitches in the signals doing it this way.
Can you explain this in more details, please?

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S-Sohn wrote:
Quote:
You are likely to get glitches in the signals doing it this way.
Can you explain this in more details, please?

Regards
Sebastian

Actually, I think I misspoke. While you do have multiple edges changing at the same time (a recipe for glitches), you never use any two signals changing at the same time as inputs to the same gate. So I take it all back - I don't see your solution producing glitches after all.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh I'm kinda surprised with all these discussions here! They're all so useful for me... Thanks to you all for being so responsible :)

snarflemike wrote:

But, again, the OP needs to clarify if he really just wants to generate a neverending pulse train with no variation whatsoever. I have to believe he also wants to modify this pulse train in some way. If so then this becomes an entirely new problem.

well I should clarify that all I need is to generate these four never-ending pulse trains. No further variations and modifications are needed. The only important point is the exact timings and pulse shapes.
furthermore, 500 ns is the maximum pulse width I can use in my system. shorter pulse widths (about 200 ns) is more desired.

cheers,
Arvin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee's solution with a Tiny at 20MHz should give you 200nS. You could even tweak it to 150nS.

It would be interesting to see if someone can get synchronised PWM on four pins though.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

arvinik wrote:
well I should clarify that all I need is to generate these four never-ending pulse trains. No further variations and modifications are needed. The only important point is the exact timings and pulse shapes.
furthermore, 500 ns is the maximum pulse width I can use in my system. shorter pulse widths (about 200 ns) is more desired.

cheers,
Arvin


Well in that case, a small AVR may be the absolute minimum parts count solution. If you don't need crystal-controlled accuracy (and it sounds like you don't), then using the built-in oscillator and running the code posted but removing one NOP from each channel you can get pulses of about 375ns, which is well within your specification. One small chip, no crystal. Doesn't get any more minimum than that. :)

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Tiny13 has a 9.6Mhz internal osc. that should be able to trim to 10Mhz without any trouble. That would get you down to a 300ns pulse.
May I ask what these signals are being used for?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is yet another one to consider. I don't know if you would call it a "one chip solution". It is probably cheaper than any AVR but then again, it needs an external clock signal.
The RC-network and NFET are needed for bootstrapping.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The Tiny13 has a 9.6Mhz internal osc. that should be able to trim to 10Mhz without any trouble.

The Tiny25 datasheet charts seem to indicate that OSCCAL at max should take the Tiny25 to 12MHz-16MHz. ;) With no EEPROM access or LPM, shouldn't be a problem.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
The Tiny25 datasheet charts seem to indicate that OSCCAL at max should take the Tiny25 to 12MHz-16MHz. Wink With no EEPROM access or LPM, shouldn't be a problem.

Good point, but might as well go with the cheaper of the two :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you buy 1, you do indeed save US$0.30; if you buy 25, you do indeed save US$5--which will be dwarfed by shipping and min order charges. If you have Tiny25's on hand, or purchase $25 of "assorted" AVRs, at least you've got something for the next project that is "useful". [My recommendation would be to go for Mega48 to have around for the next projects.] Note that using the centipede for the PWM solution is ~$15/qty. 1. ;)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
It would be interesting to see if someone can get synchronised PWM on four pins though.

Ok, for mega 48,88,168 (provided you have a resonable F_CPU):

#define TFREQ (F_CPU / 500000)
#define TPULSE (TFREQ / 4)

DDRB = (1<<PB2)|(1<<PB1); // OC1A, OC1B
DDRD = (1<<PD5)|(1<<PD3); // OC2B, OC0B
GTCCR = (1<<TSM)|(1<<PSRSYNC);
TCCR0A = (1<<COM0B1)|(1<<WGM01)|(1<<WGM00);
TCCR0B = (1<<WGM02)|(1<<CS00);
TCCR1A = (1<<COM1A1)|(1<<COM1B1)|(1<<COM1B0)|(1<<WGM11);
TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS10);
TCCR2A = (1<<COM2B1)|(1<<WGM21)|(1<<WGM20);
TCCR2B = (1<<WGM22);
OCR0A = TFREQ - 1;
OCR0B = TPULSE - 1;
TCNT0 = 256 - TPULSE + 1;
// Magic # 5 is the # of cycles for doing TCCR2B |=(1<<CS20);
TCNT2 = 256 - 2*TPULSE + 1 + 5; 
ICR1 = TFREQ - 1;
OCR1A = TPULSE - 1;
OCR1B = 3 * TPULSE - 1;
OCR2A = TFREQ - 1;
OCR2B = TPULSE - 1;
GTCCR = 0;
TCCR2B |= (1<<CS20);
while(1);

The magic number (5) is because timer 2 has its own prescaler - it can not be reset with the timer 0 and 1 prescaler. On a mega128 or similar there would be no need for this trick.
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you all for your kind replies.

fmaimon wrote:
Why not use a 4017 or a 4022 or similar, clocked with a with a 2 MHz clock and with the Q4 tied to reset? Outputs Q0 to Q3 is what youre looking for. Should work fine.

This worked really fine. Now what I need is the 2-5 Mhz clock pulse generator(for 500-200 ns pulses). do you think it's good to use the AVR chip to generate such pulses? or u recommend other oscillator circuits?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could use an ATtiny25 for this purpose. Timer1 of this device can be clocked by a 64MHz signal. The 64MHz (PLL) clock is the multiplied frequency of the internal 8MHz oscillator. This oscillator can be calibrated. You can gain 1% clock accuracy. Connect a crystal to the ATtiny25. To do calibration configure Timer0 to be clocked by the crystal and Timer1 to be clocked by the PLL. Atmel has published some application notes regarding internal oscillator calibration. They would be a good help. After calibration you can output the following clocks with Timer1:
- 64MHz / 12 = 5.33MHz
- 64Mhz / 14 = 4.57MHz
- 64MHz / 16 = 4.00MHz
...
- 64MHz / 32 = 2.00MHz

So you can adjust the frequency in 11 steps.

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S-Sohn wrote:
You could use an ATtiny25 for this purpose. Timer1 of this device can be clocked by a 64MHz signal. The 64MHz (PLL) clock is the multiplied frequency of the internal 8MHz oscillator. This oscillator can be calibrated. You can gain 1% clock accuracy. Connect a crystal to the ATtiny25. To do calibration configure Timer0 to be clocked by the crystal and Timer1 to be clocked by the PLL. Atmel has published some application notes regarding internal oscillator calibration. They would be a good help. After calibration you can output the following clocks with Timer1:
- 64MHz / 12 = 5.33MHz
- 64Mhz / 14 = 4.57MHz
- 64MHz / 16 = 4.00MHz
...
- 64MHz / 32 = 2.00MHz

So you can adjust the frequency in 11 steps.

Regards
Sebastian

Thanks Sebastian, But unfortunately I don't have access to ATtiny25! :( I couldn't find it in the market. but ATtiny26 is available here. Can I do the same process with this one? (I guess I can, regarding to tiny26 datasheet, am I right?)

BTW, may I ask for the code of doing this??
any typical code for generating a clock pulse using the AVR (in MHz range) would be helpful.

Many thanks in advance,
Arvin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, ATtiny26 or ATtiny261 should be OK.

If you need need +/- 1% frequency accuracy you should take a look a the application note
"AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC"
The calibration should be done similar as discribed in the application note with the exception that you don't have a 32kHz crystal connected to your AVR but a standard crystal (4MHz, 8MHz, ...). But if you don't need this accuracy, you might cancel calibration.

For initializing the high speed timer I recommend you take a look at the application note
"AVR131: Using the AVR’s High-speed PWM".

Both application notes plus example code is available here.

What experiences do you have in programming AVRs?
Do you already have an AVR IDE?

Regards
Sebastian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well I have so little experience in programming AVRs. that's why I asked for a code which practically shows how to use the high-speed timer to generate high frequency digital signals to clock the other digital parts in the application.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The easiest way to generate those pulses might be to use a CPLD and do it in hardware. The Altera EPM7032B comes in a 44 pin package and has 600 gates, which is more than enough.

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

leon_heller wrote:
The easiest way to generate those pulses might be to use a CPLD and do it in hardware. The Altera EPM7032B comes in a 44 pin package and has 600 gates, which is more than enough.

Oh :shock: this is completely new to me! I've never worked with CPLD's before... are you sure this would be the easiest way??!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CPLD:If you already knew how to use them, I'd say yes. Otherwise i'll say the difficulty lies in learning how to apply a CPLD, not in using it. It'd go something like this (no syntax check applied, 'kiss', VHDL):

signal quad:STD_LOGIC_VECTOR(3 downto 0);
bitwalker: process(clk)
  if RISING_EDGE(clk) then
    if quad(2 downto 0)="000" then
      quad <= quad(2 downto 0)&'1'; --insert new 1 bit
    else
      quad <= quad(2 downto 0)&'0';    
    end if;
  end if;
end process; 
-- should do about 200MHz in coolrunner?
--should synthesize to 4 FFs and 4 PTs.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To me it sounds like even such a small CPLD with 44 pins and 600 gates is an overkill for this task. However, I have never used one.

By the way, what is the approximate cost of such device and do you need an external configuration memory as with many FPGAs?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tuomas wrote:
To me it sounds like even such a small CPLD with 44 pins and 600 gates is an overkill for this task. However, I have never used one.

Yes, but in a real system there's a very large chance that there are other logic tasks that could also be taken care of by the same device.

Quote:
By the way, what is the approximate cost of such device and do you need an external configuration memory as with many FPGAs?

The most inexpensive CPLD I know of (not that I've looked too hard) is the Xilinx XC9536XL, which runs about a dollar. And they are FLASH devices.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks to you all...
I'm still looking forward for a code which makes the AVR generate a clock pulse of 2-5 MHz :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The AVR probably can't manage it, doing it in hardware is the best way.

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

leon_heller wrote:
The AVR probably can't manage it, doing it in hardware is the best way.

Are you sure about it? Regarding to this document (alternative usage, page 3) I guess it's possible to do such thing.

cheers,
Arvin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not try it? I doubt if it will do what you want, though.

Leon

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know how to code it!! :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Duh--since we are grabbing whatever resources are needed, of COURSE one could meet that timing exactly with an AVR--but it would take the whole AVR.

Let's use our Tiny25 again, and run it at a sedate 8MHz to make typing easier. We'll say that we'll save PB2 for INT0 for On/Off control, and PB0-PB1-PB3-PB4 are our outputs.

; FOR 8MHZ, 125NS PER CLOCK, FOUR CLOCKS PER PHASE
	LDI	R16, 0x1b
	OUT	DDRB, R16	; PB0,1,3,4 as  outputs
; do further setup for PB2 On/Off control via INT0 ISR.

; SET THE PATTERNS FOR THE FOUR PHASES
	LDI	R16, 0X01
	LDI	R17, 0X02
	LDI	R18, 0X08
	LDI	R19, 0X10
...
THE_LOOP:
	OUT	PORTB, R16
	NOP
	NOP
	NOP
	OUT	PORTB, R17
	NOP
	NOP
	NOP
	OUT	PORTB, R18
	NOP
	NOP
	NOP
	OUT	PORTB, R19
	NOP
	RJMP	THE_LOOP
...

That can be the whole program, I think, if you don't need on/off control and the 8MHz internal oscillator is close enough. With a crystal you kinda run out of pins. No real problem for a one-off; instead of a US$1.00 Tiny25 use $1.25 Tiny2313 or $1.50 Mega48.

Lee

Dear Lee, would you tell me what changes I should make in this code, in order to use it in ATmega16? I sent this code to my ATmega16 chip but I could detect no outputs at portB pins!!

yours,
Arvin

Last Edited: Mon. Mar 10, 2008 - 01:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

arvinik wrote:
I don't know how to code it!! :(
Can you specify "I don't know"?
- lack of AVR experience
- lack of microcontroller experience
- lack of C experience
...

Regards
Sebastian

Pages