View Full Version : Spwm signals

sangaboy

- 5th January 2012, 04:28

hi to all I need help on how this portion of code work thanx

sine:

TMR1L = timerone.byte0

TMR1H = timerone.byte1

TeMP = sineval[STEPCOUNT]

CCP1CON.4 = Temp.0 ' bit 0

CCP1CON.5 = Temp.1 ' bit 1

CCPR1L = Temp >>2 'Bit 2-7

if stepcount = 0 then stepcount =36

stepcount = stepcount -1

HenrikOlsson

- 5th January 2012, 07:34

Hi,

TMR1L = timerone.byte0

TMR1H = timerone.byte1

This loads the value stored in the variable timerone (which is a WORD) to the two individual 8-bit registers making up TMR1.

TeMP = sineval[STEPCOUNT]

This makes TeMP equal to the value at location STEPCOUNT in array sineval.

CCP1CON.4 = Temp.0 ' bit 0

CCP1CON.5 = Temp.1 ' bit 1

CCPR1L = Temp >>2 'Bit 2-7

This sets the duty cycles of the PWM signal generated by the CCP1 module by first taking the lower bits of Temp and copying those to CCP1CON.4 and CCP1CON.5. Then it takes the reminding 8 bits of the 10bit dutycycle value (stored in Temp) and copies those to CCPR1L.

if stepcount = 0 then stepcount =36

stepcount = stepcount -1

This first checks if the index into the array is 0, if so it "resets" it to 36 in order to restart the cycle. Then it decrements it the same index by one.

Stepcount counts from 35 to 0 and then starts over. It's used to retrieve values from the array sineval (which should contain 36 values). The retrieved value is desired dutycycle of the generated PWM.

sangaboy

- 5th January 2012, 12:58

thankx a lot for HenrikOlsson your help, my aim is to generate 3-phase SPWM using PIC16F877 but I started by I understanding single phase SPWM.

I have read the Microchip appliction notes for sine wave with the 16F series chip..http://ww1.microchip.com/downloads/en/AppNotes/00655a.pdf together with the examples given in http://www.picbasic.co.uk/forum/content.php?r=229-Sine-wave-using-DT- interrupts and http://www.picbasic.co.uk/forum/showthread.php?t=14359.

there are number of things which i've not understand from these readings and i'm asking for help from anyone who can help me to understand.these things are:

1) which formular was used to generate a lookup table for the sine waveforms

2)what is the purpose of this piece of code and how to get this values from example of http://www.picbasic.co.uk/forum/cont...-DT-interrupts

TMR2 = 16

PR2 = 129

TMR1L = 255

TMR1H = 254

sangaboy

- 7th January 2012, 20:09

thankx a lot HenrikOlsson for your help and to be honest, my aim is to generate 3-phase SPWM using PIC16F877 but I started by I understanding single phase SPWM.

I have read the Microchip appliction notes for sine wave with the 16F series chip..http://ww1.microchip.com/downloads/e...tes/00655a.pdf together with the examples given in http://www.picbasic.co.uk/forum/cont...wave-using-DT- interrupts and http://www.picbasic.co.uk/forum/showthread.php?t=14359.

there are number of things which i've not understand from these readings and i'm asking for help from anyone who can help me to understand.these things are:

1)what is purpose/function of TMR1 in SPWM signals generation using PIC16f877

2) which formular was used to generate a lookup table for the sine waveforms

3)what is the purpose of this piece of code and how to get this values from example of http://www.picbasic.co.uk/forum/cont...-DT-interrupts

TMR2 = 16

PR2 = 129

TMR1L = 255

TMR1H = 254

Powered by vBulletin® Version 4.1.7 Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.