Do you wanna mess with me?
Entire Forum
This board
This topic
Members
Entire Site
Home
Contact Us
Help
Search
GoogleTagged
Donations
Login
Register
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 23, 2024, 04:04:14 04:04
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Sonsivri
>
Electronics
>
Projects
(Moderators:
bbarney
,
pickit2
) >
Software PWM
Pages: [
1
]
« previous
next »
Print
Author
Topic: Software PWM (Read 4019 times)
0 Members and 1 Guest are viewing this topic.
king
Junior Member
Offline
Posts: 84
Thank You
-Given: 2
-Receive: 21
Jack of All But Master of One
Software PWM
«
on:
July 13, 2009, 10:09:14 10:09 »
Hi!
I have written the code for software PWM whose PWM frequency is 20KHz
Method:
1) Generate HPWM1 and HPWM2 of 20KHz frequency using HPWM command
2) wait for TMR2 to PR2 match interrupt Flag
3) when this flag=1 then high PWM3 port pin and start timer1 whose max delay is 50usec (20KHz)
but for 50% Duty Cycle I have reduce Timer1 delay to 25Usec by setting its TMR1H and TMR1L variables
and jump to Step '1'
When Timer1 OV interrupt generated then i have low PWM3 Port Pin so its frequency is equal to 20Khz but i have received 0.146V on PWM3 port pin instead of 2.5V and it is not working correctly , i have also attached the code if anybody find the mistake then it will be highly appreciated
Logged
Wizpic
Global Moderator
Hero Member
Offline
Posts: 1203
Thank You
-Given: 553
-Receive: 409
Re: Software PWM
«
Reply #1 on:
July 13, 2009, 06:24:28 18:24 »
I've had a quick look at your code and can see a few error's, I shall a more indpeth look later and upload some code that shoudl do it
wizpic
Logged
When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
TomJackson69
Active Member
Offline
Posts: 218
Thank You
-Given: 26
-Receive: 63
Re: Software PWM
«
Reply #2 on:
July 14, 2009, 12:28:35 00:28 »
Hi king,
I don't have Basic Compiler install in my computer so I can not compile your program. But I see one could be mistake in your program.
In the data sheet it said:
"The prescaler counter is cleared on writes to the TMR1H or TMR1L registers".
It could be true because your duty cycle now is only 12.4uS instead of 49.6uS. Which mean the LED on time is 1/4 of what you have planned.
So in your TMR1_ISR, after you write new value into timer1, set bits for prescale too.
TMR1_ISR:
LOW PWM3
LOW led
timer1=65473 '(50% DUTY CYCLE of 50US=25usec)
T1CKPS0=1 ' set prescale bits for 1:4
T1CKPS1=0 ' set prescale bits
FTMR1=0
CONTEXT RESTORE
Also, in the data sheet said:
"For writes, it is recommended that the user simply stop
the timer and write the desired values. A write contention
may occur by writing to the timer registers, while
the register is incrementing. This may produce an
unpredictable value in the timer register". I doubt it would help???
In this line:
SYMBOL FTMR1 = PIr1.0 ' TIMER1 OVERFLOW FLAG
Is PIr ok with your compiler? I don't know if its case sensitive.
Tom
Logged
Con Rong Chau Tien
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Electronics
-----------------------------
=> Projects
=> Pic Basic Languages
=> Pic C Languages
=> AVR, 8051 Family and ARM Area
=> RTOS
=> Artificial Intelligence (AI) & Robotics
=> Hardware and Tools
=> General Electronics
-----------------------------
Computers
-----------------------------
=> Internet Scripting Languages
=> Graphics and CAD
-----------------------------
Announcements and Rules
-----------------------------
=> Help & Rules
===> English
===> Arabic
===> French
===> Italian
===> Persian
===> Portuguese (Brazilian)
===> Spanish
===> Swedish
===> Turkish
=> Announcements
-----------------------------
Others
-----------------------------
=> General
=> Entertainment
=> Suggest Forum Content
=> Holiday and Greetings
=> Testing Forum
=> Invitation Request
Loading...