Proteus Oscilloscope + PIC16F877A PWM

Discussion in 'Embedded Systems and Microcontrollers' started by ActivePower, Nov 13, 2012.

  1. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    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!
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Can you zip down your project and the compiled code you use in the PIC
     
  3. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    Sure. Here is the C code. I'll attach the ISIS schematic if needed too.

    Thanks!
     
    • PWM.zip
      File size:
      757 bytes
      Views:
      294
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Yes I will need the Ptroteus schematic. And the hex file you use for the PIC in proteus.
     
  5. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    Here's the schematic and the hex file along with the code.

    Thanks! :)
     
  6. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    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! :)
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I think your problem is the code. Go through the data sheet. And make sure every step in the checklist is ok.
     
  8. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    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.
     
  9. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
  10. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    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
    Code ( (Unknown Language)):
    1. Clean: Deleting intermediary and output files.
    2. Clean Warning: File "E:\My Files\Source Codes\Embedded\Basic PWM\main.obj" doesn't exist.
    3. Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.sdb".
    4. Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.rlf".
    5. Clean: Deleted file "E:\My Files\Source Codes\Embedded\Basic PWM\main.lst".
    6. Clean: Done.
    7. Build E:\My Files\Source Codes\Embedded\Basic PWM\pwm for device 16F877A
    8. Using driver C:\Program Files (x86)\HI-TECH Software\PICC\lite\9.60\bin\picc.exe
    9.  
    10. 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"
    11. Warning [361] E:\My Files\Source Codes\Embedded\Basic PWM\main.c; 27.1 function declared implicit int
    12. Error   [800] ; 0. undefined symbol "BOREN_OFF"
    13. Error   [800] ; 0. undefined symbol "PWRTE_OFF"
    14. Error   [800] ; 0. undefined symbol "CP_OFF"
    15. Error   [800] ; 0. undefined symbol "CPD_OFF"
    16. Error   [800] ; 0. undefined symbol "LVP_OFF"
    17. Error   [800] ; 0. undefined symbol "DEBUG_ON"
    18. Error   [800] ; 0. undefined symbol "WDTE_OFF"
    19. Error   [800] ; 0. undefined symbol "FOSC_HS"
    20.  
    21. ********** Build failed! **********
    22.  
    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?
     
  11. ActivePower

    Thread Starter Member

    Mar 15, 2012
    155
    23
    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:
     
  12. absf

    Senior Member

    Dec 29, 2010
    1,492
    371
    Code ( (Unknown Language)):
    1. //main.c
    2. //To use PWM for dimming an LED
    3. //PWM Frequency: 1.22 kHz
    4. //CCP1 Register Pin=RC2
    5.  
    6. #include<htc.h>
    7. #define _XTAL_FREQ 20000000
    8.  
    9. __CONFIG(FOSC_HS & WDTE_OFF & DEBUG_ON & LVP_OFF & CPD_OFF & CP_OFF & PWRTE_OFF & BOREN_OFF);
    10.  
    11. void main()
    12. {
    13.     unsigned int duty;      //16 bit value
    14.     TRISC=0;            //set PORTC to output
    15.     PORTC=0;            //set PORTC low
    16.     PR2=255;                //set TMR2 period register
    17.     T2CON=0b00000101;       //set postscaler to 1:1; prescaler to 16
    18.     CCP1CON=0b00001111;     //set the 2 LSB of duty cycle to 0 and initialize CCP module as PWM
    19.     duty=0;
    20.     while(1)
    21.     {          
    22.             while(duty<255)         //increase duty cycle from 0% to 100%
    23.             {
    24.                 CCPR1L=duty;
    25.                 duty=duty+1;
    26.                 __delay_ms(2);
    27.  
    28.             }
    29.             while(duty>0)
    30.             {
    31.                 CCPR1L=duty;
    32.                  duty--;
    33.                 __delay_ms(2);
    34.             }
    35.     }  
    36. }
    37.  
    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
     
    Last edited: Nov 19, 2012
  13. Temitopefunmi

    New Member

    Nov 21, 2012
    1
    0
    Hi absf. I tried what you did and there is no change on d oscilloscope in proteus. Please, help.
     
Loading...