Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Function generator Attiny13

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Debu

Bascom Member



Joined: 06 Jan 2008
Posts: 21
Location: Dhaka

bangladesh.gif
PostPosted: Sun Jun 01, 2014 11:01 am    Post subject: Function generator Attiny13 Reply with quote

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
View user's profile AIM Address Yahoo Messenger MSN Messenger
JC

Bascom Member



Joined: 15 Dec 2007
Posts: 586
Location: Cleveland, OH

usa.gif
PostPosted: Sun Jun 01, 2014 5:52 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Debu

Bascom Member



Joined: 06 Jan 2008
Posts: 21
Location: Dhaka

bangladesh.gif
PostPosted: Sun Jun 01, 2014 6:47 pm    Post subject: Reply with quote

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
View user's profile AIM Address Yahoo Messenger MSN Messenger
for_ro

Bascom Member



Joined: 11 Nov 2007
Posts: 260

germany.gif
PostPosted: Sun Jun 01, 2014 7:38 pm    Post subject: Re: Function generator Attiny13 Reply with quote

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
View user's profile
Visovian

Bascom Member



Joined: 31 Oct 2007
Posts: 584
Location: Czech

czechrepublic.gif
PostPosted: Mon Jun 02, 2014 7:29 am    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Jun 02, 2014 8:31 am    Post subject: Reply with quote

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? Very Happy
Back to top
View user's profile
Debu

Bascom Member



Joined: 06 Jan 2008
Posts: 21
Location: Dhaka

bangladesh.gif
PostPosted: Mon Jun 02, 2014 9:30 am    Post subject: Re: Function generator Attiny13 Reply with quote

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
View user's profile AIM Address Yahoo Messenger MSN Messenger
Debu

Bascom Member



Joined: 06 Jan 2008
Posts: 21
Location: Dhaka

bangladesh.gif
PostPosted: Mon Jun 02, 2014 10:59 am    Post subject: Reply with quote

Hurray

Laughing

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
View user's profile AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum