• AVR Freaks

PWM output not coming out of RC5 pin of 16F1828 micon (20Pin DIP package

Author
microchipprob
Senior Member
  • Total Posts : 140
  • Reward points : 0
  • Joined: 2008/07/01 00:51:30
  • Location: 0
  • Status: offline
2019/08/19 22:59:57 (permalink)
0

PWM output not coming out of RC5 pin of 16F1828 micon (20Pin DIP package

Hi
could somebody help me to finding  the mistake in the Assembly line, My device is 16F1828 20 pin DIP package, i am running it at 8 Mhz with internal Osc, i wrote a UART initialization to drive a Noritake VFD display. My A/D and display are working satisfactorily. I removed the assembly lines for the same . i am struck with PWM output. I needed a PWM output on RC5 pin (20Pin DIP) package, PWM frequency 4.90kHz,(Standard) single PWM as suggested i used CCP3 module, Timer2 and followed steps as in data sheet, the result there is no output. I have just put only the lines for PWM activation
ASm lines are as below
help needed.Thanks
;******************************************************************************
; This file is a basic code template for code generation on the *
; PIC16F1828. This file contains the basic code building blocks to build *
; upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler. *
; *
; Refer to the respective data sheet for additional *
; information on the instruction set. *
; *
;******************************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
;******************************************************************************
; *
; Files Required: P16F1827.INC *
; *
;******************************************************************************
; *
; Notes: *
; *
;******************************************************************************
; *
; Revision History: *
; *
;******************************************************************************
list p=16f1828 ; list directive to define processor
#include <p16f1828.inc> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF
;------------------------------------------------------------------------------
; VARIABLE DEFINITIONS
; Available Data Memory divided into Bank 0-15. Each Bank may contain
; Special Function Registers, General Purpose Registers, and Access RAM
;;------------------------------------------------------------------------------
CBLOCK 0x20 ; Define GPR variable register locations
MYVAR1 ; User variables allocated contiguously
MYVAR2 ;
MYVAR3 ;
RESULTLO ;
RESULTHI ;
ANSEL
dc1
dc2
d1
d2
d3
dig4
dig3
dig2
dig1
dig0
Lbyte
Hbyte
L_byte
H_byte
dlyCnt

; UDATA
;dc1 res 1 ; delay loop counters
;dc2 res 1
ENDC
SAMPLE1 EQU 0x7D ; Sample user registers
SAMPLE2 EQU 0x7E ;
SAMPLE3 EQU 0x7F ;
;------------------------------------------------------------------------------
; EEPROM INITIALIZATION
;
; The 16F1828 has 256 bytes of non-volatile EEPROM, starting at address 0xF000
;------------------------------------------------------------------------------
DATAEE ORG 0xF000
DE "MCHP" ; Place 'M' 'C' 'H' 'P' at address 0,1,2,3
;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
ORG 0x0000 ; processor reset vector
PAGESEL START
GOTO START ; When using debug header, first inst.
; may be passed over by ICD2.
;------------------------------------------------------------------------------
; INTERRUPT SERVICE ROUTINE
;------------------------------------------------------------------------------
ORG 0x0004
;------------------------------------------------------------------------------
; USER INTERRUPT SERVICE ROUTINE GOES HERE
;------------------------------------------------------------------------------
; Note the 16F1828 family automatically handles context restoration for
; W, STATUS, BSR, FSR, and PCLATH where previous templates for 16F families
; required manual restoration. Shadow registers store these SFR values, and
; shadow registers may be modified since they are readable and writable for
; modification to the context restoration.
RETFIE ; return from interrupt
;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
START
; LED Initialisation port pins as outputs
BANKSEL TRISC
BCF TRISC,3 ;clear RC3 LED4
BCF TRISC,4 ;clear RC4 LED3
BCF TRISC,6 ;clear RC6 LED2
BCF TRISC,7 ; led

;*******FOsc set for 8 Mhz******
BANKSEL  OSCCON
MOVLW    0x72
MOVWF   OSCCON
;****************************
BANKSEL LATC
BSF        LATC,7 ; glow led
CALL     delay_500ms
BCF       LATC,7
call        delay_500ms
BSF       LATC,7
;*******PWM Intialisation*****************
;**************************************
;PWM INITIALISATION
BANKSEL  CCP1CON
clrf           CCP1CON
BANKSEL TRISC
BCF         TRISC,5 ;clear RC5 pwm o/p
BANKSEL  PIE1
clrf          PIE1
BANKSEL TMR2
CLRF       TMR2
MOVLW    0x65
BANKSEL PIR2
MOVWF    PR2 ; PR2 = 0x65,4.90 KHz, pwm frequency
MOVLW    0x21 ;33d, duty cycle approx 0.50
BANKSEL  CCPR3L
MOVWF    CCPR3L
BANKSEL CCPTMRS0
clrf          CCPTMRS0
BSF         CCPTMRS0,3
BSF         CCPTMRS0,2

BANKSEL INTCON
CLRF       INTCON
BANKSEL CCP1CON
BCF         CCP3CON,5
BCF        CCP3CON,4
BANKSEL ANSELC ;
BCF        ANSELC,5 ;CLR RC5 to Digitsl,pwm output
BANKSEL T2CON
BSF        T2CON,TMR2ON ; start timer2
goto        $
;***************************************************
#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 23581
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PWM output not coming out of RC5 pin of 16F1828 micon (20Pin DIP package 2019/08/19 23:49:16 (permalink)
    +1 (1)
    Which CCP peripheral are you trying to use?
    CCP1 outputs on RC5
    CCP3 outputs on RA2
     
    You don't set either of them into PWM mode.
    post edited by ric - 2019/08/19 23:55:12

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    ric
    Super Member
    • Total Posts : 23581
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PWM output not coming out of RC5 pin of 16F1828 micon (20Pin DIP package 2019/08/19 23:54:08 (permalink)
    +1 (1)
    You're lucky that PIR2 and PR2 are in the same bank!

    BANKSEL PIR2
    MOVWF    PR2 ; PR2 = 0x65,4.90 KHz, pwm frequency


    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    stenakew
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2013/09/04 10:54:16
    • Location: 0
    • Status: offline
    Re: PWM output not coming out of RC5 pin of 16F1828 micon (20Pin DIP package 2019/08/21 02:27:43 (permalink)
    0
    Hej.
    A simple PWM program for PIC16F1829 (as I don't have a 1828)
    MPLABX 5.15 and using relative mode (I have never used absolute mode)
     

     
     
     
    ;1829_Simple_PWM_A.asm

    #include "p16f1829.inc"
     
     
     
    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF
    __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_ON
     
     
     
    radix dec
    errorlevel -302 ;to get rid of all bank warnings

    ;button on RC4 (switch connected to RC4 on Curisoity board)
    #define BUTTON_PORT PORTC
    #define BUTTON_WPU WPUC
    #define BUTTON_BIT 4

    ;PWM signal on RC5 (connected to LED7 on Curiosity board)
    #define PWM_OUTPUT_TRIS TRISC
    #define PWM_OUTPUT_BIT 5

    #define PWM_DUTYCYCLE_BUTTON_NOT_PRESSED 51
    #define PWM_DUTYCYCLE_BUTTON_PRESSED 90
    #define PWM_PERIOD 102 ; 0x65

    RST code 0
    pagesel start
    goto start

    INT code 4
    retfie

    MAIN code
    start
    ;cange clock speed to 8MHz
    banksel OSCCON
    movlw B'01110000' ;PLL off, 8 MHz, clock by configuration bits
    movwf OSCCON

    ;remove all WPUs as flags are "on" at reset
    banksel WPUA
    clrf WPUA
    banksel WPUB
    clrf WPUB
    banksel WPUC
    clrf WPUC
    ;Enable global WPU
    banksel OPTION_REG
    bcf OPTION_REG, NOT_WPUEN

    ;initialize button
    banksel BUTTON_WPU
    bsf BUTTON_WPU, BUTTON_BIT

    ;initialize CCP1 to output PWM, using Timer 2
    banksel PR2
    movlw PWM_PERIOD
    movwf PR2
    banksel CCP1CON
    movlw B'00001100' ;PWM mode, P1A and P1C active high, P1B and P1D active low
    movwf CCP1CON
    ;set duty cycle
    banksel CCPR1L
    movlw PWM_DUTYCYCLE_BUTTON_NOT_PRESSED
    movwf CCPR1L
    banksel CCPTMRS
    movlw B'00000000' ;Select timer 2 as CCP1 source
    movwf CCPTMRS
    ;start timer 2
    banksel T2CON
    movlw B'0000101' ;POST = 1:1, ON, PRE = 1:4
    movwf T2CON

    ;enable output
    banksel PWM_OUTPUT_TRIS
    bcf PWM_OUTPUT_TRIS, PWM_OUTPUT_BIT


    main_loop
    ;if button pressed
    banksel BUTTON_PORT
    btfsc BUTTON_PORT, BUTTON_BIT
    goto main_loop ;Not pressed
    ;button pressed, change duty cycle
    banksel CCPR1L
    movlw PWM_DUTYCYCLE_BUTTON_PRESSED
    movwf CCPR1L

    goto main_loop

    end 
     
     
     

     
    /Sten-Åke
     
    post edited by stenakew - 2019/08/21 02:30:29

    Attached Image(s)

    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5