sinusoidal PWM


Results 1 to 40 of 84

Thread: sinusoidal PWM

Threaded View

  1. #35
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi,

    First of all, please don't post the same question in several threads. It makes it really hard for people to help you then when someone answers in one thread and someone else in the other. It gets impossible to get the whole picture then.

    Second, when posting code put it in between code-tags so it shows up in a scrollable window instead of just cut and paste it.

    Right, your code then...
    1)
    Code:
    TMR1L = 255
    TMR1H = 254
    This doesn't make much sense, all it does is cause an interrupt after a single cycle. The timer reloading is done in the ISR so just remove those two lines.

    2) It's best to stop the timer before reloading it as it can otherwise overflow between writing to the low and high byte. Even better is to stop it and then ADD the calculated reload value to the timer register as this will account for the otherwsie lost time that occurs when entering the ISR.

    3) You have two index variables pointing into the the array (StepCount and StepCount1). To get the phase shift you need to start at different places in the SIN-table, if you don't the phases will be "in sync".

    4)
    Code:
    if stepcount = 36 then stepcount =0
    if stepcount1 = 24 then stepcount1 =0
    stepcount = stepcount +1
    stepcount = stepcount1 +1
    Here you have three problems.
    4.1) There are 36 entries the table, numbered 0-35. Because you are incrementing your pointers AFTER you check if it's 36 you're actually trying to ACCESS sinval[36] which isn't that good since it doesn't exist. Swap that around so that you increment the pointer FIRST then check if its beyond the boundry of the array.

    4.2) You reset stepcount1 to 0 when it reach 24 so you won't get a full cycle out of it. It needs to get to 36 and then be reset but again, you need to "start" it at 12 instead of 0.

    4.3) If you look at the last two lines of your code above you never actually increment StepCount1.

    Start by fixing that and see what happens. May I also suggest you toggle an output or something in the ISR to verify that you've got the correct interrupt frequency.

    /Henrik.
    Last edited by HenrikOlsson; - 12th February 2012 at 13:08.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts