Got sidetracked about using ASM
Moderators: Chuckt, Garth, bitfogav
Re: Got sidetracked about using ASM
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?
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 

-
- 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
i MAY HAVE COME UP WITH A CLUNKY BUT MAYBE SOLUTION? uSING THIS CODE
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.
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
- brad
- 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
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:
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)
-
- 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
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
http://youtu.be/lrrloL-reUI
Re: Got sidetracked about using ASM
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 

-
- 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
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
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
- brad
- 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
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.
-
- 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
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
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
- brad
- 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
Have you had a look at this page on digital-diy?
http://digital-diy.com/swordfish-exampl ... a-pwm.html
http://digital-diy.com/swordfish-exampl ... a-pwm.html
-
- 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
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.
need to rtecheck board and maybe change out the pic.
Re: Got sidetracked about using ASM
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.
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.
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.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
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
-
- 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
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.
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
- brad
- 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
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:
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
}
-
- 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
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.
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.
- brad
- 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
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!
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!
Who is online
Users browsing this forum: No registered users and 3 guests