|
|
View previous topic :: View next topic |
Author |
Message |
small_chick
Joined: 17 Jul 2012 Posts: 53
|
PWM Proteus VSM result is different from Calculation??? |
Posted: Wed Jul 18, 2012 10:16 am |
|
|
After I had programmed code for PWM, I checked the Proteus VSM result by VSM Oscilloscope. I realised that when I changed the value ( some values for instances: 100, 200, 250) assigned for instruction "set_pwm1_duty(value);" , the duty cycle didn't change as I had expected.
I've wondered if there are any problems with VSM Oscilloscope or I've misunderstood.
Please help me!!! thanks!
You can download my Proteus VSM file here:
http://www.mediafire.com/?d9xzi4z3b8yqlei
This is my code:
Code: |
//*************************************
#include "16F887.h"
//**********************************
void ports_init()
{
//configure port_b
//set_tris_b(0x00);
output_b(0x00);
//configure port_d
//set_tris_d(0x00);
output_d(0x00);
}
//***************************************
void timers_init()
{
//initialize timer2
setup_timer_2(T2_DIV_BY_16,248,1);
set_timer2(0);
}
//***************************************
void main()
{
ports_init();
timers_init();
setup_ccp1(CCP_PWM);
set_pwm1_duty(250);
while(1);
}
//**************************************
//the end!
//************************************* |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed Jul 18, 2012 10:52 am |
|
|
First you should understand that Proteus is a very,very poor 'simulator' which is full bugs and errors and NOT a good program.
Second, the code you show is not complete,lacking 'fuses', xtal setup, etc. so we can't copy/paste/compile and test.
Third, I suggest another reading of the PWM module of the PIC as well as the CCS code examples( in the 'examples' folder). Sometimes it helps to look at their code to see how it works. |
|
|
small_chick
Joined: 17 Jul 2012 Posts: 53
|
|
Posted: Wed Jul 18, 2012 8:43 pm |
|
|
I'd like to discuss 3 problems you've recommended!
1/-First problem: Could you recommend a better stimulation way for test to me ?
2/-Second problem: I use MPLAB integrated with CCS compiler. Athough I don't use pre-processor directive #FUSES, it stll works well. In stimulation file, the frequency of PIC is 4MHz. Hope you can check again!!!
3/-Third problem: I'll try it!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Jul 19, 2012 5:23 am |
|
|
1) Sorry,but there isn't any simulator that I will recommend.While I've only got 2 decades of playing with PICs and another 2 decades with other micros,NO simulator has actually simulated the real world.Some here say MPLABs simulator is good, though my 'simulator' has always been the real world.Actual chips,wired up, tested on the bench,in the field or in the shop.I've yet to see any simulator add random EMI,welder noise,brownouts,etc. and most don't check the simple details, like proper crystal connections, correct VDD,VSS,pinouts, etc. PICs and parts are cheap these days.Heck my first 'personal computer' was $10,000 ,today I can buy one for $49 that is lightyears ahead of my first.I design with 3 PICs.1 for the actual code, the other 2 in test boards placed in the shop(which is 'noisey').It allows for real world evaluation of the product and is far cheaper than the lost R&D time due to a 'simulator' not working right( NONE do).
2) I also use MPLAB /CCS combo. However, I always include the 'fuses' in my program which overrides the MPLAB configuration.That way I have a record of the fuses within the program.The second line of code is really #include projectx_fuses.c.This file is the custom configuration of fuses for that project.The main project would be 'messy' with all the fuses listed,say for a 18F4550 or newer part, yet I can easily access or alter them as required.
3) All of the peripheral modules inside a PIC are complicated,some are easy to setup others can be a real head scratcher.While it's well known we need to add 'errors' to the USE RS232(...options) for the hardware UART, PWM config can be 'fun'.That's where the examples that CCS supplies are real handy! They've supplied documented, working code included in the compiler.Also check out the code library forum as well where others have uploaded their working code.
hth
jay |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Mon Jul 23, 2012 10:55 pm |
|
|
temtronic wrote: | First you should understand that Proteus is a very,very poor 'simulator' which is full bugs and errors and NOT a good program. |
You are so far up in your xss, we use Proteus for years with great result, just like anything else need proper coding careful planing and will provide great results !
So easy to jump the gun "full bugs and errors" like CCS does not have bugs and errors !?
as for small_chick, I don't know if you are using a demo, full or one of the hack-ware version floating in cyberspace, but I recommend you to learn more about Proteus before classify it useless.
justmy2cent
about your pwm problem, ahhh haven't even read you post fully good luck solving it.. _________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Jul 24, 2012 1:12 am |
|
|
Don't be rude.
Proteus, is a pretty foul simulator on the PIC. The company I was working for last year had used Proteus for several years, and paid for the top of the range set up. We showed to Labcentre, that three designs, which worked perfectly in hardware, would fail on their simulation, but conversely a number of designs that the simulator said should work, had glaring faults when put into hardware. There are _big_ holes in their design models.
They fixed these faults, and gave 'free' license extensions, but we have found so many more, that I have to agree with Temtronic here.
I have made the comment here in the past, that Proteus is about as bad as CCS....
Problem is worse though, because people are using Proteus as a design 'tool', and not understanding just how limited it is.
Better simulators?. As a pure simulator of the core of the processors, MPLAB wins. If you are looking for basic timing/logic faults. However the number of PIC's now is so high, and the number of hardware oddities on the chips so high, that realistically there is no substitute for the real chip.
In this case though, I doubt if Proteus is the problem.
I'd suggest looking at the manual carefully, and reading what happens if you give an _8bit_ value to 'set_pwm_duty' as opposed to a 16bit value, and how to change this (a search here will find this answered many times).
In C, what is the difference between '250', and '250L'.
Best Wishes |
|
|
|
|
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
|