Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 30th May 2008, 12:52 PM   (permalink)
Default Swordfish Questions

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
__________________
When NewBee asks...
mrfunkyjay is offline   Reply With Quote
Old 30th May 2008, 01:18 PM   (permalink)
Default

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 by Mike, K8LH; 30th May 2008 at 01:24 PM.
Mike, K8LH is offline   Reply With Quote
Old 30th May 2008, 01:21 PM   (permalink)
Default

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.
__________________
When NewBee asks...
mrfunkyjay is offline   Reply With Quote
Old 30th May 2008, 07:08 PM   (permalink)
Default

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.

http://www.sfcompiler.co.uk/wiki/upl...ebug/mplab.gif
David Barker is offline   Reply With Quote
Old 30th May 2008, 10:25 PM   (permalink)
Default

I think Swordfish BASIC is hands down the best PIC BASIC compiler / IDE I've ever used. It's not a sloppy mess like MS BASIC.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 30th May 2008, 10:43 PM   (permalink)
Default

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
Mike, K8LH is offline   Reply With Quote
Old 30th May 2008, 10:48 PM   (permalink)
Default

Until Swordfish supports debug I've simply used the UART.BAS module for viewing registers. It's old fashioned but it works.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 30th May 2008, 11:01 PM   (permalink)
Default

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 by Mike, K8LH; 30th May 2008 at 11:02 PM.
Mike, K8LH is offline   Reply With Quote
Old 30th May 2008, 11:17 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics View Post
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.

__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Old 30th May 2008, 11:46 PM   (permalink)
Default

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
Mike, K8LH is offline   Reply With Quote
Old 31st May 2008, 12:22 AM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH View Post
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 help forums as he also wanted to use the keypad routines to control the color components.
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline   Reply With Quote
Old 31st May 2008, 12:53 AM   (permalink)
Default

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

Quote:
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 by Mike, K8LH; 31st May 2008 at 01:04 AM.
Mike, K8LH is offline   Reply With Quote
Old 31st May 2008, 01:07 AM   (permalink)
Default

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
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 31st May 2008 at 01:10 AM.
gramo is offline   Reply With Quote
Old 31st May 2008, 01:17 AM   (permalink)
Default

Quote:
Originally Posted by gramo View Post
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 by Mike, K8LH; 31st May 2008 at 01:21 AM.
Mike, K8LH is offline   Reply With Quote
Old 31st May 2008, 01:22 AM   (permalink)
Default

Quote:
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

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.
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net

Last edited by gramo; 31st May 2008 at 01:24 AM.
gramo is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Swordfish SE Question lclark Micro Controllers 11 2nd May 2008 03:06 PM
Unicorn + Swordfish + DS1820 Pommie Micro Controllers 10 27th February 2008 10:34 PM
Swordfish DS1307 Example gramo Micro Controllers 4 28th June 2007 11:48 AM
Swordfish - Structures gramo Micro Controllers 0 10th May 2007 12:21 PM
Swordfish Example gramo Micro Controllers 0 4th May 2007 02:09 PM



All times are GMT. The time now is 11:30 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.