Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ATMega 168 Fast PWM with Timer 2

 
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
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 64
Location: Aachen

germany.gif
PostPosted: Thu May 01, 2014 1:36 pm    Post subject: ATMega 168 Fast PWM with Timer 2 Reply with quote

Dear All,
I cannot explain why my circuit does not work.
I want to use Timer 2 to generate a refernce voltage to control the dutycycle of a stepper motor.
The C is PDIP casing. OC2A is on pin 17.
Pin is connected to a 150 kOhm + 15 kOhm + 10 F RC combination. So the current is small.
By setting OCR2A =100 I expect appr. 2.2 V at pin 17. I measure 0V ( digital multimeter).
Even on the RC combination voltage is 0 V.

The buzzer's beeping shows that the program is running.

Do you have an idea why it does not work ?

Please see the attached program. I included also the description of the TCCR registers.

best regards

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 269
Location: McMinnville, OR

usa.gif
PostPosted: Thu May 01, 2014 3:00 pm    Post subject: Reply with quote

You don't have a clk source selected in TCCR2B= &B00000000

Bits 0,1 & 2 are the clk select bits. Zero stops the timer.
Back to top
View user's profile
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 64
Location: Aachen

germany.gif
PostPosted: Thu May 01, 2014 4:37 pm    Post subject: Reply with quote

Hi Dave,

many thanks for the useful advice.

I changed the registers now to:

TCCR2A= &B10000011 ' Fast PWM, 1 0 Clear OC2A on Compare Match, set OC2A at BOTTOM
'
TCCR2B= &B00000001 ' No prescaling

OCR2a=128

Now the multimeter shows a voltage of nearly 5 V at the OC2A pin.
I expect 2.5 V with the OCR2A = 128 setting.

It seems that the value of the OCR2A register = 50 is some kind of threshold.
With OCR2A = 50 or less the voltage on the pin is 0V.
With OCR2A = 51 or higher the voltage on the pin is 5V.

This is strange to me.

Are there some other registers that have to be modified ?


best regards

Christian


Last edited by autoguider on Thu May 01, 2014 5:04 pm; edited 1 time in total
Back to top
View user's profile
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 269
Location: McMinnville, OR

usa.gif
PostPosted: Thu May 01, 2014 4:57 pm    Post subject: Reply with quote

Hi Christian,

Remove "Start Timer2".

See help:" The START TIMER statement will only work correctly when you have selected a clock source or pre-scaler value with the CONFIG TIMER statement."

Dave
Back to top
View user's profile
autoguider

Bascom Member



Joined: 24 Sep 2007
Posts: 64
Location: Aachen

germany.gif
PostPosted: Thu May 01, 2014 5:20 pm    Post subject: Reply with quote

Dear dave,
now it works.

This is my short program for testing.

dim j as integer


Config PORTC.3 = Output ' For Buzzer
Config Portb.3 = Output ' Output OC2A


TCCR2A= &B10000011 ' Fast PWM, 1 0 Clear OC2A on Compare Match, set OC2A at BOTTOM
'
TCCR2B= &B00000001 ' No prescaling

OCR2a=10 'Initial value



Portc.3=1 ' Initial loud beep
wait 1
portc.3=0



do
portc.3=1 'acoustic signal indicating program running
waitms 4
portc.3=0

j= ocr2a
J=j +10
if j >254 then J=1
ocr2A =j
wait 5
loop

many thanks and best regards

Christian
Back to top
View user's profile
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