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.

converting from Swordfish to Assembly

Status
Not open for further replies.

MrDEB

Well-Known Member
I have a PWM circuit and code for a 18F1320 BUT a smaller PIC would be more cost effective.
How does one convert from swordfish to assembly or ?? using a smaller cheaper PIC.
need 3 PWM outputs.
 
Which PIC do you plan to use, none of the smaller than 8pin devices have hardware PWM. If you're planning to use a 12F series and the PWM is slow enough you could do 3 channel in software.
 
Anything smaller and cheaper than an 18 pin PIC
right now I am using an 18F1320.
See my link to Neckerchief on fire for finale result of project prototype.
will post code in few miniutes need to locate.
 
swordfish code I am using

it works very well for a flickering flame effect.
changing the randomval creates different effects.
Code:
}
Device = 18F1320
Clock = 8

//Include "IntOSC8.bas" 
Include "RandGen.bas"
Include "Utils.bas"
//Include "ADC.bas"                   // Include the ADC.bas library
 #option AD_RESIST = 800000 //11XXXXXXXX

 Include "InternalOscillator.bas" //22XXXXXXXXX
 Include "ADC.bas"        //33XXXXXX
 Include "MinADtime.bas"  //44XXXXXXXX

//Dim LED As PORTB.3                  // Declare the LED pin turns on transistor
Dim LED0 As PORTB.0, LED1 As PORTB.1, LED2 As PORTB.2, LED3 As PORTB.3//55XXX 

//OSCCON = %01110110                 // Setup the internal OSC for 8Mhz
 

Dim TMR2IE As PIE1.1,         // TMR2 interrupt enable
    TMR2IF As PIR1.1,         // TMR2 overflow flag
    TMR2ON As T2CON.2,        // Enables TMR2 to begin incrementing
    Signal_Pin As PORTA.3     // Signal output to frequency meter
 
Dim Red_Pin As PORTB.0,
    Green_Pin As PORTB.1,
    Blue_Pin As PORTB.2,
    Red_Duty As Byte,
    Green_Duty As Byte,
    Blue_Duty As Byte,
    Red_DutyVal As Byte,
    Green_DutyVal As Byte,
    Blue_DutyVal As Byte,
    RandomVal As Byte
   
 
Dim uS As Word,
    mS As Word           
 Const DarkVal = 512 //XXX

 Function Get_ADC_Sample() As Word       //2xx Function to grab the ADC sample
   Result = ADC.Read(0)                 //3xx Grab an ADC sample from channel 0
 End Function                            //4xxxx

 //ADCON1.0 = 0                            //5xxx Configure AN0 as analogue
  
Interrupt TMR2_Interrupt()
    High(Signal_Pin)
    Save(0)                   // Back up system variables   
    If TMR2IF = 1 Then        // Check if the interrupt was from TMR2   
        TMR2IF = 0            // Clear the TMR2 interrupt flag
        uS = uS + 50
        If uS >= 1000 Then
            uS = uS - 1000
            Inc(mS)
        EndIf       
        Inc(Red_DutyVal)
        Inc(Green_DutyVal)
        Inc(Blue_DutyVal)
        If Red_DutyVal > Red_Duty Or Red_Duty = 0 Then
            Red_Pin = 0
        Else
            Red_Pin = 1
        EndIf
        If Green_DutyVal > Green_Duty Or Green_Duty = 0 Then
            Green_Pin = 0
        Else
            Green_Pin = 1
        EndIf
        If Blue_DutyVal > Blue_Duty Or Blue_Duty = 0 Then
            Blue_Pin = 0
        Else
            Blue_Pin = 1
        EndIf               
    EndIf                     //
    Restore                   // Restore system variables
    Low(Signal_Pin)
End Interrupt
 
Private Sub TMR2_Initialize()
    TMR2ON = 0                // Disable TMR2
    TMR2IE = 0                // Turn off TMR2 interrupts   
 
    PR2 = 149                 // TMR2 Period register PR2
    T2CON = %00000001         // T2CON 0:1 = Prescale
                             
 
    TMR2 = 0                  // Reset TMR2 Value   
    TMR2IE = 1                // Enable TMR2 interrupts
    TMR2ON = 1                // Enable TMR2 to increment
    Enable(TMR2_Interrupt)
End Sub
 
// Start Of Program...
Low(Red_Pin)
Low(Green_Pin)
Low(Blue_Pin)
Red_Duty = 30
Green_Duty = 0
Blue_Duty = 0
Red_DutyVal = 0
Green_DutyVal = 0
Blue_DutyVal =0
 
uS = 0
mS = 0
 //Function Get_ADC_Sample() As Word       //2xx Function to grab the ADC sample
 //  Result = ADC.Read(0)                 //3xx Grab an ADC sample from channel 0
 //End Function                            //4xxxx

 ADCON1.0 = 0                            //5xxx Configure AN0 as analogue
