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.

sine lookup table with 16 bit value...

Status
Not open for further replies.

kvrajasekar

Junior Member level 3
Joined
Sep 18, 2008
Messages
28
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,517
sine lookup table

Hi,

I want to generate sine wave using asm code in 16f877.it has 10-bit adc.

data in adc is 16 bit wide.the result will be stored in ADRESH and ADRESL.How can i use the sine LUT for 16 bit variable or is there any method to implement.

If i store the values using PCL it is 8 bit wide ,but my adc data is 16 bit,how can i use the sine LUT,

Please share your ideas.

Regards,
raja.
 

sin values table

Hi,

Thanks for the response.I am not goin to generate sine wave,i am using the sinee LUT for internal comparision to generate sine pwm.
 

sine wave lookup table

I can't catch the point, you need a way to generate the output sinewave from PIC by using a LUT or your think is different? You talk about ADC but this is on input, if you like to generate output wave you need a DAC or use the PWM by modulating the duty-cycle accordling to the stored sinetable values and feed all trough a low-pass filter.

Bye
Pow
 

sin table values

i am using the sinee LUT for internal comparision to generate sine pwm.
Then it's unclear, what's the inteded role of the ADC in your design. Sine PWM normally implies comparing a software generated ramp with a sine table. Apart from that, the bitwidth (and also number of points) depends on the required resolution respectively accuray rather than on the data format of any signal involved in the operation, cause it could be shifted to a different bitwidth.
 

generate look up table sin

Thanks for the reply...

Actually sine pwm is generated by compare software generated ramp with sine LUT.

we are receiving input thru ADC(for example.RA0).16f877 has 10-bit adc(1024 steps).so the sine LUT table also has 16 bit value (correst me if i am wrong ).but 16f877 is a 8 bit processor,can anyone help me how to generate the sine lookup table.
 
  • Like
Reactions: dilshy

    dilshy

    Points: 2
    Helpful Answer Positive Rating
sin lookup table

;*********************************************************************
TITLE "PWM based sine wave generator"
LIST P=16C620, R=DEC

INCLUDE <P16C620.INC>
__CONFIG _BODEN_OFF&_CP_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC
;
;*********************************************************************
; File: SINE.ASM
; Author: Rob Stein
; Date: 12/20/95
; Assembler: MPASM V01.40
; Xtal: 20 Mhz
; Inst Clk: 5 Mhz (200nSec)
;*********************************************************************
; Description:
; Outputs a 60 Hz synthizied sine wave (32 step) via a general
; purpose I/O pin (RB1) into a low pass filter. A software PWM
; routine is used to create 32 seperate sinewave steps. This
; software was prototyped with the PICDEM1 board.
;
; Circuit Diagram:
;
; 2.7k 2.7k
; RB1 ___/\ /\ /\______/\ /\ /\________ Analog Output
; \/ \/ | \/ \/ |
; | |
; ----- 0.1uF ----- 0.1uF
; ----- -----
; | |
; GND GND
;
; ROM Usage: 98 words
;
; RAM Usage: 6 bytes
;
;************************* Constant Definition *********************

FXTAL EQU .20000000 ; Crystal Frequency
FINST EQU FXTAL/4 ; Instruction Cycle Frequency
FSINE EQU .60 ; Sine function frequency
STEP# EQU .32 ; Number of steps
FSTEP EQU FSINE * STEP# ; Step frequency

;************************* Register Definition *********************

TEMPW EQU 0x20 ; Temporary interupt storage for W
DELAYCNT1 EQU 0x21 ; Delay routine counter low
DELAYCNT2 EQU 0x22 ; Delay routine counter high
STEPCOUNT EQU 0x23 ; Sine step counter
OUTLOW EQU 0x24 ; PWM low cycle load for TMR0
OUTHIGH EQU 0x25 ; PWM high cycle load for TMR0

;************************* Bit Definition *********************

PWM EQU 0x01 ; RB1 used for PWM output

;*********************************************************************
; Reset Vector
;*********************************************************************

org 0x000
goto Start ; Begining of Program

;*********************************************************************
; Interupt Vector and Service Routine
; This interupt routine is entered via an overflow of TMR0 from
; 0xFF to 0x00. A test of RB1 determines if the next time state
; is a high or low cycle. The next interupt will occure based the
; TMR0 reload value (OUTLOW or OUTHIGH).
;
; The interupt routine was designed to use a minimial number of
; instruction cycles. This was done to maximize the PWM duty cycle
; range (ie. a 5 % to 95 % range is achievable with this ISR). Note
; that 'swapf' instructions are used to perform register moves without
; effecting the STATUS flags (this saves instruction cycles by
; eliminating the need to temporarily save the STATUS register).
;
;*********************************************************************

org 0x004 ; Interupt vector location
IntVector
movwf TEMPW ; Temporarily save W
btfsc PORTB,PWM ; Was this a Low cycle ?
goto PWMLow ; No ...
PWMHigh
swapf OUTHIGH,W ; Yes... Load high time without affecting STATUS flags
bsf PORTB,PWM
nop ; Delay to equalize high/low TMR0 load cycles
movwf TMR0 ; Load next edge interupt time
bcf INTCON,T0IF ; Clear TMR0 overflow flag
swapf TEMPW,F ; Swap saved W
swapf TEMPW,W ; Restore W
IntEndHi
retfie ; Return from Interupt
PWMLow
bcf PORTB,PWM
swapf OUTLOW,W ; Load low time
movwf TMR0 ; Load next edge interupt time
bcf INTCON,T0IF ; Clear TMR0 overflow flag
swapf TEMPW,F ; Swap saved W
swapf TEMPW,W ; Restore W
IntEndLo
retfie ; Return from Interupt

