View previous topic :: View next topic |
Author |
Message |
shalfani Guest
|
PWM simulation with Proteus |
Posted: Mon Nov 30, 2009 6:49 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
shalfani Guest
|
|
Posted: Mon Nov 30, 2009 7:16 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Dec 01, 2009 9:52 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
shalfani Guest
|
|
Posted: Tue Dec 01, 2009 10:48 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Tue Dec 01, 2009 10:57 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
shalfani Guest
|
|
Posted: Tue Dec 01, 2009 11:07 am |
|
|
Thank, i will try that eventually, after i'll give up on proteus. |
|
![](templates/subSilver/images/spacer.gif) |
ahmadkamalnasir
Joined: 24 Nov 2009 Posts: 5
|
|
Posted: Tue Dec 01, 2009 2:37 pm |
|
|
Try using the Proteus 7.4 SP3. It will work for sure believe me or not ![Wink](images/smiles/icon_wink.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|