Got sidetracked about using ASM

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Got sidetracked about using ASM

Post by bitfogav » Thu Nov 28, 2013 4:18 am

Just has a note the PWM module in Swordfish only supports 2 PWM channels, the rest will have to be coded by yourself.

http://www.sfcompiler.co.uk/wiki/pmwiki ... hUser.PWM2

How many PWM channels do you actually need on one microcontroller?
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Thu Nov 28, 2013 6:23 am

i MAY HAVE COME UP WITH A CLUNKY BUT MAYBE SOLUTION? uSING THIS CODE

Code: Select all

Device = 18F2420
Clock = 8

Include "InternalOscillator.bas" 
Include "RandGen.bas"
Include "Utils.bas" 
  Const led(30) As Byte = (%11111100, %11111100, %11111100, %11111100, %11111100, %11111011, 
                           %11111000, %11111100, %11111100, %11111100, %11111100, %11111011, 
                           %11111100, %11111100, %11111000, %11111100, %11111100, %11111011,
                           %11111100, %11111100, %11111100, %11111100, %11111100, %11111011, 
                          %11111100, %11111100, %11111100, %11111000, %11111100, %11111011 )
   Dim INDEX As Byte 
   Dim x As Byte
    Dim LED1 As PORTA
    
    Dim RANDONVAL As Byte
   Sub flicker()
   'DIM X AS BYTE
        For x = 0 To 29
        RANDONVAL = RandGen.Rand
        PORTA = led(x)
        DelayMS(RANDONVAL)
        Next
    End Sub
    ' START OF PROGRAM
  INDEX = 0   
 TRISA = %00000000     
SetAllDigital
RandGen.Initialize(255)    
    While true 
          flicker
         'LED1 = %00000111
         ' DelayMS(100)
          'LED1 = %00000011
          'DelayMS(100)
   
    Wend
    
