jean12
Advanced Member level 2
- Joined
- Aug 27, 2013
- Messages
- 529
- Helped
- 5
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 18
- Activity points
- 5,497
so could you help using another methods of LUT storage??
Thank you!!
Thank you!!
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
In general, the assembler language for all members of a family are the same. Therefore code is transportable between them.I got such codes but the PIC are not the same so I want to adapt the codes to my PIC16f1936,for example the https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en012129 Here are the codes but I need a help for adapting them to my PIC16F1936,here they used PIC16F777,
Please help!!
W_TEMP RES 1 ;LOCATION FOR SAVING 'WREG' DURING INTERRUPT
STATUS_TEMP RES 1 ;LOCATION FOR SAVING 'STATUS' DURING INTERRUPT
LIST P=P16F1936
#include <P16F1936.INC>
ERRORLEVEL -302 ;Warning destination register
ERRORLEVEL -207 ;Warning label after column 1
__CONFIG H'8007',H'3FAA'
__CONFIG H'8008',H'3FBC'
; UDATA_SHR
;///////////////////////////////////////////////////////////////
;PROGRAM ASSIGNATIONS
;///////////////////////////////////////////////////////////////
;CNT15 EQU h'25'
LOCALES UDATA 0X20
FLAGS RES 1 ;FLAGS REGISTERS USED TO INDICATE DIFFERENT STATUS
tmp1 RES 1
tmp2 RES 1
GLOBALES UDATA_SHR;Starting of zone 0x71 to 0x7F
W_TEMP RES 1 ;LOCATION FOR SAVING 'WREG' DURING INTERRUPT
STATUS_TEMP RES 1 ;LOCATION FOR SAVING 'STATUS' DURING INTERRUPT
CNT15 RES 1
CNT16 RES 1
CNT17 RES 1
ORG 0XF000
DE D'123'
DE D'127'
DE D'129'
DE D'133'
DE D'135'
DE D'139'
DE D'141'
DE D'145'
DE D'146'
DE D'150'
DE D'152'
DE D'156'
DE D'158'
DE D'162'
DE D'164'
DE D'167'
DE D'169'
DE D'173'
DE D'174'
DE D'177'
DE D'179'
DE D'182'
DE D'184'
DE D'187'
DE D'189'
DE D'192'
DE D'194'
DE D'197'
DE D'198'
DE D'201'
DE D'203'
DE D'205'
DE D'207'
DE D'209'
DE D'210'
DE D'213'
DE D'214'
DE D'216'
DE D'218'
DE D'219'
DE D'221'
DE D'222'
DE D'223'
DE D'225'
DE D'226'
DE D'227'
DE D'228'
DE D'229'
DE D'230'
DE D'231'
DE D'231'
DE D'233'
DE D'233'
DE D'234'
DE D'234'
DE D'235'
DE D'235'
DE D'235'
DE D'236'
DE D'236'
DE D'236'
DE D'236'
DE D'236'
DE D'235'
DE D'235'
DE D'235'
DE D'234'
DE D'233'
DE D'233'
DE D'232'
DE D'231'
DE D'231'
DE D'230'
DE D'229'
DE D'228'
DE D'227'
DE D'226'
DE D'224'
DE D'223'
DE D'222'
DE D'221'
DE D'218'
DE D'218'
DE D'215'
DE D'214'
DE D'212'
DE D'210'
DE D'208'
DE D'207'
DE D'204'
DE D'203'
DE D'200'
DE D'198'
DE D'195'
DE D'194'
DE D'191'
DE D'189'
DE D'186'
DE D'184'
DE D'181'
DE D'179'
DE D'176'
DE D'174'
DE D'171'
DE D'169'
DE D'165'
DE D'164'
DE D'159'
DE D'158'
DE D'154'
DE D'152'
DE D'148'
DE D'146'
DE D'142'
DE D'141'
DE D'137'
DE D'135'
DE D'131'
DE D'129'
DE D'125'
DE D'123'
;POWER ON RESET VECTOR LOCATION
;**************************************************************************************
STARTUP CODE 0X0000 ;RESET VECTOR ADDRESS
GOTO START
CODE 0X04 ;INTERRUPT VECTOR LOCATION
GOTO readadc ;GOTO INTERRUPT SERVICE ROUTINE
;**************************************************************************************
;PROG0 CODE
;**************************************************************************************
;INITIALIZATION OF THE PORTS AND TIMERS
START
BANKSEL WDTCON
CLRF WDTCON
MOVLW 0x0F
BANKSEL TRISA
MOVWF TRISA
BANKSEL PORTB
CLRF PORTB
BANKSEL TRISB
MOVLW 0xB7
MOVWF TRISB
BANKSEL T2CON
CLRF T2CON
MOVLW 0X0C
BANKSEL CCP1CON
MOVWF CCP1CON
BANKSEL CCP2CON
MOVWF CCP2CON
BANKSEL CCP3CON
MOVWF CCP3CON
BANKSEL PR2
MOVLW d'74' ;LOAD PR2 VALUE TO PR2 REGISTER For 10KHZ generated signal
MOVWF PR2
MOVLW 0XFF
BANKSEL APFCON
MOVWF APFCON
MOVLW 0x10
BANKSEL PWM1CON
MOVWF PWM1CON
BANKSEL PWM2CON
MOVWF PWM2CON
BANKSEL PWM3CON
MOVWF PWM3CON
MOVLW 0X0F
BANKSEL CCP1AS
MOVWF CCP1AS
BANKSEL CCP2AS
MOVWF CCP2AS
BANKSEL CCP3AS
MOVWF CCP3AS
MOVLW 0X1F
BANKSEL PSTR1CON
MOVWF PSTR1CON
BANKSEL PSTR2CON
MOVWF PSTR2CON
BANKSEL PSTR3CON
MOVWF PSTR3CON
MOVLW 0x00
BANKSEL CCPTMRS0
MOVWF CCPTMRS0
BANKSEL TRISC
BCF TRISC,2
BANKSEL TRISB
BCF TRISB,3
BCF TRISB,6
BANKSEL T2CON
MOVLW 0x05
MOVWF T2CON
;BANKSEL CCPR1L
;CLRF CCPR1L
;BANKSEL CCPR2L
;CLRF CCPR2L
;BANKSEL CCPR3L
;CLRF CCPR3L
;BANKSEL EEDATL
;CLRF EEDATL
;BANKSEL EECON1
;BCF EECON1,RD
; CALL
;///////////////////////////////////////////////////////////////////////////////////////
; PROGRAMME PRINCIPAL
;///////////////////////////////////////////////////////////////////////////////////////
MOVLW d'121'
MOVWF CNT15
PROG
DECFSZ CNT15,F
GOTO next
RETURN
;nop
next
MOVF CNT15,W
BANKSEL EEADRL ;Switch to Bank1
MOVWF EEADRL ;Put counter to EEADR
BANKSEL EECON1
BCF EECON1,CFGS
BCF EECON1,EEPGD
BSF EECON1,RD
BANKSEL EEDATL
MOVF EEDATL,W
DECF CNT15,1
adcplace
CALL readadc
BANKSEL ADRESH
MOVF ADRESH,W
BANKSEL CCPR1L
MOVWF CCPR1L
BANKSEL CCPR2L
MOVWF CCPR2L
BANKSEL CCPR3L
MOVWF CCPR3L
BANKSEL EEDATL
MOVF EEDATL,W
BANKSEL CCPR1L
MOVWF CCPR1L
CALL UPDATE_SPWM2
CALL UPDATE_SPWM3
GOTO PROG
RETURN
UPDATE_SPWM2
MOVLW D'121'
MOVWF CNT15
next2
DECFSZ CNT15,f
GOTO next21
RETURN
next21
MOVF CNT15,W
BANKSEL EEADRL ;Switch to Bank1
MOVWF EEADRL ;Put counter to EEADR
BANKSEL EECON1
BCF EECON1,CFGS
BCF EECON1,EEPGD
BSF EECON1,RD
BANKSEL EEDATL
MOVF EEDATL,W
DECF CNT15,1
adcplace2
; CALL readadc
;BANKSEL ADRESH
;MOVF ADRESH,W
;BANKSEL CCPR2L
;MOVWF CCPR2L
BANKSEL EEDATL
MOVF EEDATL,W
BANKSEL CCPR2L
MOVWF CCPR2L
;call delay_1us
RETURN
UPDATE_SPWM3
MOVLW D'121'
MOVWF CNT15
next3
DECFSZ CNT15,f
GOTO next31
RETURN
next31
MOVF CNT15,W
BANKSEL EEADRL ;Switch to Bank1
MOVWF EEADRL ;Put counter to EEADR
BANKSEL EECON1
BCF EECON1,CFGS
BCF EECON1,EEPGD
BSF EECON1,RD
BANKSEL EEDATL
MOVF EEDATL,W
DECF CNT15,1
adcplace3
CALL readadc
BANKSEL ADRESH
MOVF ADRESH,W
BANKSEL CCPR3L
MOVWF CCPR3L
BANKSEL EEDATL
MOVF EEDATL,W
BANKSEL CCPR3L
MOVWF CCPR3L
;call delay_1us
RETURN
readadc
BSF PIE1,ADIE
BSF INTCON,GIE
BSF INTCON,PEIE
BTFSS PIE1,ADIE
return
BTFSS PIR1,ADIF
RETURN
CALL bosco
BCF PIR1,ADIF
return
bosco
BANKSEL ANSELA
MOVLW 0X01
MOVWF ANSELA
MOVLW 0x01
BANKSEL ADCON0
MOVWF ADCON0
MOVLW 0x20
BANKSEL ADCON1
MOVWF ADCON1
BANKSEL ADCON0
BSF ADCON0,GO
BSF ADCON0,CHS0
call delay1
BANKSEL ADRESH
MOVF ADRESH,W
BANKSEL CCPR1L
MOVWF CCPR1L
BANKSEL CCPR2L
MOVWF CCPR2L
BANKSEL CCPR3L
MOVWF CCPR3L
return
readvoltage
MOVLW 0X20
BANKSEL ADCON1
MOVWF ADCON1
MOVLW 0X02
BANKSEL ADCON0
MOVWF ADCON0
BSF ADCON0,CHS0
BCF ADCON1,CHS1
;MOVF ADRESH,W
;MOVWF voltage
;XORLW 0XFF
;BTFSC STATUS,Z
RETURN
INIT_PARAMETERS
BANKSEL EECON1
BCF EECON1,RD ;Stop EEPROM reading process
BANKSEL CCPR1L
CLRF CCPR1L ;clear duty cycle of CCPR3L
CLRF CCPR2L ;clear duty cycle of CCPR2L
BANKSEL CCPR3L
CLRF CCPR3L ;clear duty cycle of CCPR3L
RETURN
delay1
MOVLW d'2'
MOVWF tmp2
delay2
DECFSZ tmp2,f
GOTO delay2
RETURN
delay_1us
MOVLW d'5'
MOVWF tmp2
delay4
DECFSZ tmp2,f
GOTO delay4
RETURN
END
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 char i = 0; unsigned char sin_table_0_180[32]={0, 25, 49, 73, 96, 118, 137, 159, 177, 193, 208, 220, 231, 239, 245, 249, 250, 249, 245, 239, 231, 220, 208, 193, 177, 159, 137, 118, 96, 73, 49, 25}; unsigned char sin_table_120_300[32]={120, 145, 169, 193, 216, 238, 259, 279, 297, 313, 328, 340, 351, 359, 365, 369, 370, 369, 365, 359, 351, 340, 328, 313, 297, 279, 259, 238, 216, 193, 169, 145}; unsigned char sin_table_300_480[32]={270, 295, 319, 343, 366, 388, 409, 429, 447, 463, 478, 490, 501, 509, 515, 519, 520, 519, 515, 509, 501, 490, 478, 463, 447, 429, 409, 388, 366, 343, 319, 295}; unsigned int frequency = 0; unsigned int TBL_POINTER_NEW[3], TBL_POINTER_OLD[3], TBL_POINTER_SHIFT[3], SET_FREQ; unsigned int TBL_temp[3]; unsigned char DUTY_CYCLE[3]; void interrupt(){ if (TMR2IF_bit == 1) { TBL_POINTER_NEW[0] = TBL_POINTER_OLD[0] + SET_FREQ ; if (TBL_POINTER_NEW[0] < TBL_POINTER_OLD[0]){ CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge } TBL_POINTER_SHIFT[0] = TBL_POINTER_NEW[0] >> 11; DUTY_CYCLE[0] = TBL_POINTER_SHIFT[0]; CCPR1L = sin_table_0_180[DUTY_CYCLE[0]]; TBL_POINTER_OLD[0] = TBL_POINTER_NEW[0]; TBL_POINTER_NEW[1] = TBL_POINTER_OLD[1] + SET_FREQ; if (TBL_POINTER_NEW[1] < TBL_POINTER_OLD[1]){ CCP2CON.P2M1 = ~CCP2CON.P2M1; //Reverse direction of full-bridge } TBL_POINTER_SHIFT[1] = TBL_POINTER_NEW[1] >> 11; DUTY_CYCLE[1] = TBL_POINTER_SHIFT[1]; CCPR2L = sin_table_120_300[DUTY_CYCLE[1]]; TBL_POINTER_OLD[1] = TBL_POINTER_NEW[1]; TBL_POINTER_NEW[2] = TBL_POINTER_OLD[2] + SET_FREQ; if (TBL_POINTER_NEW[2] < TBL_POINTER_OLD[2]){ CCP3CON.P1M1 = ~CCP3CON.P1M1; //Reverse direction of full-bridge } TBL_POINTER_SHIFT[2] = TBL_POINTER_NEW[2] >> 11; DUTY_CYCLE[2] = TBL_POINTER_SHIFT[2]; CCPR3L = sin_table_300_480[DUTY_CYCLE[2]]; TBL_POINTER_OLD[2] = TBL_POINTER_NEW[2]; TMR2IF_bit = 0; } } void main() { Delay_ms(200); ADCON1 = 0b10100000; FVRCON = 0x00; ANSELA = 0x01; ANSELB = 0x00; CM1CON0 = 0x00; CM2CON0 = 0x00; TRISA = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; SET_FREQ = 287; for(i = 0; i < 3; i++) { TBL_POINTER_SHIFT[i] = 0; TBL_POINTER_NEW[i] = 0; TBL_POINTER_OLD[i] = 0; DUTY_CYCLE[i] = 0; } PR2 = 410; TRISB = 0xFF; TRISC = 0xFF; PWM1_Init(16000); PWM2_Init(16000); PWM3_Init(16000); PWM1_Set_Duty(0); PWM2_Set_Duty(0); PWM3_Set_Duty(0); PWM1_Start(); PWM2_Start(); PWM3_Start(); TMR2IF_bit = 0; T2CON = 4; while(TMR2IF_bit == 0); TMR2IF_bit = 0; TRISB = 0x00; TRISC = 0x00; TMR2IE_bit = 1; PEIE_bit = 1; GIE_bit = 1; while(1) { } }
unsigned char sin_table_0_180[34]={125,149,171,193,211,227,239,246,250,249,243,233,219,202,182,160,
137,113,90,68,48,31,17,7,1,0,4,11,23,39,57,79,101,125};
unsigned char sin_table_120_300[34]= {21,10,2,0,2,10,21,37,56,77,101,125,125,149,173,194,213,229,240,248,250,248,240,229,
13,194,173,149,125,101,77,56,37};
unsigned char sin_table_300_480[34]={229,213,194,173,149,125,101,77,56,37,21,10,2,0,2,10,21,37,56,77,101,125,125,149,173,194,213,229,240,248,250,248,240,};
{
if(Phase1_index++ > MAX_TABLE_ENTRIES) Phase1_index = 0; // cycle the index through the table then restart again
if(Phase2_index++ > MAX_TABLE_ENTRIES) Phase2_index = 0; // cycle the index through the table then restart again
if(Phase3_index++ > MAX_TABLE_ENTRIES) Phase3_index = 0; // cycle the index through the table then restart again
Set_PWM1(SineTable[Phase1_index]);
Set_PWM2(SineTable[Phase2_index]);
Set_PWM3(SineTable[Phase3_index]);
}