RandGen.Initialize(128)       // Initialize the Random Number generator
TMR2_Initialize               // Setup and enable TMR2
 
While True                    // Create an infinite loop
 If Get_ADC_Sample > DarkVal Then     //7xxx Monitor for change
 
 
 
 
    RandomVal = RandGen.Rand  // Grab a random number from 0 to 255 
   
             Red_Duty =RandomVal-25 
             
           
            
       
            If Red_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Red_Duty)
            EndIf
      
             Green_Duty =RandomVal-20 
             
            If Green_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Green_Duty)
            EndIf
     
             Blue_Duty = RandomVal-30
             
            If Blue_Duty > 0
              Then  mS = 0
                Repeat
                Until mS = 19
                Dec(Blue_Duty)
            EndIf
              Else                                //8xxx
        Low(LED0)
        Low(LED1)
        Low(LED2)
        Low(LED3)
    EndIf    //9xxxxxx
Wend         //10xxxxxx
           
         End
 
You could convert it to the free BoostBasic and compile it for a 16F628A ($1.70). However the 18F1320 is only $2.90 - is it worth the $1.20 saving?

Mike.
 
I have a PWM circuit and code for a 18F1320 BUT a smaller PIC would be more cost effective.
How does one convert from swordfish to assembly or ?? using a smaller cheaper PIC.
need 3 PWM outputs.

hi,
If you look in the folder where the swordfish basic resides, after you have compiled the basic file, you will find the assembler listing.
 
I found an 8 pin circuit w/ code on INSTRUCTABLES late last night BUT the file is a RAR which I can't open. I can't even find the artical again but have the download.
The 1320 @ Mouser is $3.24 in an ssop package. Its smaller than the 18 pin dip. The SMD resistors are .50+ per. If to much trouble (seen some of the other candle simulations, pretty lame) then maybe just stick with the 18F1320 in the ssop package and surface mount some 1/8 watt resistors etc. Entire unit gets epoxy covered anyway.
Besides the unit I built has 3 LEDs, 2 yellow and one red.
I have a board kinda designed for the surface mounted resistors etc using the 1320.
Kinda sounds like I am bailing on using a smaller PIC but I like the effect better.
 
hi D,

Download the free unzip: its unzips almost everything, so watch out for your flies.!:rolleyes:

**broken link removed**
 
Thanks Eric for the download
Looked at file and it is pretty lame.
Only one LED
Will relook at the SMD resistors. I guess I looked at the wrong ones.
 
Is a total rewrite worth the trouble?
I wish I knew more about code writing. Just getting comfortable with Swordfish.
The 16F505 looks promising BUT a total rewrite is involved.
gonna have to think about this.
Tonight I am wearing my protype to awards dinner. LOTS of scout leaders will be present.
At present , using an SSOP pkg PIC and SMD passive componets plus a circuit board = $6 more or less.
add 30% profit margin plus 10% for shipping costs to get parts in my hands.about $10 per unit.
 
If you think there's any chance at all that you might be doin' things with the 8 or 14 pin devices with a 14-bit core then you owe it to yourself to start learning one of the C languages.

Swordfish BASIC is by far the best BASIC language I've come across but (1) it limits you to 18F' devices, and (2) it's BASIC. I don't have anything against BASIC but unfortunately it's not considered "mainstream".

You shouldn't have too much trouble converting BASIC program statements into C statements though there will be a learning curve. Why not download the free/lite versions of BoostC and check it out?

Kind regards, Mike
 
If you think there's any chance at all that you might be doin' things with the 8 or 14 pin devices with a 14-bit core then you owe it to yourself to start learning one of the C languages.

Swordfish BASIC is by far the best BASIC language I've come across but (1) it limits you to 18F' devices, and (2) it's BASIC. I don't have anything against BASIC but unfortunately it's not considered "mainstream".

You shouldn't have too much trouble converting BASIC program statements into C statements though there will be a learning curve. Why not download the free/lite version of BoostC and check it out?

Kind regards, Mike
 
If you think there's any chance at all that you might be doin' things with the 8 or 14 pin devices with a 14-bit core then you owe it to yourself to start learning one of the C languages.

Swordfish BASIC is by far the best BASIC language I've come across but (1) it limits you to 18F' devices, and (2) it's BASIC. I don't have anything against BASIC but unfortunately it's not considered "mainstream".

You shouldn't have too much trouble converting BASIC program statements into C statements though there will be a learning curve. Why not download the free/lite versions of BoostC and check it out?

Kind regards, Mike

Wholeheartedly agree.

Mike.
 
Will give it a go as I have my second computer working. Still need to figure out how to use MPLAB and get the Junebug configured better. Right now I need to COMPILE, PROGRAM 2 times before the hex file shows up to use Junebug to program the PIC. It works but not smoothly.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top