Changing the sines frequency?


Closed Thread
Results 1 to 33 of 33

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Hi,
    1) What's the width of the pulses? Not the time between them but the width?
    2) What's the value stamped on your x-tal?
    3) The timing calculations that I provided are based on the fact that your chip is SUPPOSED to run at 40MHz, if it's not running at 40MHz then the timing will be wrong and the interrupt frequency will wrong as well.
    4) Please don't quote the complete message you're responding to. It clutters the thread and it gets hard read because everything is quoted all the time - that's my personal view.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    The pulses are very very thin :



    The width of a pulse is 4,4µs.

    Of course the crystal is stamped at 40MHz, I've difficulties with the setup of this timer, but I hope I'm not an idiot

    The circuit :


  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Of course the crystal is stamped at 40MHz
    Well, then that is likely the problem - or one of them... If you look at page 355 in the datasheet you'll see that the maximum x-tal frequency WITHOUT PLL is 25 MHz and with using the PLL it's 10MHz (resulting in 40Mhz). You're trying to use 40Mhz which is out of specs in both cases.

    The fact that your pulses are 4.4us wide while mine are 3us means that your chip is running way SLOWER than mine while in fact it "should" be running twice as fast.

    Get the oscillator sorted and verify that the PIC is running at the speed you think. One way to do that is a simple program like:
    Code:
    DEFINE OSC 20    'Don't forget to DEFINE the correct OSC speed.
    TRISB.0 = 0
    Main:
      PortB.0 = 1
      Pause 1
      PortB.0 = 0
      Pause 1
    Goto Main.
    If you DON't get a 500Hz signal with 1ms wide pulses the chip isn't running at the correct and/or DEFINE'd oscillator speed.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Okay, sincelery I'm quite new with the PICs, so I doesn't know this "problem" (in reality is not a problem).

    I'll try to find a slower crystal tomorrow.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Okay, so I've unsoldered an 8MHz xtal (not an 10MHz unfortunately) on a old board, and I connected this one to the PIC.
    I've enabled the PLL, so my PIC clocks at 8*4=32MHz.

    On the oscilloscope, I get now a 2µs pulse, it's a little better.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Now it seems to run properly - finally.

    In order to make the calculations of the preload value match your new (32MHz) oscillator speed you need to change the Dummy2 value from 10000 to 8000.

    Then keep the same test code in the interrupt service routine and try with InterruptFrequency = 10800, check the scope, there should now be pulses at 10800 or likely a little bit slower.

    The reason it's not 10800 exactly is, again, due to time that the timer is actually stopped while reloading it. To tune it simply tweak the +1 in the following line:
    Code:
    TimerReload = 65535 - TimerReload + 1
    Try +12 or something and see what happens.

    Then try adding code to your interrupt, not all at once, add it in little by little and keep an eye on the scope. If you start to see jitter or "missed" pulses then you're "overloading" the PIC - ie interrupting to fast. Keep the code in the ISR as tight and short and possible. Think thru it, is there any other way to achive this or that to make this execute faster. Every cycle counts here. Verify with the scope, the pulsewidth shows the execution time of the ISR.

    Trying to make a 3-phase inverter when you're new to PICs are quite a challange - as you probably/hopefully know by now - take baby steps.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Hurray, now I got something who works flawlessly.

    I've played with the dummy values (Dummy2=8745 and Dummy3=100), now I get the exact sines I want.

    For 1200 for example (120*10=120.0Hz), I get 120Hz, for 500 (50*10=50.0Hz) I get 50Hz, for 357 (35.7*10=35.7Hz) I get 35.7Hz...

    So now it works, I can go ahead in my project.

    Thanks a lot Henrik for your help and your support.

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