View previous topic :: View next topic |
Author |
Message |
Debu
Joined: 06 Jan 2008 Posts: 21 Location: Dhaka
|
Posted: Sun Jun 01, 2014 11:01 am Post subject: Function generator Attiny13 |
|
|
Hi
Every one
I am trying to make a frequency generator with tiny13.
Now I can generate 9KHz to 520KHz by timer0 CTC mode.
Here is my question is it possible to generate 4MHz or 2MHz ?????
Here is my Code
Code: |
$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 16
$swstack = 16
$framesize = 16
dim friq_com as Byte
dim adc_value as Word
dim div_1 as Byte
'----------------------------------------------------------------------------
'Config Portb = Output
Config Timer0 = Timer , Prescale = 1 , Clear_timer = 1 , Compare_a = Toggle
CONFIG ADC = single, PRESCALER = AUTO, REFERENCE = INTERNAL
'-----------------------------------------------------------------------------
Do
Compare0a = friq_com
Toggle Portb.3
Waitms 10
adc_value = getadc(2)
friq_com=adc_value/4
Loop
End
'-----------------------------------------------------------------------------
|
(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.7.7 ) |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 586 Location: Cleveland, OH
|
Posted: Sun Jun 01, 2014 5:52 pm Post subject: |
|
|
I assume you have an External Crystal attached to your micro?
Have you changed the Fuses to switch the micro's clock source to use the External Crystal?
If not, the micro is still running on its internal RC oscillator, (at 1 MHz, or whatever the data sheet says it is).
Be careful in changing the Fuses.
An external crystal is a two lead device, and uses two external capacitors.
This is probably what you have.
An external oscillator is a small module, with its own V+ and Ground pins, and it outputs a square wave. This is probably NOT what you have.
JC |
|
Back to top |
|
|
Debu
Joined: 06 Jan 2008 Posts: 21 Location: Dhaka
|
Posted: Sun Jun 01, 2014 6:47 pm Post subject: |
|
|
Thank you
JC
for your replay.
I don't connect external x-tal.
I use internal 9.6MHz rc by fuse H(FF) L(6A).
I think it have another way to generate high frequency by config Timer0.
Thanks again. |
|
Back to top |
|
|
for_ro
Joined: 11 Nov 2007 Posts: 260
|
Posted: Sun Jun 01, 2014 7:38 pm Post subject: Re: Function generator Attiny13 |
|
|
Debu wrote: | adc_value = getadc(2)
friq_com=adc_value/4 |
Hi Debu,
this will not do what you want, as friq_com will only get values from 0 .. 63
This would do:
adc_value = getadc(2) / 4
friq_com=adc_value
With COMPARE0A = 0 you will get a frequency of _XTAL/2, whatever _XTAL the µc is really running on. |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Mon Jun 02, 2014 7:29 am Post subject: |
|
|
Quote: | is it possible to generate 4MHz or 2MHz ????? |
With CTC you can get only frequencies
$crystal / 2
$crystal / 4
$crystal / 6
$crystal / 8
and so on |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Jun 02, 2014 8:31 am Post subject: |
|
|
Visovian wrote: | With CTC you can get only frequencies
$crystal / 2
$crystal / 4
$crystal / 6
$crystal / 8
and so on |
Using OSCCAL you get some of the in-betweens. No guarantee of course, as this is heavily detuning of the internal RC out of specs.
But for hobby-use - who cares? |
|
Back to top |
|
|
Debu
Joined: 06 Jan 2008 Posts: 21 Location: Dhaka
|
Posted: Mon Jun 02, 2014 9:30 am Post subject: Re: Function generator Attiny13 |
|
|
for_ro wrote: | Debu wrote: | adc_value = getadc(2)
friq_com=adc_value/4 |
Hi Debu,
this will not do what you want, as friq_com will only get values from 0 .. 63
This would do:
adc_value = getadc(2) / 4
friq_com=adc_value
With COMPARE0A = 0 you will get a frequency of _XTAL/2, whatever _XTAL the µc is really running on. |
Thank you
FOR_RO
for your replay
Now I get to 2.33KHz to 592.24KHz |
|
Back to top |
|
|
Debu
Joined: 06 Jan 2008 Posts: 21 Location: Dhaka
|
Posted: Mon Jun 02, 2014 10:59 am Post subject: |
|
|
Hurray
Thanks to all
Now it is run 18.5KHz to 4.76MHz by fuse sating CKDIV8.
But, suddenly it jump 800KHz to 1.20MHz to 2.42MHz to 4.80MHz.
18KHz to 800KHz work linearly.
Workable but not perfect yet. |
|
Back to top |
|
|
|