-
1 Attachment(s)
Re: sinusoidal PWM
Hi HenrikOlsson
thankx for your coments and Idea you gave me on the code I posted last time which make my output to be some how clear. But is not quiet clear. here are some challenges I faced again
(1) The ouput does not apper smoth. I tttach the output as seen from ISIS and code.
Code:
STEPCOUNT var byte
STEPCOUNT1 var byte
STEPCOUNT = 0 'pointer for phase one in sinearray
STEPCOUNT1 = 12 'pointer for phase two in sine array
ADCON0 = %00000000
ADCON1 = %00000000
TRISB = %11111001
TRISC = %11111001 'PMW output for CCP1 AND CCP2
TRISA = %11111111
TMR2 = 117
PR2 = 55 'set for 18Khz HPWM
CCP1CON = %00001100 'set CCP1 for PWM OPERATION
CCP2CON = %00001100 'set CCP2 for PWM OPERATION
T2CON = %00000100 'TIMER2ON and prescale of 1:1
sineval var byte[36]
sineval[0] = 128
sineval[1] = 150
sineval[2] = 171
sineval[3] = 191
sineval[4] = 209
sineval[5] = 225
sineval[6] = 238
sineval[7] = 247
sineval[8] = 253
sineval[9] = 255
sineval[10] = 253
sineval[11] = 247
sineval[12] = 238
sineval[13] = 225
sineval[14] = 209
sineval[15] = 191
sineval[16] = 171
sineval[17] = 150
sineval[18] = 128
sineval[19] = 105
sineval[20] = 84
sineval[21] = 64
sineval[22] = 46
sineval[23] = 30
sineval[24] = 17
sineval[25] = 8
sineval[26] = 2
sineval[27] = 0
sineval[28] = 2
sineval[29] = 8
sineval[30] = 17
sineval[31] = 30
sineval[32] = 46
sineval[33] = 64
sineval[34] = 84
sineval[35] = 105
timerone var word
Temp var byte
Temp1 var byte
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System emp
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _sine, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = 000001 ; Prescaler = 1;1, TMR1 ON
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
timerone = 64980 ;gives about 50 htz sine
Main:
PAUSE 5
GOTO Main
'---[TMR1_INT - interrupt handler]------------------------------------------
sine:
T1CON = 000000 'stop the timer
TMR1L = timerone.byte0 'reload the timer
TMR1H = timerone.byte1
T1CON = 000001 'start the timer
TeMP = sineval[STEPCOUNT]
CCP1CON.4 = Temp.0 ' bit 0
CCP1CON.5 = Temp.1 ' bit 1
CCPR1L = Temp >>2 'Bit 2-7
TeMP1 = sineval[STEPCOUNT1]
CCP2CON.4 = Temp.0 ' bit 0
CCP2CON.5 = Temp.1 ' bit 1
CCPR2L = Temp >>2 'Bit 2-7
stepcount = stepcount +1
stepcount1 = stepcount1 +1
if stepcount = 36 then stepcount =0
if stepcount1 = 36 then stepcount1 =12
@ INT_RETURN
(2) I try to write a code so that I can measure if the interrupt frequence is 1800hz.
When I start learning timer in the previous days I passed I cross the link http://www.microcontrollerboard.com/...-tutorial.html there is formural for calcalating a numeric value(count) to be placed to obtain the desired output frequency.
count=fclk/(4*prescale*(65536-TMR1)*fout
where for me
fout=1800hz, prescale 1, TMRI=64980 and fclk=4MHz
gives count = 1 ohh! here I'm confusing how should I proceed since is very small count I cant use it.
can you help which count should I use so I can measure my interrupt frequecy
thankx
-
1 Attachment(s)
Re: sinusoidal PWM
Hi to all
I am here again I am still working on the code I posted last 2 days. It try to work on the code but I still get the same output, as I Attach on the two days ago, when I try to put LED on the interrupt service routine and to see if the frequency is clear this became another problem to me. The problem arising are
(1) The ouput does not apper smoth and which condition should I put to show I get the desired frequency . I atttach again the output as seen from ISIS and the code use to generate that output.
Code:
DEFINE OSC 4
STEPCOUNT var byte
STEPCOUNT1 var byte
STEPCOUNT = 0 'pointer for phase one in sinearray
STEPCOUNT1 = 12 'pointer for phase two in sine array
ADCON0 = %00000000
ADCON1 = %00000000
TRISB = %11111001
TRISC = %11111001 'PMW output for CCP1 AND CCP2
TRISA = %11111111
TMR2 = 117
PR2 = 55 'set for 18Khz HPWM
CCP1CON = %00001100 'set CCP1 for PWM OPERATION
CCP2CON = %00001100 'set CCP2 for PWM OPERATION
T2CON = %00000100 'TIMER2ON and prescale of 1:1
sineval var byte[36]
sineval[0] = 128
sineval[1] = 150
sineval[2] = 171
sineval[3] = 191
sineval[4] = 209
sineval[5] = 225
sineval[6] = 238
sineval[7] = 247
sineval[8] = 253
sineval[9] = 255
sineval[10] = 253
sineval[11] = 247
sineval[12] = 238
sineval[13] = 225
sineval[14] = 209
sineval[15] = 191
sineval[16] = 171
sineval[17] = 150
sineval[18] = 128
sineval[19] = 105
sineval[20] = 84
sineval[21] = 64
sineval[22] = 46
sineval[23] = 30
sineval[24] = 17
sineval[25] = 8
sineval[26] = 2
sineval[27] = 0
sineval[28] = 2
sineval[29] = 8
sineval[30] = 17
sineval[31] = 30
sineval[32] = 46
sineval[33] = 64
sineval[34] = 84
sineval[35] = 105
timerone var word
Temp var byte
Temp1 var byte
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System emp
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _sine, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = 000001 ; Prescaler = 1;1, TMR1 ON
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
timerone = 64980 ; vakue loaded to TMR1 to gives about 50 htz sine
Main:
PAUSE 5
GOTO Main
'---[TMR1_INT - interrupt handler]------------------------------------------
sine:
T1CON = 000000 'stop the timer
TMR1L = timerone.byte0 'reload the timer
TMR1H = timerone.byte1
T1CON = 000001 'start the timer
TeMP = sineval[STEPCOUNT]
CCP1CON.4 = Temp.0 ' bit 0
CCP1CON.5 = Temp.1 ' bit 1
CCPR1L = Temp >>2 'Bit 2-7
TeMP1 = sineval[STEPCOUNT1]
CCP2CON.4 = Temp.0 ' bit 0
CCP2CON.5 = Temp.1 ' bit 1
CCPR2L = Temp >>2 'Bit 2-7
stepcount = stepcount +1
stepcount1 = stepcount1 +1
if stepcount = 36 then stepcount =0
if stepcount1 = 36 then stepcount1 =12
@ INT_RETURN
When I start learning timer in the days ago I passed across the link http://www.microcontrollerboard.com/...-tutorial.html there is formural for calcalating a numeric value(count) to be placed to obtain the desired output frequency.
count=fclk/(4*prescale*(65536-TMR1)*fout this formular gives me a small count which I can not use to test the frequency condition.
thanks
-
Re: sinusoidal PWM
Hi to all
can any one help me how to write 10 bit resolution to PWM MODULE because I read pic datasheets and Ds33023 refference manual I see 10bit resolution is applicable for low frequencies.
thankx.
-
5KHZsinusoidalPWM
Hi to every one
I have worked and modify the code posted by ScaleRobotics and I manage to compile it for the PIC 16F877 and get 2 phase although my output was not very good. my aim is to generate 5kHZ SPWM so that when filtered will give sine waves(50hz). I havebeen reading different application manual and PIC16877 datashet for almost two days but I 'm still in darkness the problem comes for that frequency my duty cycle will have 10bit resolution. here are the questions.
(1) I Try to write the code to FOR 10 bit resolution to PWM module I dont think if is correct.
Code:
TeMP = sineval[STEPCOUNT]
CCP1CON.4 = Temp.0 ' bit 0
CCP1CON.5 = Temp.1 ' bit 1
CCPR1L = Temp.Byte0 >>2 '
(2)when I do my calculation
from microchip application note pwm_frequency=50hz*step*10
which gives me very low step about 10step which is very low when I try to use it my output become very distorted and only CCP1 gives output while ccp2 dont gives any output.
any one can help me how to get 5KHZ 36 step and is it nessary to modify my lookup table for 10bit resolution thankx