;*********************************************************************
; Main Routine
;*********************************************************************
Start
clrf STATUS ; Intitialize STATUS & select bank 0
bsf STATUS,RP0 ; Select register bank 1
movlw 0x88
movwf OPTION_REG ; 1:1 TMR0 prescaler, PORTB pull-ups disabled
movlw 0xFF
movwf TRISA ; Set Port_A as inputs
clrf TRISB ; Set Port_B as outputs
bcf STATUS,RP0 ; Select register bank 0
movwf PORTB ; PORT_B pins high
clrf TMR0 ; Initialize TMR0
movlw 0xA0
movwf INTCON ; Enable TMRO and global interupt
ResetStep
movlw STEP#
movwf STEPCOUNT ; Load counter for 32 steps
StepLoop
call Delay ; Software delay
movf STEPCOUNT,W ; Pass table offset via W
call SineTable ; Get table value
call SetPWM ; Set-up low & high PWM values
decfsz STEPCOUNT,F ; Next step
goto StepLoop
goto ResetStep

;*********************************************************************
; Set PWM Subroutine
; The following calculates the next low and high PWM time values.
; The two time values, OUTLOW and OUTHIGH, will be passed to the
; interupt service routine.
;*********************************************************************
SetPWM
bcf INTCON,GIE ; Disable interupts to protect ISR from...
; corrupting OUTLOW & OUTHIGH values
movwf OUTLOW ; Set PWM Duty Cycle
comf OUTLOW,W

addlw IntEndHi-IntVector ; Adjust for Int Service time
movwf OUTHIGH
movf OUTLOW,W
addlw IntEndHi-IntVector ; Adjust for Int Service time
movwf OUTLOW

swapf OUTLOW,F ; Swap nibbles so that interupt service...
swapf OUTHIGH,F ; will not corrupt STATUS
bsf INTCON,GIE ; Re-enable interupts
return

;*********************************************************************
; Look-up Table for Sine Wave
; This 32 entry table was generated to produce a 0.1*Vdd to
; 0.9*Vdd (typicaly 0.5 to 4.5 volt) sine function.
;*********************************************************************
SineTable
addwf PCL,F ; Increment into table
retlw .0 ; Dummy table value
retlw .128 ; 0 degree, 2.5 volt
retlw .148
retlw .167
retlw .185
retlw .200
retlw .213
retlw .222
retlw .228
retlw .230 ; 90 degree, 4.5 volt
retlw .228
retlw .222
retlw .213
retlw .200
retlw .185
retlw .167
retlw .148
retlw .128 ; 180 degree, 2.5 volt
retlw .108
retlw .89
retlw .71
retlw .56
retlw .43
retlw .34
retlw .28
retlw .26 ; 270 degree, 0.5 volt
retlw .28
retlw .34
retlw .43
retlw .56
retlw .71
retlw .89
retlw .108

;*********************************************************************
; Time Delay Sub-routine
; The time delay is used to create the precision 32 steps. The
; 32 step times totaled together add up to a 60 Hz rate. Note that
; constants DELAYCNT# are used so that other frequencies can easily
; generated (example: FSINE equ .50 for a 50 Hz sinewave).
;*********************************************************************
TDELAY EQU FINST/FSTEP ; # of delay count cycles
ADJTDELAY EQU TDELAY/3 - 55 ; Adjust for main routine cycles
TDELAYHI EQU high ADJTDELAY ; Most Significant Byte of TDELAY
TDELAYLO EQU low ADJTDELAY ; Least Sig. Byte of TDELAY

Delay
movlw TDELAYHI
movwf DELAYCNT2 ; Load high byte delay counter
clrf DELAYCNT1
LoopD1
decfsz DELAYCNT1,F ; Finished with 256 loops ?
goto LoopD1 ; No ... keep going
decfsz DELAYCNT2,F ; Yes... Done with TDELAYHI loops ?
goto LoopD1 ; No ...

movlw TDELAYLO ; Yes... Load low byte with adjust for...
movwf DELAYCNT1 ; main routine cycles.
LoopD2
decfsz DELAYCNT1,F ; Finished with TDELAYLO loops ?
goto LoopD2 ; No ... keep going
return ; Yes... Finished

END ; That's all Folks !

 
sine table lookup

Dear friend,
Could you clarify your idea of PWM Generation by c. or conceptually as i don't understand..from where you get your LUT values.
Thanks
 

sine value table

Hi,
Interesting pwm sinewave generating routine. Instead of 32 table entry for whole 360 degree, total 64 entry with 32 each for 180 degree would have given better result. Thanks.
 

could some one please explain the mechanism of generating spwm.. and also post the code for it.
 

whats wrong with this code ..can any one help...



#include <p18cxxx.h>
#include <delays.h>

#pragma config OSC = HS /* Sets the oscillator mode to HS */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#pragma config DEBUG = OFF /* Compiles without extra debug code */
//LCD Control pins




const unsigned char sinetable[10] = {0,77,147,202,237,250,237,202,147,77};
int i=0;




void main(void)
{
TRISC=0xFB;
LATC=0;

CCP1CON=0x0C;
PR2=234;
T2CON=0x00;

while(1)
{
i=0;


for(i=0; i < 10; i++)
{
CCPR1L= sinetable;
TMR2=0x0;
PIR1bits.TMR2IF=0;
T2CONbits.TMR2ON=1;
while(PIR1bits.TMR2IF ==0);
}
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top