Sinewaves using interrupts.


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Hi Henrik,

    thanks for the info (& the link to your thread - I'll read it tonight as it's not exactly a quick 'snappy read'!) - just to clarify, I'm using scalerobotic's code ....so anything declared as ASM, PBP etc...at this stage of my 'pic programming for dummies' learning curve.....blissfully washes over me! (in my naive programming world, I'm still convinced the earth is still flat & if you sail towards the horizon, you will fall off over the end)

    I've already picked up that when using ASM interrupts, that you have to be careful what you get up to in the interrupt handler (ie get in, get out asap - handle the stuff in your main code), but I've no intention of doing much in there (bar the odd port toggle to assist with scope observations!)

    Re generating sine waves - I've actually a couple of AD9835 ICs winging their way over the North Atlantic to me as I type - they seem to be a rather quite serious way of generating sine waves! (but while waiting I thought I'd have a dabble with this PWM method, just to start getting up to speed in the black art of Sinewaveology!)
    Last edited by HankMcSpank; - 1st October 2010 at 13:43.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default

    Hi,
    It's not just get in get out, I'm afraid.

    PBP has a bunch of internal system variables that it uses for its needs. If you use DT-INTS and declare the handler as an ASM type handler DT-INTS doesn't save those internal system variables before entering the ISR beacuse you told it the ISR is written in ASM. (Which doesn't use PBP's system variables). But in this case the handler IS written in PBP even though it's declared as ASM type so you need to be very careful.

    It means that if that main program is in the middle of a calculation (or HSEROUT or a anything) that happens to use one or more of the system variables when the interrupt occurs AND the code in the handler ALSO need to use these variables you're pretty much screwed.

    I've only looked at this briefly but this particular handler...
    Code:
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 32
        toggle PortB.4 
     
    @    INT_RETURN
    ...seems to use system variable T1 so IF your main code happens to use a PBP statement that also needs T1 it's going to be a mess.

    Now, your main code (at least the one you posted) is a simple Pause and Goto and it does not seem to use T1 so you get away with it. Once you add code to the main routine that needs T1 it'll start acting up.

    It is possible to do what is being done here by carefully examining the generated code for the interrupt handler to determine which PBP system variables it uses and then save and restore only those variables.

    I hope that makes SOME sense.

    /Henrik.

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