Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Pwm on tiny13

 
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
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Sun Jul 13, 2014 8:48 pm    Post subject: Pwm on tiny13 Reply with quote

Hi
I want to generate 20khz of pwm on the pwm outputs of tiny but with a 10ms gape between the two signals, Is it possible with interrupt or the only option is WAITMS command.


$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 16
$swstack = 16
$framesize = 16



'----------------------------------------------------------------------------
Config Portb = Output

Config Timer0 = Timer , Prescale = 1 , Clear_timer = 1 , Compare_a = Toggle , Compare_b = Toggle

Config Adc = Single , Prescaler = Auto , Reference = Internal

'-----------------------------------------------------------------------------
Do

Compare0a = 64
Compare0b = 0

Waitms 10

Compare0b = 64





Loop

End

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

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Mon Jul 14, 2014 10:15 pm    Post subject: Reply with quote

$regfile = "attiny13.dat"
$crystal = 9600000
$hwstack = 16
$swstack = 16
$framesize = 16


Config Portb = Output

Config Timer0 = Pwm , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down



Do

Gosub Halfcycle_1



Loop
End

Halfcycle_1:
Pwm0b = 0

Pwm0a = 128
Waitms 1
Pwm0a = 202
Waitms 1
Pwm0a = 249
Waitms 1
Pwm0a = 249
Waitms 1
Pwm0a = 202
Waitms 1
Pwm0a = 128
Waitms 1
Pwm0a = 53
Waitms 1
Pwm0a = 6
Waitms 1
Pwm0a = 6
Waitms 1
Pwm0a = 53
Waitms 1
Pwm0a = 128
Gosub Halfcycle_2
Return

Halfcycle_2:
Pwm0a = 0

Pwm0b = 128
Waitms 1
Pwm0b = 202
Waitms 1
Pwm0b = 249
Waitms 1
Pwm0b = 249
Waitms 1
Pwm0b = 202
Waitms 1
Pwm0b = 128
Waitms 1
Pwm0b = 53
Waitms 1
Pwm0b = 6
Waitms 1
Pwm0b = 6
Waitms 1
Pwm0b = 53
Waitms 1
Pwm0b = 128
Return

This is my new code with 10 element table as tiny13 has no other timer to interrupt and pick a value from the table this is why I am doing it with waitms command dividing the 10ms time for each half cycle equally in 10 segments. but I am not getting sine wave on my Proteus Oscilloscope I suspect I am missing a suitable filter on the out put but then what should be the values of filter elements to filter out the unwanted harmonics.
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Tue Jul 15, 2014 12:52 am    Post subject: Reply with quote

hi
you can try with rc filter Res 10K and cap 0.1uF on both pwm output
use channel A and B in proteus
on A channel select A+B then you see if its more like sinus

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
naseerak

Bascom Member



Joined: 08 Nov 2008
Posts: 138

pakistan.gif
PostPosted: Tue Jul 15, 2014 9:12 pm    Post subject: Reply with quote

Yes it worked!
BTW is there any better way of generating spwm on Tiny13?
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