Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Swordfish Questions

Status
Not open for further replies.

mrfunkyjay

New Member
Hello guys,

I found this Swordfish Compiler and I would like to ask you guys, what Swordfish had as its advantage over another compiler like MCC18 C compiler or so? Thanks!

Best regards,

Kelvin Susanto
 
That's probably subjective. It is (in my opinion) a very nice compiler though. I wish Microchip would pick it up and turn it into their official B18 language. They would make sure it functions within MPLAB and I think it might tend to legitimize a well designed BASIC language compiler as a 'professional' development tool.

Mike
 
Last edited:
the thing i recon when I read thru tutorials from digital diy website is... u can just simplify the codes by writing several definitions and thats it. for example setting the pwm duty cycle or freq, a very nice tool but takes time to understand also. correct me if im wrong.
 
I'm a little biased to comment - I'm sure other people will.

> They would make sure it functions within MPLAB...

The current (BETA) version of the compiler has better MPLAB support, particularly with respect to debugging.

**broken link removed**
 
Forgive me if my "mplab integration" comment sounded like a complaint. I did read the recent post on the Swordfish forum regarding improved debug capabilities and it seems MPLAB integration is improving in small steps over time.

I was trying to say that Swordfish is the best BASIC compiler and IDE I've evaluated and tested. Full "mplab integration" is just another "wish list" item like having the ability to "offset" code and vectors from flash memory location 0x000.

Mike
 
Swordfish produces an ASM file which can be used in MPLAB for simulation. I've done this a few times.

I'm going to have to check out the new debug capabilities.

Mike
 
Last edited:
Until Swordfish supports debug I've simply used the UART.BAS module for viewing registers. It's old fashioned but it works.

I use the same method as well Bill, it works great

The only other debug issue I run into is with interrupts, as they can be hard
to calculate how much time you need to service the routine due to code overhead, but the best method I have found is to;

a) Make a separate project to record how long it takes between pulses (rising edge trigger)
b) On your target project, place a High(Signal.Pin) at the start of the interrupt, and a Low(Signal.Pin) at the end of the interrupt

If your timer module is setup to display the maximum time taken as well as an average, then you have a very good idea on just how many cycles it has taken to service the interrupt.


As for the modules/libraries within SF, well, its clean and very structured compared to some interpreted "top-down" PIC Basic compilers out there.

:eek:
 
Hi Spency,

You could also just look at the ASM file and count cycles. I did this the other day with your RGB demo. The Save(0) and Restore commands are pretty costly, using approximately 140 cycles each. I seem to recall you were using somewhere around 23 usecs of the 50 usec interrupt interval which is almost 50% overhead.

Regards, Mike
 
Hi Spency,

You could also just look at the ASM file and count cycles. I did this the other day with your RGB demo. The Save(0) and Restore commands are pretty costly, using approximately 140 cycles each. I seem to recall you were using somewhere around 23 usecs of the 50 usec interrupt interval which is almost 50% overhead.

Regards, Mike

The Save(0) and Restore commands will backup the system registers, and then restore them. I is very costly, but provides a real safety blanket for whatever the target application in the future.

Say your program was doing the following (poor example, just for explanation);

Code:
Interrupt TMR2_Interrupt()
    ...
    mS = mS + 1
    ...
End Interrupt

.
.
.
...
While True
    // Get a new ADC sample
    Result = ADC.Read(0)
    // Scale to volts, factor of 1000
    Result = Result * 5000 / 1023  
    // Display on the LCD, always show 5 characters
    LCD.WriteAt(1,1, Convert.DecToStr(Result, 5))
Wend

If the interrupt occurred during Result = Result * 5000 / 1023 then the system registers will be modified when the interrupt services mS = mS + 1 and your result will not be what was intended when it returns and finishes the algorithm.

Now end uses can use the RGB program with any commands, and not worry about corrupting system registries. Yes there should be a more efficient way to go about this, eg, SF discovers what system registers are in use and only backs up the potential threats, but perhaps in a future edition...

The program was originally written for Erosennin on my **broken link removed** as he also wanted to use the keypad routines to control the color components.
 
Hi Spency,

Thank you for the explanation.

I think I understand what the Save(0) and Restore commands do and when to use them. If you study the ASM code for your ISR in your RGB demo you'll see you don't need to use them in this case.

I wasn't criticizing your code and it's perfectly ok to use the Save(0) and Restore commands since you have plenty of cycles to spare with a 48 MHz clock. I'm just not sure why you'd use them when you don't need to.

Mike

If the interrupt occurred during Result = Result * 5000 / 1023 then the system registers will be modified when the interrupt services mS = mS + 1 and your result will not be what was intended when it returns and finishes the algorithm.
None of the system registers are used when your ISR code executes the ms = ms + 1 instruction. None of the system registers or file select registers are used for any of the ISR code in your RGB demo. Do you ever look at or study the ASM code produced?
 
Last edited:
No problems Mike,

This is probably a better example, pulled from the SF library

Code:
// get value function...
function GetValue(pValue as byte) as longword
   result = pValue * pValue * pValue
end function

// some interrupt...
interrupt MyInt()
   dim Value as longword
   Value = GetValue(10)   
end interrupt

This will lead to errors without context saving
 
Last edited:
Poor example on my behalf, but surely system registers such as the status register could be modified with the use of addition? When the interrupt is complete, this could lead to problems with the algorithm within the main program?
Spency,

OMG! You really don't know that the WREG and STATUS registers are automatically saved when an interrupt occurs and then restored when the retfie FAST instruction is executed?

Forgive me. I assumed too much. I thought you told me last year that you were an accomplished assembly language programmer before moving up to BASIC. This does however explain why some of your statements in the previous few posts (and some other statements this past year) seem so far "off base" to me.

Mike
 
Last edited:
Spency,

OMG! You really don't know that the WREG and STATUS registers are automatically saved when an interrupt occurs and then restored when the retfie FAST instruction is executed?

Hence my edit at 11:10am and your post at 11:17am, well now modified to 11:20am - guess you felt the need to include the miss statement :eek:

had a look at the asm and a few things clicked which lead to the edit.

Sorry if it was misleading, I just wanted to create a program that could be used no matter what the future use would be. I use context saving for safety sake with interrupts, and refine it off dependent on the application.
 
Last edited:
Spency,

Like I said, there's nothing wrong with using it. Understanding why and when to use it probably isn't that important either.

Best regards, Mike
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top