Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
haseeb_00001
PostPosted: Feb 20, 2011 - 02:51 PM
Newbie


Joined: Jul 29, 2010
Posts: 13
Location: Pakistan

Hi,

I want to generate PWM using Timer1
Crystal oscillator= 8MHz
Timer1 Prescale=8

so one timer tick is of 1us.

for 2ms high pulse, 2ms/1us= 2000
so S1=65535-2000=63535

for 18ms low pulse, 18ms/1us=18000
so prescale= 65535-18000=47535


By using S1, and prescale value, i wrote the code. When i check the simulation on ISIS protesus, i m getting 8 times high and low pulse.
Can anybody help?

the code is

Code:


$regfile = "m16def.dat"
$crystal = 8000000

Config Timer1 = Timer , Prescale = 8

On Timer1 Servoirq

Config Portd.0 = Output
Portd.0 = 0


Dim Preload As Word


Dim S1 As Word
Dim I As Byte


  Preload = 63285
   S1 = 47535


Enable Timer1                                               'required in any case
Enable Interrupts                                           'required in any case

Do

Loop
End


Servoirq:
If Portd.0 = 0 Then
  Timer1 = S1
  Portd.0 = 1
Else
  Portd.0 = 0
  Timer1 = Preload
End If
Return
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Feb 20, 2011 - 02:59 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71163
Location: (using avr-gcc in) Finchingfield, Essex, England

A mega16 by default clocks at 1MHz. Presumably there's a setting in Proteus where you tell it that the chip is actually running at 8MHz? Have you changed this option?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
haseeb_00001
PostPosted: Feb 20, 2011 - 03:33 PM
Newbie


Joined: Jul 29, 2010
Posts: 13
Location: Pakistan

hmmm. I was thinking that statement $crystal = 8000000 will do this job, but i was wrong.
In proteus, when i set CKSEL Fuses to Int. RC[8MHz]. i get right 2ms and 18ms pulses.

Thanks
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Koshchi
PostPosted: Feb 20, 2011 - 06:50 PM
10k+ Postman


Joined: Nov 17, 2004
Posts: 15004
Location: Vancouver, BC

Quote:
I want to generate PWM using Timer1
Then why not use PWM mode?

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: Feb 20, 2011 - 06:59 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 21992
Location: Lund, Sweden

Quote:

hmmm. I was thinking that statement $crystal = 8000000 will do this job, but i was wrong.

It is common that you need to have one setting telling your tool chain (compiler, assemblerm whatever..) the CPU speed so that it can generate correct code (e.g. calculating correct UBBRnx values for USART baud rates), AND one setting to tell the actual system what clock it should use. For the latter there is e.g. a setting in AVR Simulator, on real chips it is determined in part by fuses etc...
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: Feb 20, 2011 - 07:18 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 71163
Location: (using avr-gcc in) Finchingfield, Essex, England

Warning: In another thread OP has already admitted to using a stolen copy of Bascom so it seems likely the Proteus is also stolen. As such I'll leave it for you to decide if you still want to provide support in this thread.

Moderator.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits