Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F1936 variable duty cycle with lookup table and potentiometer

Status
Not open for further replies.
I am not coming able to read the program memory for updating the CCPRXL accordingly,I referred to the datasheet but it is not giving clear response.!!

Regards,
 

Hi,

This is somehow a useless post.
It's not possible to find the problem with that error description.

--> show us the code.

Klaus
 

I am not coming able to read the program memory for updating the CCPRXL.
Your previous posts suggest that you are programming PIC16 in assembly language, is this true?

Using PIC program memory for constant data is a bit tricky and involving special table read instructions. Microchip VFD examples like AN889 are e.g. copying the sine LUT to a RAM table during startup and generating the PWM out of RAM.
 

Provided the table is aligned to a page boundary it should be OK. The problem with tables in 16F processors occurs when they cross a page boundary and the offset wraps to the beginning of the same page instead of starting in the next one.

The 16F1936 also has the 'BRW' (Branch Relative to W) instruction that makes it easier to pick table values although it doesn't appear to fix the boundary issue.

It's much easier with 18F devices which have dedicated table write and read instructions.

Brian.
 

Hey,FvM I am using assembly I had different recommendations here in forum to use assembly rather than C language,I found that AN889 but I don`t have PIC16F777 with me what I have is PIC16F1936.So I need to refer to the information provided in AN889 https://ww1.microchip.com/downloads/cn/AppNotes/cn012129.pdf and do my codes in PIC16F1936 and the main problem is updating data of Phases(Phase1,Phase2 and Phase3) via CCPR1L,CCPR2L and CCPR3L and this to be done I need to place the LUT in a RAM for easier access.

For example the following codes I was trying to read the LUT and immediately create a PWM signal but I am not succeeding,any help may be wonderful for me
PHP:
	LIST		p=P16F1936
	INCLUDE		<P16F1936.INC>
 __CONFIG _CONFIG1, _FOSC_HS& _WDTE_OFF& _PWRTE_OFF& _MCLRE_ON& _CP_OFF& _CPD_OFF& _BOREN_OFF& _CLKOUTEN_ON& _IESO_OFF& _FCMEN_ON
 __CONFIG _CONFIG2, _WRT_OFF& _VCAPEN_OFF& _PLLEN_ON& _STVREN_OFF& _BORV_19& _LVP_OFF
	
	INCLUDE		<parameters.INC>

;**************************************************************************************
 UDATA_SHR  
W_TEMP		RES	1	;LOCATION FOR SAVING 'WREG' DURING INTERRUPT
STATUS_TEMP	RES	1	;LOCATION FOR SAVING 'STATUS' DURING INTERRUPT
TEMP_LOC	RES	1	;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_1	RES	1	;GENERAL PURPOSE TEMPORARY LOCATION
TEMP_LOC_2	RES	1	;GENERAL PURPOSE TEMPORARY LOCATION
 UDATA 
TABLE_Value        	RES	0X24	;SINE TABLE	

	GLOBAL	TEMP_LOC
	GLOBAL	TEMP_LOC_1
	GLOBAL	TEMP_LOC_2

;**************************************************************************************
;MACRO FOR MULTIPLICATION - 8X8 UNSIGNED
;**************************************************************************************
MULT    MACRO   BIT			;MACRO FOR UNSIGNEDMULTIPLICATION
	BTFSC   NO_1_LSB,BIT
	ADDWF   RESULT_MSB,F
	RRF     RESULT_MSB,F
	RRF     RESULT_LSB,F
	ENDM				;END OF MACRO FOR MULTIPLICATION
	
;**************************************************************************************
;POWER ON RESET VECTOR LOCATION
;**************************************************************************************
STARTUP	CODE	0X00			;RESET VECTOR ADDRESS 
	    GOTO	START	
	;******************************************************************
;INTERRUPT SERVICE ROUTINE
;******************************************************************
;******************************************************************
  CODE 0x004
	MOVWF 	W_TEMP 			;COPY W TO A TEMPORARY REGISTER
	SWAPF 	STATUS,W 		;SWAP STATUS NIBBLES AND PLACE INTO W REGISTER
	MOVWF 	STATUS_TEMP 		;SAVE STATUS TO A TEMPORARY REGISTER IN BANK0


	SWAPF	STATUS_TEMP,W 		;SWAP ORIGINAL STATUS REGISTER VALUE INTO W (RESTORES ORIGINAL BANK)
	MOVWF 	STATUS 			;RESTORE STATUS REGISTER FROM W REGISTER				
	SWAPF 	W_TEMP,F 		;SWAP W_TEMP NIBBLES AND RETURN VALUE TO W_TEMP
	SWAPF 	W_TEMP,W 		;SWAP W_TEMP TO W TO RESTORE ORIGINAL W VALUE WITHOUT AFFECTING STATUS
	RETFIE				;RETURN FROM INTERRUPT
;******************************************************************


;	CODE	0X04			;INTERRUPT VECTOR LOCATION
    ;GOTO	ISR_INT			;GOTO INTERRUPT SERVICE ROUTINE

;**************************************************************************************
PROG0	CODE
START
;**************************************************************************************
;INITIALIZATION OF THE PORTS AND TIMERS
	CLRWDT
;//////////////////////////////////////////////////////////////////////////////////////////////////////
; 		PORT DATA DEFINITION

;**************************************************************************************

	;***********************************************
	;  PORTS CONFIGURATION
	;**********************************************
	MOVLW 0x00
	BANKSEL TRISC 
	MOVWF TRISC	
	BANKSEL PORTC
	CLRF PORTC
;	MOVLW 0x03
	;BANKSEL TRISB 
	;MOVWF TRISB 

   BANKSEL LATC
	CLRF LATC
;	BANKSEL LATE
	;CLRF LATE
;//////////////////////////////////////////////////////////////
;				REGISTER DEFINITION
;/////////////////////////////////////////////////////////////
	BANKSEL FVRCON
	MOVLW 0X00
	MOVWF FVRCON
	BANKSEL CCP1CON
	CLRF CCP1CON
	BANKSEL CCP2CON
	CLRF CCP2CON
	BANKSEL CCP3CON
	CLRF CCP3CON
;	BANKSEL TRISC
	;BSF TRISC,1
	;BSF TRISC,2
	;BSF TRISC,6
	;CLRF TRISC
	BANKSEL PORTB
	CLRF PORTB
	BANKSEL TRISB
	CLRF TRISB
	BANKSEL LATB
	CLRF LATB
	MOVLW 0X00
	BANKSEL WPUB
	MOVWF WPUB
	BANKSEL WPUE
	MOVWF WPUE
	BANKSEL LATE
	MOVWF LATE
	BANKSEL LATA
	MOVWF LATA
	BANKSEL LATB
	MOVWF LATB
	MOVLW 0X00
	BANKSEL LATC
	MOVWF LATC
	BANKSEL OSCCON
	MOVLW 0X38
	MOVWF OSCCON

	BANKSEL APFCON
	MOVLW 0X00
	MOVWF APFCON
	MOVLW 0XBC      ;for Half bridge configuration
	BANKSEL CCP1CON	
	MOVWF	CCP1CON			;CCP1,CCP2 AND CCP3 CONFIGURED  TO PWM
	BANKSEL CCP2CON	
	MOVWF	CCP2CON
	BANKSEL CCP3CON
	MOVWF	CCP3CON
	BANKSEL PWM1CON
	MOVLW 0X80
	MOVWF PWM1CON
	BANKSEL PWM2CON
	MOVWF PWM2CON
	BANKSEL PWM3CON
	MOVWF PWM3CON
	BANKSEL PSTR1CON
	BANKSEL CCPTMRS0 ;select the TMR2 on which CCP1,CCP2 and CCP3 are based
    MOVLW 0x00
	MOVWF CCPTMRS0
	BANKSEL PIR1
	BCF PIR1,TMR2IF
	BANKSEL	PR2
	;MOVLW	PR2_VALUE		;LOAD PR2 VALUE TO PR2 REGISTER
	;MOVWF	PR2		
;	CALL STOP_MOTOR
	;MOVLW d'7'
	;BANKSEL T2CON
	;MOVWF T2CON
	clrf CCPR1L
prog
	BANKSEL PR2
	MOVLW PR2_VALUE
	MOVWF PR2
	MOVLW 0X0C
	BANKSEL CCP1CON
	MOVWF CCP1CON
	BANKSEL T2CON
	BSF T2CON,TMR2ON
	CALL COPY_TABLE_TO_RAM
	GOTO  START
	RETURN

;*******************************************************************
;Copy Table to RAM
;*****************************************************************

COPY_TABLE_TO_RAM
	BANKSEL TABLE_Value
	BANKISEL TABLE_Value
	MOVLW LOW(TABLE_Value)
	MOVWF FSR1L
	MOVLW HIGH(TABLE_Value)
	MOVWF FSR1H
	MOVIW 0[FSR1]
	MOVLW 0X79
	MOVWF TEMP_LOC
	CLRF TEMP_LOC_1
	BANKSEL TRISC
	BCF TRISC,2
COPY_AGAIN
	MOVLW HIGH(SINE_TABLE)
	MOVWF PCLATH
	MOVIW 0[FSR1]
	MOVF	TEMP_LOC_1,W
	PAGESEL SINE_TABLE
	CALL	SINE_TABLE
	BANKSEL  CCPR1L
	MOVWF CCPR1L
	MOVWF	INDF1	
	INCF	TEMP_LOC_1,F
	INCF	FSR1L,F
	DECFSZ	TEMP_LOC,F
	GOTO	COPY_AGAIN
	MOVLW HIGH(TABLE_Value)
	MOVWF  FSR1H
	MOVLW	LOW(TABLE_Value)	;FSR POINTS TO THE STARTING OF THE TABLE
	MOVWF  FSR1L	
	MOVIW   0[FSR1]
	RETURN	
;*******************************************************************************
;EQUATION USED FOR CALCULATION OF SINE TABLE ENTRIES = (SIN(ANGLE)+1)*FF/2
;ANGLES ARE FROM 270 DEG. TO 90 DEG. STEP SIZE = 10 DEG.
;*******************************************************************************

TABLE	CODE	0X0035

SINE_TABLE  
	BRW  
		ADDWF	PCL,F
		RETLW 	0x7B
		RETLW 	0x7F
		RETLW 	0x81
		RETLW 	0x85
		RETLW 	0x87
		RETLW 	0x8B
		RETLW 	0x8D
		RETLW 	0x91
		RETLW 	0x92
		RETLW 	0x96
		RETLW 	0x98
		RETLW 	0x9C
		RETLW 	0x9E
		RETLW 	0xA2
		RETLW 	0xA4
		RETLW 	0xA7
		RETLW 	0xA9
		RETLW 	0xAD
		RETLW 	0xAE
		RETLW 	0xB1
		RETLW 	0xB3
		RETLW 	0xB6
		RETLW 	0xB8
		RETLW 	0xBB
		RETLW 	0xBD
		RETLW 	0xC0
		RETLW 	0xC2
		RETLW 	0xC5
		RETLW 	0xC6
		RETLW 	0xC9
		RETLW 	0xCB
		RETLW 	0xCD
		RETLW 	0xCF
		RETLW 	0xD1
		RETLW 	0xD2
		RETLW 	0xD5
		RETLW 	0xD6
		RETLW 	0xD8
		RETLW 	0xDA
		RETLW 	0xDB
		RETLW 	0xDD
		RETLW 	0xDE
		RETLW 	0xDF
		RETLW 	0xE1
		RETLW 	0xE2
		RETLW 	0xE3
		RETLW 	0xE4
		RETLW 	0xE5
		RETLW 	0xE6
		RETLW 	0xE7
		RETLW 	0xE7
		RETLW 	0xE9
		RETLW 	0xE9
		RETLW 	0xEA
		RETLW 	0xEA
		RETLW 	0xEB
		RETLW 	0xEB
		RETLW 	0xEB
		RETLW 	0xEC
		RETLW 	0xEC
		RETLW 	0xEC
		RETLW 	0xEC
		RETLW 	0xEC
		RETLW 	0xEB
		RETLW 	0xEB
		RETLW 	0xEB
		RETLW 	0xEA
		RETLW 	0xE9
		RETLW 	0xE9
		RETLW 	0xE8
		RETLW 	0xE7
		RETLW 	0xE7
		RETLW 	0xE6
		RETLW 	0xE5
		RETLW 	0xE4
		RETLW 	0xE3
		RETLW 	0xE2
		RETLW 	0xE0
		RETLW 	0xDF
		RETLW 	0xDE
		RETLW 	0xDD
		RETLW 	0xDA
		RETLW 	0xDA
		RETLW 	0xD7
		RETLW 	0xD6
		RETLW 	0xD4
		RETLW 	0xD2
		RETLW 	0xD0
		RETLW 	0xCF
		RETLW 	0xCC
		RETLW 	0xCB
		RETLW 	0xC8
		RETLW 	0xC6
		RETLW 	0xC3
		RETLW 	0xC2
		RETLW 	0xBF
		RETLW 	0xBD
		RETLW 	0xBA
		RETLW 	0xB8
		RETLW 	0xB5
		RETLW 	0xB3
		RETLW 	0xB0
		RETLW 	0xAE
		RETLW 	0xAB
		RETLW 	0xA9
		RETLW 	0xA5
		RETLW 	0xA4
		RETLW 	0x9F
		RETLW 	0x9E
		RETLW 	0x9A
		RETLW 	0x98
		RETLW 	0x94
		RETLW 	0x92
		RETLW 	0x8E
		RETLW 	0x8D
		RETLW 	0x89
		RETLW 	0x87
		RETLW 	0x83
		RETLW 	0x81
		RETLW 	0x7D
		RETLW 	0x7B

;*******************************************************************************
;END OF FILE
;*******************************************************************************
	END

- - - Updated - - -

Dear betwixt,Do you have more information with PIC18?can`t you help with this 16f1936??

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top