iT IS VERY CLOSE BUT JUST NEED TO ALTER/ ADJUST / TWEEK THE BITS. But thinking of adding PWM to the anode of the RGB via one mosfet then the bits will change color and the PWM will change led intensity hopefully. Need to play with this idea as I just got back from the dump (cleaning out the shop of 3 layers of mess.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by brad » Sat Nov 30, 2013 10:13 pm

It looks like that code would pretty much give you a random-ish flicker. do you need an array of 30 bytes though?

What if you also made the data from the array random?

I can't remember how to set the min and max values for the random number generator (I.E. 0 to 29) because I've been using Arduino for many months now! how about something like this:

Code: Select all

PORTA = led(RandGen.Rand)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Sun Dec 01, 2013 12:32 am

Well I have been hacking at fine tunning and think I have results but maybe insert less blue for more amber color. Using my first posted code but still going to fine tune the last posted code using the CONST array and a random number generator
http://youtu.be/lrrloL-reUI

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Got sidetracked about using ASM

Post by bitfogav » Sun Dec 01, 2013 3:06 am

Little Ghostman has pretty much answered your questions here http://www.electro-tech-online.com/thre ... 22.139118/
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Sun Dec 01, 2013 3:44 am

I added several resistors to dim the blue and some green as suggested. The resistors really helped.
I am still under the impression that using the code I posted using the CONST array is a simpler approach but will look further into it but for now I am going with what the video shows.
After adding the hot melt glue on top it should look pretty life like IMO

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by brad » Sun Dec 01, 2013 8:50 pm

Now that I think about it, I have seen others make candles where they have multiple LED's in them and the LED's flicker at different brightnesses to give the illusion of a flame moving due to a bit of a breeze.

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Mon Dec 02, 2013 12:50 pm

Using a color chart that Jonsea posted over at Electrotech I tried using the hex, converted into a percentage of full on = 255 using delayms for amopunt of on time but tis didn't work real well. I tried using the percentage as the delayms amount.
Back toi the drawing board and work with actual PWM but I need three outputs unless I drop 2 transistors or 2 mosfets in the circuit.
Going to bed and mull over options

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by brad » Mon Dec 02, 2013 8:00 pm

Have you had a look at this page on digital-diy?

http://digital-diy.com/swordfish-exampl ... a-pwm.html

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Wed Dec 04, 2013 11:13 pm

Yes I read that piece. Very informative. My problem now is getting the 18F13K22 to be able to write to and run but the Pickit2 says my Vpp is too low. It shows 6.4 - 7.4 at different times.
need to rtecheck board and maybe change out the pic.

Garth
I practically live here!
I practically live here!
Posts: 232
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: Got sidetracked about using ASM

Post by Garth » Sun Dec 08, 2013 3:02 am

I doubt you need a PWM at all. You could feed random 0's and 1's at a fast rate to one pin per LED and follow it with a resistor and capacitor for a filter. That way even an 18-pin PIC could have more independent outputs than a bigger one with four PWMs. I have an audio noise generator that works with a one-bit digital stream, and it filters it.
brad wrote:I would highly recommend going straight for the 18F pics because they don't have the memory paging problems like the 16f's do. The prices are also quite comparable :)
I tried going that route for a recent project, and downloaded their MPLAB X for Linux. (I won't use Windows again, not even to save my job.) It wouldn't install on one computer, and it promptly crashes on the other, so I decided to go back to my old DOS MPLAB that works for the PIC16F's which have just barely enough power for the job. MPLAB X is the only Linux software I've had any trouble with, so I have to conclude that Microchip has no commitment to Linux.

Concerning assembly language though, get a peek at what I've been doing with structure macros, at http://bradsprojects.com/forum/viewtopic.php?f=20&t=797 . It has made assembly programming so much more productive, maintainable, clear, and intuitive.
http://WilsonMinesCo.com/ lots of 6502 resources

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Sun Dec 29, 2013 7:53 am

The posted code I have hacked at dosen't work as well as the PWM code I have written.
Here is what the simple approach looks like. A bunch of flickering on/off. Nothing like a real candle. Jon over at Electrotech suggested some "flickering" LEDs. Don't think so as they to just turn on and off.
Here is my simplistic code that dosen't work as desired but was suggested. I now have transistors driving the LEDs due to the fact the 13K22 only has one PWM module but 4 outputs. Got to watch the current draw per pin.

Code: Select all

{
*****************************************************************************
*  Name    : UNTITLED.BAS                                                   *
*  Author  : [select VIEW...EDITOR OPTIONS]                                 *
*  Notice  : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS]              *
*          : All Rights Reserved                                            *
*  Date    : 11/26/2013                                                     *
*  Version : 1.0                                                            *
*  Notes   :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18F13K22
Clock = 8
Include "osc1322.bas"
Include "RandGen.bas" 
Include "Util1322.bas"   
'Include "internaloscillator.bas"
// alias to port pin...
Dim LED1 As PORTC.5
Dim led2 As PORTC.4
Dim Led3 As PORTC.2
Dim INDEX As Byte 
Dim x As Byte
Dim RANDONVAL As Byte    
     


// main program...
 

  

  Const led(6) As Byte = (%00100000, %00110000, %00100000, %00100000, %00100000, %00110000) 
                         
   ' Const led(2) As Byte = (%00100000, %00010000)
  
    ' START OF PROGRAM
Output(LED1)         ' portb.6 pin 11 BLUE
Output(led2)         ' portb.5 pin 12 RED
Output(Led3)         ' not connected yet port c.2 pin 14  GREEN      
    
  INDEX = 0   
 TRISC = %00000000     
SetAllDigital
RandGen.Initialize(255)    
    While true 
        for x = 0 to 5   
            PORTC = led(x)
            DelayMS(80)
            PORTC = led(x)
            DelayMS(3)
        next
      Wend
         
    
  
   
         
   
    

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by brad » Thu Jan 02, 2014 12:56 am

I guess one thing to note is that candle flames are just a single color, so you won't really achieve the effect your after with RGB's.

I did find some code though where someone has done a similar thing with a single LED programmed in Arduino:

Code: Select all

/*
  LED Candle
  
  Makes an LED pulse randomly to simulate a candles flame. Takes a series of values and randomly
  generates sets of pulses with varied brightness and frequency within these values.
 
  "by A Green for x2Jiggy.com"
  
 */

int ledPin = 0; // Pin the LED is connected to

int pulseMin = 1; // Minimum number of pulses in each set
int pulseMax = 5; // Maximum number of pulses in each set

int brightMin = 92; // Baseline LED brightness. Cannot exceed 128.

int minDelay = 1000; // Minimum delay between pulse sets (ms)
int maxDelay = 5000; // Maximum delay between pulse sets (ms)

void setup() {                
  
  randomSeed (analogRead (3)); // Randomise
  pinMode(ledPin, OUTPUT); // Sets LED Pin to be an output 
  
}

void loop() {

  // For loop sets the number of pulses and repeats these pulses
  
  for (int x = random(pulseMin, pulseMax); x > 0; x-- ) { 
    
    int bright = 224 - random(96); // Sets a random maximum brightness level for this pulse
  
    // For loop raises the brightness of the LED from minimum to maximum value
  
    for (int y = brightMin; y < bright ; y++) {
     
      analogWrite(ledPin, y);
      delay(3);
      
    }
    
    // For loop lowers the brightness of the LED from maximum to minimum value
    
    for (int y = bright; y > brightMin; y--) {
    
      analogWrite(ledPin, y);
      delay(3);
      
    }
    
    delay(10); // Adds a delay between pulses to make them more visible
    
  }

  analogWrite(ledPin, brightMin);
  delay(random(minDelay,maxDelay)); // Adds a delay between pulse sets
    
}

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by MrDEB » Thu Jan 02, 2014 10:37 pm

Thanks!!
I looked over the code you posted and I can kinda follow what it is doing. I see where BASIC kinda gets into other code languages.
I am still going to play with ASM. using your tutorial. I just need to get time to learn it.
My big hangup is using MPLAB. I feel I just need more seat time.

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Got sidetracked about using ASM

Post by brad » Sat Jan 04, 2014 9:39 pm

Basic and C are really quite similar (in my opinion) If you have programmed in swordfish basic, you should be able to navigate your way through some Arduino (C) code.

I'd love to help you more with MPLAB, but unfortunately I have forgotten a lot of the setup procedure for it since I haven't used it in maybe 3 - 4 years!

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 8 guests