Searching \ for 'Variable pulse generation reply' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=variable+pulse+generation
Search entire site for: 'Variable pulse generation reply'.

Truncated match.
PICList Thread
'Variable pulse generation reply'
1997\04\22@100042 by FrankT

picon face
Steve wrote

>Well the software shouldn't be all that complicated.  To get a precise
>50us output, you can code a software loop which runs while interrupts
>are disabled (e.g. in the interrupt handler itself).  Of course this
>depends on whether the rest of your application can tolerate this.  If
>you are using slave IIC at 100KHz, 50us should not cause you to lose
>any data, since a byte will take about 80us to receive.

I agree, but the frequency is selected by the I2C received data and with a
fixed pulse width I will have to do some extra calculations in order to
convert the recieved(wanted freq) in to the High and Low Timer value and I
gues you know that performing calculations isn't mplabc's strongest side.

>Compare mode allows timer1 to free-run as a divide-by-anything counter,
>so long as you set the flag which resets timer1 to zero when the compare
>'hits'.  If you set it up correctly, timer1 starts at zero and counts
>up at a rate set by the processor clock and a prescaler.  When it reaches
>the 16-bit value in ccpr1h/l, timer1 is automatically reset to zero and
>and interrupt will be triggered.

Does the value in CCPR1H/L need to be reloaded?

I also need to switch the pulse generation on and off via I2C, what do you
suggest is the most elegant way to this.
1.Stop TIMER1.
2.Disable the CCP1 interrupt.
3.Switch off capture mode (CCP1CON = 0x00)
4.Let everthing as it is but stop switching the PORT.

Regards,
Frank Temmerman
Belgium

1997\04\22@211430 by Steve Hardy

flavicon
face
> From: FrankT <spam_OUTgymnaTakeThisOuTspamCOMPUSERVE.COM>
> [cut]
> I agree, but the frequency is selected by the I2C received data and with a
> fixed pulse width I will have to do some extra calculations in order to
> convert the recieved(wanted freq) in to the High and Low Timer value and I
> gues you know that performing calculations isn't mplabc's strongest side.

Actually, I don't know since I use assembler.  OK, so you have to convert
a frequency command into a time period.  If possible, you could use the
smarts in the processor which sends the I2C command to do the calculation
and send a raw period value instead.  If this is impossible, you will need
to perform a long division in the code.  Suppose the command comes in as
a 16-bit frequency in Hz (say 1 to 10000).  You want to convert this to a
period count.  Assuming a period of 65536 generates 1Hz, then basically
you want to perform the division

 ccpr1(h,l) = 65536 / freq.

Since the dividend (65536) is constant, you can write a routine optimised
for this operation.

>
> >Compare mode allows timer1 to free-run as a divide-by-anything counter,
> >so long as you set the flag which resets timer1 to zero when the compare
> >'hits'.  If you set it up correctly, timer1 starts at zero and counts
> >up at a rate set by the processor clock and a prescaler.  When it reaches
> >the 16-bit value in ccpr1h/l, timer1 is automatically reset to zero and
> >and interrupt will be triggered.
>
> Does the value in CCPR1H/L need to be reloaded?

No.

>
> I also need to switch the pulse generation on and off via I2C, what do you
> suggest is the most elegant way to this.
> 1.Stop TIMER1.
> 2.Disable the CCP1 interrupt.
> 3.Switch off capture mode (CCP1CON = 0x00)
> 4.Let everthing as it is but stop switching the PORT.

I would probably use (4), since all you have to do is check a flag.  (2)
may be better if you want to waste the least number of processor cycles
in the 'off' state.  The most 'elegant' way depends on your application
requirements, as always

Regards,
SJH
Canberra, Australia

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...