Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Very simple frequency generator

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Wed Sep 09, 2020 3:33 pm    Post subject: Very simple frequency generator Reply with quote

Hello,

I found very simple frequency generator on Timer1 published by Arek2014 in "Share your working BASCOM-AVR code here" section.
What about Timer2?
Can we do similar thing using Timer2?
Timer1 is 16-bit and Timer2 is 8-bit so I would expect change in frequency range and resolution, this is not a problem.

Original code of Arek2014:

Code:

$crystal = 8000000
Config Timer1 = Timer , Prescale = 1 ,clear timer = 1, Compare_a = Toggle    'generator frequency!!! OC1A
'Ocr1a = 500
dim freq as word
dim f as dword
Enable Interrupts
enable timer1

do
f = 4000000 / freq  'f crystal / 2 !!!
print f ; "Hz"
Ocr1a = freq    'changing dim freq --> change frequency
loop


My Code that generates frequency about 28kHz on OC2A output:

Code:
Config Timer2 = Timer , Prescale = 256 , Compare A = Toggle , Clear Timer = 1       '(wyjscie OC2a)
Enable Timer2
Config Portb.4 = Output                                     'OC2a Generator


But when I want to modify the frequency by OCR2A it stops working.

Code:
Config Timer2 = Timer , Prescale = 256 , Compare A = Toggle , Clear Timer = 1       '(wyjscie OC2a)
Enable Timer2
Config Portb.4 = Output                                     'OC2a Generator
Ocr2a = 100


Why?

(BASCOM-AVR version : 2.0.8.3 )


Last edited by Pzx on Wed Sep 09, 2020 7:50 pm; edited 9 times in total
Back to top
View user's profile
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Wed Sep 09, 2020 4:48 pm    Post subject: Reply with quote

Ok, after some time I found that my second code also works.
The frequency is much lower so I could not see it on my oscyloscope with the same presets Smile
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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