CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PWM simulation with Proteus

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
shalfani
Guest







PWM simulation with Proteus
PostPosted: Mon Nov 30, 2009 6:49 pm     Reply with quote

Hi,

I’m new to the world of MCUs and to this forum so I’m sorry ahead for any silly mistakes I make, please be gentle with me.

I’m trying to use PIC16F88 to convert analog data from 2 channels, manipulate it and generate PWM signal through RB3/CCP1.

I’m using CCSC 4.093 and PROTEUS ISIS 7.5 SP3 as simulator.

I managed to use the ADC and to manipulate the data but I’m stuck with the PWM output. It just won’t produce the signal. I tried to follow the strait forward examples on CCSC help file and it still didn’t work.

It seems that the problem is with the set_pwm1_duty() function or the setup_timer_2() function. When I write set_pwm1_duty() before setup_timer_2(), it works and I get PWM signal, but when I switch places between them (as the example in CCSC help files) it doesn’t work. I tried to debug it and it seems that the value in CCPR1L does not move into CCPR1H when TM2 equals PR2. By the way now I tried to debug it using MPLAB SIM and it work fine!! But it won’t work with ISIS. Any suggestions?

This is just an example of the code that doesn’t work (if I move the set_pwm_duty() before the setup_timer_2() it works fine):
Code:

#include <16F88.h>
#include <math.h>
#fuses HS,NOWDT,CCPB3
#use delay(clock=20000000)
#use fast_io (A)
#use fast_io (B)

void main()
{
int i=0b00111111;
Set_tris_a(0xff);
Output_b(0);
Set_tris_b(0);

//**** PWM Init****//

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,0b11111111, 1);

//****************//

While( True )
{
delay_us(100);
i+=1;
set_pwm1_duty(i);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 30, 2009 6:55 pm     Reply with quote

See this post for a PWM example program for the 16F88:
http://www.ccsinfo.com/forum/viewtopic.php?t=35191&start=3
shalfani
Guest







PostPosted: Mon Nov 30, 2009 7:16 pm     Reply with quote

Thanks PCM programmer for the fast response.

I looked at the link and that is exactly what I need.

I tried to run the code at the link and it still doesn't work. Maybe I'm not configuring Proteus right?! Can anyone run the code on his system and tell me if it works?

Thanks!!
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 01, 2009 9:52 am     Reply with quote

The problem is nobody here has Proteus here so they can't really help you. PWM is very easy to check. You can search this forum for some sample, compilable code and then check your output at the PWM pin using a scope.
shalfani
Guest







PostPosted: Tue Dec 01, 2009 10:48 am     Reply with quote

mkuang, thanks for the reply. I don't have access to a scope right now, that is why I'm trying to simulate it with Proteus.

I tried to simulate with some othe sofware and it works fine, so the problem is with Proteus. For some reason it gives me a message that CCP1 is Disabled. I will try to post on the Proteus Forum for answers.

Thank for all the help.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 01, 2009 10:57 am     Reply with quote

If you don't have a scope you can lowpass filter the output signal (something like a 10k resistor and a 2uF cap will do nicely) and check it with a voltmeter. You won't be able to see the period but you can see the duty cycle as a fraction of your supply voltage.
shalfani
Guest







PostPosted: Tue Dec 01, 2009 11:07 am     Reply with quote

Thank, i will try that eventually, after i'll give up on proteus.
ahmadkamalnasir



Joined: 24 Nov 2009
Posts: 5

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 01, 2009 2:37 pm     Reply with quote

Try using the Proteus 7.4 SP3. It will work for sure believe me or not Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group