Forums > Technical Discussion > Programming PIC's (Project Arclight)

Login/Join to Participate
Page:
anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
(*note to admins: there are several posts about programming, but not a whole thread dedicated to it, so ill post a new one solely for programming PIC's)

Okay. This thread is about programming PIC's. First of all I'll give a small introduction to my new project... after several months of no single bit of progress I started my PIC-poi project all over again, starting at point zero again. But now the hardware is making SERIOUS progress... but I forget pretty much all I new about programming so I need to start it all over again (and this time I wanna learn it GOOD, and I need HELP for that).

Some pictures:


Non-Https Image Link

Non-Https Image Link

Non-Https Image Link

Non-Https Image Link


The design is quite secure (thanks to Epoxy material and a hot glue gun!). Although it makes it look kinda sloppy, it's strong as hell!

The whole lot is running on 4x AAA batteries, providing 4.8 volts. The batteries have 750mah (i need to get my hands on 1000mah AAA batteries, but they are expensive frown )... with 750mah it should run for about 2 to 3 hours i think (considering voltage drops and depending on how much color blending im gonna use and how much strobing).

Furthermore im using a PIC16F627A from microchip and some 16F628A and 16F648's are arriving soon (giving me more memory).

That's about the hardware for now... now about the software.

The reason I started this thread is because I KNOW that several people here have programmed/are programming PIC's (pointing @ Polarity and HyperLight wink )... and I HOPE that there are willing to give me enough support to guide me through the very first basic principles of programming. And this time I wanna do it step by step, so I understand what Im doing!

The first basic program

See the above URL for the program im currently using. First of all before I get to program myself I need to know what everything means. Can any of you be of any assistance? (Looking again to Polarity and HyperLight) In the file linked above I made some notes (which are prolly NOT CORRECT)... It would be wonderful if some could check if I understand it a bit before I start with more complex codes (note to self: first understand what your doing before continuing!)

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
hrm... i can't seem to get at the pics and the asm file...

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Still nothing?

Can't do anything about the Pictures now... hope it's just something temporarily...



Well here's the code at least:

(After the " ; " are my own comments, sometimes preceded by comment written by the writer of the code. It would be lovely if someone could correct them...)









LIST P=16F627A, R=DEC ;????



__CONFIG _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _MCLRE_OFF & _CP_OFF & _INTOSC_OSC_NOCLKOUT & _LVP_OFF ;????



include "P16F627A.inc" ; attaching a 'include file' with instruction for the appropriate chip



;--------------------------------------------------------------------------

; Subroutines

;--------------------------------------------------------------------------



Ram EQU h'20' ; ????

Count1 EQU Ram+0 ; ????

Count2 EQU Ram+1 ; ????



ORG 0 ;reset vector -> going to point zero where it's about to start.

Start call Init ;Initialise hardware -> getting the hardware ready

call StrobeLoop ;Starting the programmed stuff





Init clrf PORTA ;all of porta low -> stopping all input/output from port A

clrf PORTB ;all of portb low -> stopping all input/output from port B

bsf STATUS,RP0 ;change to bank1 -> read the instructions from bank 1

bsf PCON, 3 ;set INTOSC to 4Mhz -> the processor's speed is set to 4 MHZ

clrf TRISA ;all of porta outputs -> blocking input to port A

clrf TRISB ;all of portb outputs -> blocking input to port B

bcf STATUS,RP0 ;back to bank0 -> from now read instructions from bank 0 again

RETURN





DelayRoutine movlw d'255' ;-> the value 255 is put in the workingsregister

movwf Count1 ;give Count1 the value 255 -> value from the instr. reg. is ass. to Count1

DelayLoop1 movlw d'255' ;-> the value 255 is put in the working reg

movwf Count2 ;give Count2 the value 255 -> same as with count1

DelayLoop2 decfsz Count2 ;decrease Count2, if it's 0 skip the next line -> counting from 255 till 0

goto DelayLoop2 ;-> keep looping (so delaying) until above is 0

decfsz Count1 ;decrease Count1, if it's 0 skip the next line -> counting from 255 till 0

goto DelayLoop1 ;-> keep looping (so delaying more) till above is 0. if it is: return all the way to 'start'

RETURN



StrobeLoop movlw B'00010000' ; Set the red bit (pin RB4) to 1 -> means it's opening up the port RB4

movwf PORTB ; Write the value to the port -> ?

Call DelayRoutine ; Wait for a bit -> going to the delay. there it counts some cycles and then goes back

movlw B'00100000' ; Set the green bit (pin RB5) to 1 -> means it's opening up the port RB5

movwf PORTB ; Write the value to the port -> ??

Call DelayRoutine ; Wait for a bit

movlw B'01000000' ; Set the blue bit (pin RB6) to 1 -> means it's opening up the port RB6

movwf PORTB ; Write the value to the port -> ??

Call DelayRoutine ; Wait for a bit

GOTO StrobeLoop ; going a few lines back. meaning it will never stop looping.



END

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
I can see pictures and code just fine here.

I reckon your best bet is to have a read of the fantastic documentation available on microchip's site. This is the document for your PIC. Page 117 onwards will describe all of the commands you have at your disposal. If you're after some more general advice try Hazer's tutorial... those + a bit of advice from a few people when things didn't work are what got me to where I am today.

Looks like you've pretty much constructed my mark I hyperlights there eek

Cake or Death?


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
more importantly, if you want bits of code that you can rip off, try looking at www.piclist.com smile

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
@hyperlight:

I already looked at that tutorial... still it seems beyond my league... but the hardware's mostly finished now (for now) so I can really begin with programming... if I get stuck i think I'll mail you, hyperlight (if that's ok).



@hyperlight again:

and yes... i can say i basically copied your hyperlights. but don't worry, once i get this project really started i will take it somewhere far beyond anything comparible biggrin but i just need a good start, and your hyperlights are a perfect example to copy and try building from there smile



The result of some last minute hardware modifications (and together with that i fixed the last brightness problems ill EVER have!):
Non-Https Image Link






In a few days ill post more codes and my findings!

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Looking very nice indeed smile

Cake or Death?


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
Written by: anonomatos

...but don't worry, once i get this project really started i will take it somewhere far beyond anything comparible biggrin




Since you have no idea how many funky things I have planned, I think that's quite a rash statement to make... but we'll see smile Should be interesting to see what you'll come up with cool

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
It sure is smile I have some funky things planned too smile And I'm getting where I want to... at least with hardware. I just did some serious shopping and started building my second pair of Arclights. This time with ICSP (In-circuit Serial Programming)... which I just got working! Hell yeah! biggrin



But the programming is still lacking behind... gotta start to work on that the next few days!

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Finally im a bit experimenting now with programming smile

But i was wondering... what are the most efficient ways to deal with delays? A very short one (just one instruction) would be a NOP, a bit longer would be with the DECFSZ or INCFSZ command, so it count for one cycle round (256 instruction afaik) and then continues when it reaches zero.

Then what's the best for longer delays (in a code-efficient way)?

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
depends on the circumstance in which you need the delay, you could either use timers or Delay Code Generator

AnApplenewbie
9 posts

Posted:
Hey, looking good.

I program PICs (using basic, I'm too impatient for ASM hehe!). I was planning on doing the same sort of thing, using a row of superbright LEDs in a section of clear rubber tubing, each in parallel so I can experiment with different colour combinations etc.

What are you using for illumination? It looks like you have 1 for each colour?

Thanks
AA.

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Im using (just like mr. hyperlight) 1 watt Luxeon emitters.



Well... i just survived another moment of almost giving up (some SERIOUS issues with my programmer. I ordered a new one now, this old one still works from time to time (with loads of error messages).



Still done some programming. I started making notes on my hardware and software and finally getting to know what I'm doing.



Primary and secondary colors...

(no Pulse width modulation involved yet... but the brightness difference between 1 and 2 colors on isn't horrible)





the result:


Non-Https Image Link


yes, shot in a room with daylight. there are that bright yes! And me likes the pink color ^_^





im going to work on some testcodes with different delays now. From very short ones to bigger delays and see what it'll do smile



And a question:

i have low voltage programming off (LVP_OFF), but I work with ICSP (so it should be ON). Would it matter? It programmes just the same as when I click it in the programmer (with occasional errors, but those has nothing to do with the ICSP).

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
If it works, it works - I wouldn't worry about it. For the record though, ICSP is exactly the same as programming it in a chip. The same contacts are made to the device.

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
I've been playing around with different delays and it's working nicely :-) with 6 different delays in my code, varying from 20ms till about 1second I can get nice effects. From strobes till somethings that look a bit like Hyperlight' 'stutter fades'. And I might be testing around to see if I can combine them (so a color going strobing, then strobing faster, then strobing with a different color mixed through, en then strobing slower till the second color is pure).

But I'll just keep playing around. :-)



Anyways, I can only get 6 colors now, and I'm triying to get more (by dimming lights). I guess the only way to do that is by Pulse Width Modulation. I've been looking in at least 5 tutorials to see if I can understand it, but they all have a totally different idea of PWM.



As far as I have filtered out, this will be the basic thing divided in steps:

1. Assign value to 'Value1'.

2. Turn LED on.

3. Check if value of 'Count' is above 'Value1'

4. No: do nothing (LED stays on).

5. Yes: turn off LED.

6. 'Count' = 'Count' +1

7. Jump to point 3.



I guess this should give me a certain constant brightness. But I have no idea how to compare certain values? I'm reading the instruction list in the data-sheet and I'm clueless what command to use.

I read somewhere a thing about setting a Z-flag after a certain amount of cycles and then checking it each time. When the Z-flag is set the next instruction is skipped (so jumping out of the loop). But this still leaves me clueless about the fact that it should stay off the rest of the 256 cycles to appear only partly bright...



*cracking head over PWM*

Can someone give me a bit of a hint on this thing?

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
EDIT: Ah i just reread your post, i think i got it all wrong.... i'll retype somethign when my brain is working properly (assuming no one else replies first). though instead of pwm, you might want to try bit angle modulation. it seems to use less programming overhead than pwm though it might cause some problems depending on how you implement it and how fast your hardware is running.



if i understand you correctly,



2 ways of doing the count is one, subtract the number of counts/cycles/loops you have gone though from the number of counts/cycles/loops want and return the data to W. then something like:

btfsc STATUS,Z

goto someLabel

--more code here--



btfsc = Bit Test F____ Skip if Clear.

STATUS,Z = if last operation returned a zero, bit is set.

so in otherwords, if the last operation (number of counts wanted - number of counts elapsted) equals zero, then it'll skip the "goto someLable" line and continue after that, otherwise it goes to the line indicated by the goto.





or other way is to set your counter to the number of counts you want and countdown with something like



decfsz counter,F

goto someLabel

--- more code---



i think decfsz gets complied as:

decf counter,F

btfss STATUS,Z



so there's no performance benifit for using decfsz except that it seems to make the code easier to read (for me at least).
EDITED_BY: The Misguided Oracle (1136471344)

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
I just wanna make more colors smile and im trying to find a way (possible throught PWM by dimming certain colors) to do that. Im trying to work my way to a smooth rainbow fade, see?

Ill just wait for your reply when your brain works OK :-p

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
PWM test 1



The code is VERY messy. BUT IT WORKS! I just dimmed a 2 lights smile now I need to make this code a little more elegant...

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
i just got back, sorry, brain not working still frown 9.5hrs of work + copious amounts of alcohol after doesn't help methinks.

this might be useful https://www.piclist.com/techref/microchip/pwm.htm
more stuff on pwm...

actually, www.piclist.com has been one of the best sources of info for me when i was trying to learn pic programming.

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Keeping a light dimmed is no longer a prob.

Point is, I try to increasing the brightness slightly. But this doesn't work... this the code i've been using:

Pulse Width Modulation test 3

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Little baby step by baby step im getting there.



With this code I can now increase the brightness slightly:

PWM test, yet again



if anyone has tips. please post/pm it :-)

(though i know hyperlight is away for a week, misguidedoracle is drunk and i haven't seen polarity in ages around this thread, but still).



I keep on programming :-)



and a little vid. yes... this took me days to figure out! it's far more complicated than it looks eek



*edit*

with a little more programming im working now on color blending. what you see here is the effect of pulse width modulation, this time 2 colors at about 50% on each (which means it'll flash VERY fast... not visible to the naked eye, only on a photo!). The processor is kinda busy though, working on 1 million instructions every second!




Non-Https Image Link

EDITED_BY: anonomatos (1136757885)

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
well, I don't have much for tips, but here's something that would save you one instruction smile

where you have:
movlw B'00000000'
movwf PORTB

you should be able to change that to:
clrf PORTB

other than that, brightness, would be down to your hardware i reckon. since you're pulsing it, you could in theory run the LEDs at higher than it's rated current, though problem with that is you'd have to find some way of not letting them burn out when it's not pulsing

Not too sure if i can dispense more advice (i've only started to learn pic programming & electronics in oct/november and still haven't even started on my 2nd prototype yet)

RobertBruceGOLD Member
member
63 posts
Location: Montreal, Quebec Canada


Posted:
How about writing a visualizer... (I know that it is fun to mess with ASM but...) a program that lets you design the effects you want and generates the ASM code, compiles and also sends the program to the programmer. This would be handy for creating endless effects... if you use a matieral to nicly blend and absorb the LED colors you could make many RGB colors and also amazing effects. I can try and build a simple prototype in VB(easy and quick) and DirectX to make a realistic "Poi Circle" that you can adjust parameters live untell the desired effect is achieved then it will out put a text file or log with the ASM code. smile Just an idea.

Robert Bruce
Poi Geek, Technologie Freak. Montreal, Quebec Canada


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
I've actually did that with my pov-sticks, used flash to read an image and turn it into raw data, stored on the chip's flash mem.

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
I forget to mention it here. But I got it all worked out. I used the SUBWF command the wrong way around, so stupid!

The result:

Rainbow!


Non-Https Image Link


I just love it when a plan comes together smile

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
So how's it going anon? I've been busy working on the next (and possibly final) hyperlight prototype!

Cake or Death?


anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
Thanks for asking!

Project Arlight is going well :-)



My Arclight-poi haven't changed much design-wise, only a tad bit smaller (3 inch diameter). But I've developed my program much, much further. I managed 750+ colours for strobing effects for instance and some sort of what you call 'stutter-fade' with lots of colors. My way of programming is far more efficient now. It's like:

Call Shade XX

Call Length

Call Delay



Which will program a certain color for a certain time and then delays for a certain time, etcetera.



And best of all, I've created a RGB Arclight-staffs. Containing 24 leds total (8 red, 8 green, 8 blue) powered by 4aaa batteries and a 16F648a chip.

Believe it or not, they are virtually indestructable... I threw them 30 feet in the air a dozen of times, came bouncing back and still working!

The only thing is that when it hit something the program will reset (because the batteries are in battery-holders and will stop making contact for a split-second).



I showed 2 Arcstaffs and 2 pairs of Arcpoi (a little show with the 4 of us) at the Dutch Juggling Convention at the open stage and the crowd went nuts ^_^



So, yes. Things are well. I'm too busy to make a handbook for or Blog about my progress, but I DID managed to create a LED-staff that is just BRIGHT and very, very DURABLE. The raw material costs are under 40 dollars and my second staff was finished within 5 hours.



2 examples of patterns (the pictures aren't really good, you can't even see all the 8 sets of 3 LEDs, but you can get the idea):


Non-Https Image Link



Non-Https Image Link

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
Great work!
if only i could muster up the motivation to work on my own glow toy frown

anonomatos, do you mind me asking how you mounted your leds in the staff? i still haven't found a way to do mine that i'm satisfied with (but then i'm trying to put 128 leds into a staff wink assuming i end up getting the motivation to restart the project that is...)

anonomatosGOLD Member
enthusiast
389 posts
Location: Utrecht [NL], Netherlands


Posted:
unfortenately i haven't got my staffs with me (a friend borrowed them for a show in a club... yes, they are quite popular already ^_^ ), so I can't make a picture of the leds. But it's one, long circuit-board with 8 sets of 3 LEDs, each set mounted in a triangle with a blob of glue in between (so the blob gets lit up).



This means that on one side of the staff the light is dimmer because of the circuit-board that's in the way... and a solution to that is to drill holes (on the place where the blob of glue is).



So:

_______________________________________



-0- -0- -0-

---------------------

_______________________________________







The -0- indicating the sets of leds.

The --- indicating the circuit board.

The ___ indicating the tubing.



A picture will come soon enough of the LEDs construction :-) but to keep everyone satisfied till then, a new shot of the light-program:


Non-Https Image Link

"Don’t know how long, this one’s gonna take;
I could fail, but I’d rather be a fuckup, than a fake"


jcrsGOLD Member
the floor is a sea of tigers...
404 posts

Posted:
Ah...
I was planning to do something like that, but instead put LEDs on both sides of the board (since i'm only doing a single colour staff)
How do you find having a long pcb though the whole staff? I'm kinda paranoid of the board constantly beign rattled and flexed, which could eventually lead to some solder joints breaking or something (well, i was thinking of that since i tempted to use smd leds which means i don't have to hand drill 128 * 2 holes for the leds)

*HyperLightBRONZE Member
old hand
1,174 posts
Location: Great Malvern [UK]


Posted:
128 holes isn't an enormous amount.. c'mon, be a man wink

Cake or Death?


Page:

Similar Topics

Using the keywords [programming pic * project arclight] we found the following existing topics.

  1. Forums > Programming PIC's (Project Arclight) [38 replies]

      Show more..

HOP Newsletter

Sign up to get the latest on sales, new releases and more...