Proteus Oscilloscope + PIC16F877A PWM

Thread Starter

ActivePower

Joined Mar 15, 2012
155
I have implemented a basic PWM based LED dimmer with my PIC16F877A processor. The circuit worked fine in both MPLAB SIM as well as hardware and I was able to get the desired output.

However, the scope in Proteus ISIS fails to display the PWM signal. I was even not able to get any change of state on the RC2 (CCP1) port pin whose state is a Weak Low (WLO).

Is there any configuration in ISIS I may have messed up?

Thanks!
 

Thread Starter

ActivePower

Joined Mar 15, 2012
155
I forgot to mention I am using Proteus v7.1. I have tried searching unsuccessfully on Google and even playing around with the step timing configurations in ISIS but to no avail. I'll keep trying to get it working though.

Any help is appreciated.

Thanks! :)
 

Thread Starter

ActivePower

Joined Mar 15, 2012
155
I have tested the code in MPLAB SIM as well as hardware (in a LED dimmer circuit) and there doesn't seem to be much of a problem with it. I'll double-check it though, just to be sure.
 

Thread Starter

ActivePower

Joined Mar 15, 2012
155
The problem seems to be a little worse than I thought. Even the previous versions of the code are not compiling correctly in MPLAB now. Don't know how this came about :( Here's the build report
Rich (BB code):
Clean: Deleting intermediary and output files.
Clean Warning: File "E:\My Files\Source Codes\Embedded\Basic PWM\main.obj" doesn't exist.
Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.sdb".
Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.rlf".
Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.lst".
Clean: Done.
Build E:\My Files\Source Codes\Embedded\Basic PWM\pwm for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\lite\9.60\bin\picc.exe

Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\lite\9.60\bin\picc.exe" -C "E:\My Files\Source Codes\Embedded\Basic PWM\main.c" -q --chip=16F877A -P --runtime=default,+clear,+init,-keep,+osccal,-resetbits,+clib --opt=default,+asm,-debug,-speed,+space,9 --warn=0 -D__DEBUG=1 --rom=default --ram=default --double=24 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Warning [361] E:\My Files\Source Codes\Embedded\Basic PWM\main.c; 27.1 function declared implicit int
Error   [800] ; 0. undefined symbol "BOREN_OFF"
Error   [800] ; 0. undefined symbol "PWRTE_OFF"
Error   [800] ; 0. undefined symbol "CP_OFF"
Error   [800] ; 0. undefined symbol "CPD_OFF"
Error   [800] ; 0. undefined symbol "LVP_OFF"
Error   [800] ; 0. undefined symbol "DEBUG_ON"
Error   [800] ; 0. undefined symbol "WDTE_OFF"
Error   [800] ; 0. undefined symbol "FOSC_HS"

********** Build failed! **********
This exact same code worked perfectly a week ago and I haven't touched it since. I am using MPLAB v8.73 and HiTech v9.60. How can things go this wrong suddenly? Any ideas?
 

Thread Starter

ActivePower

Joined Mar 15, 2012
155
Sorted out the compiler issue. I still have no clue where that popped up from. Anyway, I tried the LED blink waveform with the scope and it shows a square wave as expected. What is the trouble with the PWM signal, I wonder :confused:
 

absf

Joined Dec 29, 2010
1,968
Rich (BB code):
//main.c
//To use PWM for dimming an LED
//PWM Frequency: 1.22 kHz
//CCP1 Register Pin=RC2

#include<htc.h>
#define _XTAL_FREQ 20000000

__CONFIG(FOSC_HS & WDTE_OFF & DEBUG_ON & LVP_OFF & CPD_OFF & CP_OFF & PWRTE_OFF & BOREN_OFF);

void main()
{
	unsigned int duty;		//16 bit value
	TRISC=0;			//set PORTC to output
	PORTC=0;			//set PORTC low
	PR2=255;				//set TMR2 period register
	T2CON=0b00000101;		//set postscaler to 1:1; prescaler to 16
	CCP1CON=0b00001111;		//set the 2 LSB of duty cycle to 0 and initialize CCP module as PWM
	duty=0;
	while(1)
	{			
			while(duty<255)			//increase duty cycle from 0% to 100%
			{
				CCPR1L=duty;
				duty=duty+1;
				__delay_ms(2);

			}
            while(duty>0)
            {
                CCPR1L=duty;
				 duty--;
				__delay_ms(2);
            }
	}	
}
I just changed "CCP1CON=0b00001111;" to "CCP1CON=0b00001100;" and it worked on my proteus. I was unable to open your proteus files as I am having a different version from yours.

Though it doesnt make a reasonable sense, I guess the 877a device file in proteus might have some problem...

Allen
 

Attachments

Last edited:
Top