PDA

View Full Version : Old and beyond help ?



DavidFMarks
- 28th November 2008, 23:23
Just returning to PIC programming after a years gap and seem to have forgotten what little I knew. Have just bought the PICkit2 to use in conjunction with PICbasic Pro. Managed (with some difficulty to get them working together and have tried to implement the good old blink program on the 44 pin demo board (PIC 16f887)with the following code:

define osc 4
TRISD = 0
loop: PORTD.0 = 1 ' Turn on LED connected to PORTD.0
Pause 500 ' Delay for .5 seconds

PORTD.0 = 0 ' Turn off LED connected to PORTD.0
Pause 500 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End

All the darned thing does when I compile and program from McS is to fire up the PICKit2 OK and when I hit the Auto imort hex and write file button it programs the thing OK but when I put the power onto the demo board all 8 of the LEDs on port B light. Got a feeling it has something to do with those darned configuration thingies .. Never did really understand those and now the old grey cells are packing up at a rate of knots... I would be very grateful if anyone could indicate what particular piece of stupidity I have perpetrated this time round.. Thanks for your patience folks ....

Darrel Taylor
- 29th November 2008, 00:16
The default oscillator config for the 887 is XT. But it's easy to switch to the internal oscillator without using configs.
Just add OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz.
And clear PORTD before setting TRIS.



define osc 4
OSCCON = %01100001
PORTD = 0
TRISD = 0
loop: PORTD.0 = 1 ' Turn on LED connected to PORTD.0
Pause 500 ' Delay for .5 seconds

PORTD.0 = 0 ' Turn off LED connected to PORTD.0
Pause 500 ' Delay for .5 seconds

Goto loop ' Go back to loop and blink LED forever
End
Tested on my PicKit2 with 887 on the Debug Express board.

DavidFMarks
- 30th November 2008, 10:45
Thanks for that Darrel, works a treat although I am still not quite sure why I need to clear PORTd before using TRIS. It has always seemed to me that there is a real need for a genuine idiot's guide (speaking as a genuine idiot). For instance the PICbasic manual early on gives the usual little blink program but there is no mention of setting up oscillators clearing registers etc. without which it wont work ! Just a thought as I have always felt that mant people are put off learning about a fantastic piece of kit which is a shame as once having got over all these teething troubles the system is a joy to use.
Thanks again
Regards
David Marks

Jumper
- 30th November 2008, 12:11
Hi,

It is good practise to set the PORT to a known state before using the TRIS register to enable the outputs. When the pic starts up the PORT register can be anything so by setting it before we enable the outputs we dont have to sit there looking at our project going up in smoke just becuse the PORT ended up at a random unlucky combination.

/me

DavidFMarks
- 4th December 2008, 16:18
Thanks Jumper I take the point. Now another daft question. In order to get my Christmas "Star of David" working I need three 8 bit ports and was planning to use the 44 pin demo board. Port A.6 and PortA.7 will not work as outputs presumable because they are connected to the crystal . Sinc I am using the internal oscillator can I do anything to make these two pins available as outputs. Incidentally maybe I am going blind but I can't see any reference to the osccal command in the manual.
Cheers

duncan303
- 4th December 2008, 17:55
Hi David

One quick way to always find out what pins can do is look at the graphical pin layout in the datasheet in this case for the 887 on page 6, It shows the osc pins as being multiple use. I might then look on table 1-1 on page 16 and find say RA6/osc2/clkout and the table will describe, as it does here, that this pin can be assigned RA6 (portA 6) or osc1 or clkin. Also gives brief info and again in this case gives a bit more info that RA6 is a TTL CMOS general purpose I/O, Usually these chips are defaulted in their pin configuration but are easily changed, I would then search down to page 45 which confirms how these pins can be used.

I might guess that if you choose the internal osc without a clock_out/in then the pin could become an I/O, so then I might hunt through section 4, I know it might sound boring but once you have read and got a feel for the oscillator module on one chip all the others are very very similar. I have not been following your project and I am just looking in briefly, so I hope I may have helped rather than hindered but I see you have been grappling with the config fuses already.

Don't worry I'm sure you'll get those lights up before Crimbo.

anyway doesn't one only need 12 leds to represent this particular motif :D


__

DavidFMarks
- 4th December 2008, 18:33
Thanks Duncan thats very helpful. Bit of bedtime reading of the data sheet.
This isn't the star of David that rose in the east this is the one that rises in the west then flashes and rotates etc.
Thanks for the info

duncan303
- 4th December 2008, 18:44
this is the one that rises in the west then flashes and rotates etc.


A very secular star that happens to belong to David then, have you envisaged it playing a little tune :p


____

mackrackit
- 4th December 2008, 23:45
Three pins are all you need.
http://www.picbasic.co.uk/forum/showthread.php?t=10200

Not the star of David though...

DavidFMarks
- 5th December 2008, 15:11
Hi
My secular star of David has 16 arms each with 8 hi-brite leds so the easy way (i think) is a matrix which requires 24 I/O pins. Whilst I could use some other Ports it would be nice the way I have set up the 44 pin demo board to use Port A. Two questions now arise:
1. Can I use RA6 and RA7 as outputs if there is a xtal connected across them ( do not know what the DC characteristics of a xtal are)
2. How the devil do I program the 16F887 so that those two pins are available as outputs. I understand that I have to set up the configuration word (register 1) so that bits 2 -0 are 100 which should set the two pins as available for I/O (subject to item 1 ((above)) But what is the syntax for doing this ? I see no rference in the Picbasic manual (or anywhere else) to this. I have looked at examples but cannot figure it out from that. Any advice on this would be appreciated
Cheers

mackrackit
- 5th December 2008, 15:35
1. Can I use RA6 and RA7 as outputs if there is a xtal connected across them ( do not know what the DC characteristics of a xtal are)

No , you will have to use the internal OSC.


2. How the devil do I program the 16F887 so that those two pins are available as outputs. I understand that I have to set up the configuration word (register 1) so that bits 2 -0 are 100 which should set the two pins as available for I/O (subject to item 1 ((above)) But what is the syntax for doing this ? I see no rference in the Picbasic manual (or anywhere else) to this. I have looked at examples but cannot figure it out from that. Any advice on this would be appreciated
Cheers


@__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF

So you did not like the shift registers?

DavidFMarks
- 5th December 2008, 16:46
Hi,
I have set the oscillator to internat but since the crystal is already mounted on the 44 pin board I did not really want to remove it ! .. and yes I dis like the shift register idea but need more time to get my ancient brain around it and to obtain the chips ( Meanwhile Christmas lights are going up all round me !)

mackrackit
- 5th December 2008, 17:14
My board did not come with an external OSC mounted, I assumed yours did not also.

I thought you were asking if the chip was running off the XT could the pins be used as an output.

Is it Monday or something?

DavidFMarks
- 5th December 2008, 17:38
Sorry you are right, there is no crystal (it's my age) I still haven't figured out where the terms in your config expression come from. They are clearly assembler terms of some kind

mackrackit
- 5th December 2008, 18:02
Are you using PM or MPASAM for the assembler?
If you are using MPASAM, ( my choice) goto program files,microchip,mpasamsuite and find the *.inc file for your chip. At or near the end of the file all of the different fuse settings are listed.

http://www.picbasic.co.uk/forum/showthread.php?t=543
Goes into more detail. Pay close attention to Melanie and Mister_E.

If you are still unclear let us know.

mackrackit
- 5th December 2008, 18:03
(it's my age)
How old are you???

Look at my avatar. That is really me :D

DavidFMarks
- 5th December 2008, 23:35
Many thanks for that, Had a quick look at the link ..looks just the thing I wanted, Bit late to study now, bedtime & just got in from g daughters school musical. Age ? put it this way, Faraday hadn't satrted shaving when I got into this game and I aint going to seeing the good old three score years and ten again so its good to be helped by all you patient youngsters ! Thanks again !

DavidFMarks
- 8th December 2008, 16:54
Hi again,
Got the porta I/O proble sorted insofar as i can now switch on any of the a port bits and light an led. Or so I thought, I wrote a program which switched on each bit of the port in turn held it with a pause 500 command and then switched it off and so on. When writing te Christmas star program I wrote simple code tp switch on all of the bits of PortA (they are each connected through Darlingtons to the - line of one of 16 arms (the other 8 are driven from portc by identical code (other than the port id). Now what happens is that only pins 4 6 and 8 remain high (leds lit). I have now written a separate little piece of code to test it. If I switch each pin on in turn pausing between each one (but not switching them off ) then led 0 switches on and after the specified delay it switches off and the next one comes on. only when I get to pins 4 6 and 8 do they stay switched on. Another curiousity which may be a clue is that when I compile and program the pickit2 comes on with a lower Vdd(about 3.8 and I have to turn it up again. I have also removed the darlingtons so there are only leds an port A but it has made no difference. If anyone can spot whatever my latest stupid mistake is I would be very grateful. BTW the reason I could'nt originally use pins 6 an7 was that [I] had my knickers in a twist thinking I was programming with MPASm when in fact I was using the default !!

Archangel
- 8th December 2008, 18:32
Hi David,
Let's have a look at your code, and schematic, if you don't mind. What is wired on those ports (as leftover from the demo board's orig.) ? Anything?

DavidFMarks
- 8th December 2008, 21:52
Hi
Before I post the code I seem to remember that there is a particular etiquette for including code in a post but I can't find any reference to it. Just thought I'd ask as I dont want to upset folk . Thanks

mackrackit
- 8th December 2008, 22:59
Code tags work well.
http://www.picbasic.co.uk/forum/misc.php?do=bbcode#code

Makes thing a little more readable.

DavidFMarks
- 9th December 2008, 01:01
Thanks for that.

My original circuit had three octal darlingtons (ULN 2803) with inputs directly coupled to Ports A, C and D I have also connected leds with 680ohms to each pin so that I can see what the ports outputs are. A test program switched on and off each led in turn thru ports D C and A in that order and worked OK. Problem arose when tryin to switch on all of the A port bits and leave them on. I have now disconnected ther darlington from port a and written the following simple test program:


@ DEVICE pic16f887,intrc_osc_noclkout


PORTD = 0
PORTA = 0
PORTC = 0
TRISD = 0
TRISA = 0
TRISC = 0
portA.0 = 1
pause 500
porta.1 = 1
pause 500
porta.2 =1
pause 500
porta.3 = 1
pause 500
porta.4 = 1
pause 500
porta.5 = 1
pause 500
porta.6 = 1
pause 500
porta.7 = 1
end


I have just run this program and
1. When Microcode studio fired up the Pickit2 the voltage Vdd had been set down to 3.3
2. I turned up Vdd to 5 volts and programmed the chip.
LEDs 0,1,2,3 tuswitched on and then off after the delay. LED 4 switched on and stayed on, LED 5 switched on and then off again after the delay and then LEDs 6 and seven switched on and remainedon. I can see no logic inthis although I have that horrible feeling that it is staring me in the face !

Archangel
- 9th December 2008, 01:06
Thanks for that.

My original circuit had three octal darlingtons (ULN 2803) with inputs directly coupled to Ports A, C and D I have also connected leds with 680ohms to each pin so that I can see what the ports outputs are. A test program switched on and off each led in turn thru ports D C and A in that order and worked OK. Problem arose when tryin to switch on all of the A port bits and leave them on. I have now disconnected ther darlington from port a and written the following simple test program:


@ DEVICE pic16f887,intrc_osc_noclkout


PORTD = 0
PORTA = 0
PORTC = 0
TRISD = 0
TRISA = 0
TRISC = 0
portA.0 = 1
pause 500
porta.1 = 1
pause 500
porta.2 =1
pause 500
porta.3 = 1
pause 500
porta.4 = 1
pause 500
porta.5 = 1
pause 500
porta.6 = 1
pause 500
porta.7 = 1
end


I have just run this program and
1. When Microcode studio fired up the Pickit2 the voltage Vdd had been set down to 3.3
2. I turned up Vdd to 5 volts and programmed the chip.
LEDs 0,1,2,3 tuswitched on and then off after the delay. LED 4 switched on and stayed on, LED 5 switched on and then off again after the delay and then LEDs 6 and seven switched on and remainedon. I can see no logic inthis although I have that horrible feeling that it is staring me in the face !

If this is all of the code, then You have to turn off all the analog stuff to get it to work, ADCON, ANSEL, and Comparators
http://www.picbasic.co.uk/forum/showthread.php?t=561

DavidFMarks
- 9th December 2008, 23:00
Very many thanks. I now have the system fully operational and can start programming the Star of David which should now be appearing in the village tomorrow evening. It might not seem much but by this time tomorrow I confidently expect the village will be swarming with wise men and shepherds. Thanks again folks !

mackrackit
- 9th December 2008, 23:08
Lets see some pictures :)

Archangel
- 9th December 2008, 23:58
. . .It might not seem much but by this time tomorrow I confidently expect the village will be swarming with wise men and shepherds. . . !You obviously do not live in Washington DC. :D

DavidFMarks
- 10th December 2008, 00:55
Spoke too soon !... Not about the shepherds and wise men but about the program working. I have been programming a whole load of different sequences one after another. They have all worked ok until the last few, the program simply ignores them and returns to the beginning. If i bung in a goto directly to the last few sequences the behave erratically (cutting short loops etc. I wonder if I have broken some rule about memory size or borders or some such as I am far from clear on this subject .... To hell with the shepherds I just need the wise men.....

mackrackit
- 10th December 2008, 01:09
We might be able to help if we could see your code.

DavidFMarks
- 10th December 2008, 09:59
OK Just didn't want to clutter up the forum with my lengthy and probably badly written code, but here goes !


'***********CHRISTMAS STAR PROGRAM FOR OPERATING *************
'**********A 16 ARM STAR WITH 8 LEDS ON EACH ARM *************
'******ARMS CONNECTED TO PORTS A AND C AND EACH "RING" ******
'***************CONNECTED TO A PIN OF PORT D ******************

'************AUTHOR DAVID MARKS DEC 2008 ***********************8

@ DEVICE pic16f887,intrc_osc_noclkout
ansel = %00000000
delay var word

fastflash var word

PORTD = 0
PORTA = 0
PORTC = 0
TRISD = 0
TRISA = 0
TRISC = 0
fastflash = 150

Ring0 var portd.0
Ring1 var portd.1
Ring2 var portd.2
Ring3 var portd.3
Ring4 var portd.4
Ring5 var portd.5
Ring6 var portd.6
Ring7 var portd.7
Arm0 var Portc.0
Arm1 var Portc.1
Arm2 var Portc.2
Arm3 var Portc.3
Arm4 var Portc.4
Arm5 var Portc.5
Arm6 var Portc.6
Arm7 var Portc.7
Arm8 var Porta.0
Arm9 var Porta.1
Arm10 var Porta.2
Arm11 var Porta.3
Arm12 var Porta.4
Arm13 var Porta.5
Arm14 var Porta.6
Arm15 var Porta.7

loop

'********************************************
'EXPANDING WHITE CIRCLES
'********************************************
For delay = 400 to 0 step -25
high Arm0
high Arm2
high Arm4
high Arm6
high Arm8
high Arm10
high Arm12
high Arm14
High Ring0
pause delay
Low ring0
High Ring1
pause delay
Low ring1
High Ring2
pause delay
Low Ring2
High Ring3
pause delay
Low ring3
High Ring4
pause delay
low ring4
High Ring5
pause delay
Low Ring5
High Ring6
pause delay
Low Ring6
High Ring7
pause delay
low Ring7
next delay
LOW ARM0
LOW ARM2
LOW ARM4
LOW ARM6
LOW ARM8
LOW ARM10
LOW ARM12
LOW ARM14

'************************************************* *
'EXPANDING RED CIRCLES
'************************************************* *
For delay = 400 to 0 step -25
high Arm1
high Arm3
high Arm5
high Arm7
high Arm9
high Arm11
high Arm13
high Arm15
High Ring0
pause delay
Low ring0
High Ring1
pause delay
Low ring1
High Ring2
pause delay
Low Ring2
High Ring3
pause delay
Low ring3
High Ring4
pause delay
low ring4
High Ring5
pause delay
Low Ring5
High Ring6
pause delay
Low Ring6
High Ring7
pause delay
low Ring7
next delay
'************************************************
'EXPANDING MULTICOLOUR CIRCLES
'************************************************
For delay = 400 to 0 step -25
high Arm0
high Arm1
high Arm2
high Arm3
high Arm4
high Arm5
high Arm6
high Arm7
high Arm8
high Arm9
high Arm10
high Arm11
high Arm12
high Arm13
high Arm14
high Arm15
High Ring0
pause delay
Low ring0
High Ring1
pause delay
Low ring1
High Ring2
pause delay
Low Ring2
High Ring3
pause delay
Low ring3
High Ring4
pause delay
low ring4
High Ring5
pause delay
Low Ring5
High Ring6
pause delay
Low Ring6
High Ring7
pause delay
low Ring7
next delay
'************************************************* ****
'EXPANDING WHITE DISC
'************************************************* ****
low arm1
low arm3
low arm5
low arm7
low arm9
low arm11
low arm13
low arm15
For delay = 400 to 0 step -25
high Arm0
high Arm2
high Arm4
high Arm6
high Arm8
high Arm10
high Arm12
high Arm14
High Ring0
pause delay
High Ring1
pause delay
High Ring2
pause delay
High Ring3
pause delay
High Ring4
pause delay
High Ring5
pause delay
High Ring6
pause delay
High Ring7
pause delay

LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
NEXT DELAY
'************************************************* *****
'flash all white
'************************************************* *****
fOR DELAY = 0 TO 100
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
PAUSE fastflash
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
PAUSE fastflash
NEXT DELAY
'************************************************* *****
'EXPANDING RED DISC
'************************************************* *****

lOW ARM0
low arm2
low arm4
low arm6
low arm8
low arm10
low arm12
low arm14

For delay = 400 to 0 step -25
high Arm1
high Arm3
high Arm5
high Arm7
high Arm9
high Arm11
high Arm13
high Arm15
High Ring0
pause delay
High Ring1
pause delay
High Ring2
pause delay
High Ring3
pause delay
High Ring4
pause delay
High Ring5
pause delay
High Ring6
pause delay
High Ring7
pause delay
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
NEXT DELAY
'*********************************************
'FLASH ALL RED
'*********************************************
fOR DELAY = 0 TO 100
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
PAUSE fastflash
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
PAUSE fastflash
NEXT DELAY
'*********************************************
'EXPANDING MULTICOLOUR DISC
'*********************************************
HIGH ARM0
high Arm1
high Arm2
high Arm3
high Arm4
high Arm5
high Arm6
high Arm7
high Arm8
high Arm9
high Arm10
high Arm11
high Arm12
high Arm13
high Arm14
high Arm15
For delay = 400 to 0 step -25
High Ring0
pause delay
High Ring1
pause delay
High Ring2
pause delay
High Ring3
pause delay
High Ring4
pause delay
High Ring5
pause delay
High Ring6
pause delay
High Ring7
pause delay
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
NEXT DELAY
'************************************************* ******************
'flashall
'************************************************* ******************
HIGH ARM0
high Arm1
high Arm2
high Arm3
high Arm4
high Arm5
high Arm6
high Arm7
high Arm8
high Arm9
high Arm10
high Arm11
high Arm12
high Arm13
high Arm14
high Arm15

For delay = 400 to 0 step -25
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
pAUSE DELAY
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
Pause delay
next delay
For delay = 0 to 100
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
pause fastflash
LOW RING0
LOW RING1
LOW RING2
LOW RING3
LOW RING4
LOW RING5
LOW RING6
LOW RING7
next delay
'****************************************
'ROTATE WHITE
'****************************************
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
for delay = 400 to 50 step -30
hIGH arm0
high arm8
pause delay
low arm0
low arm8
high arm2
high arm10
pause delay
low arm2
low arm10
high arm4
high arm12
pause delay
low arm4
low arm12
high arm6
high arm14
pause delay
low arm6
low arm14
next delay
'*********************************************
'ROTATE MULTI
'*********************************************
high ring0
high ring1
high ring2
high ring3
high ring4
high ring5
high ring6
high ring7
for delay = 300 to 50 step -10
hIGH arm0
HIGH ARM15
HIGH ARM1
high arm8
HIGH ARM7
HIGH ARM9
pause delay
low arm0
low arm8
LOW ARM7
LOW ARM15
high arm2
high arm10
HIGH ARM11
HIGH ARM3
pause delay
low arm2
LOW ARM1
low arm10
LOW ARM9
high arm4
high arm12
HIGH ARM5
HIGH ARM13
pause delay
low arm4
LOW ARM3
LOW ARM11
low arm12
high arm6
high arm7
high arm15
high arm14
pause delay
low arm6
low arm5
low arm13
low arm14
next delay
goto loop

The program runs ok until somewher near the end of the @flashall section then instead of going thru the rotate routines it jumps back to the beginning and starts again.
I would be very happy to post a picture or video clip if someone could point me towards the instructions for doing so which I cant seem to find !
Thanks all

mackrackit
- 10th December 2008, 11:36
I do not see the problem in your code. Maybe it is a hardware problem? Power supply dropping out by the time it is finished with "flashall" causing a reset? Add a BIG capacitor across the rails? 4700uf?

Sorry, I am not much help. :(

If you want to see how some one else has created a post, just click the quote button. It shows all.

Here is a thread about pictures
http://www.picbasic.co.uk/forum/showthread.php?t=9156

Videos
http://www.picbasic.co.uk/forum/showthread.php?t=9531

skimask
- 10th December 2008, 14:34
Different way of doing your code (may have messed some of it up along the way)
Also, not sure about the '887 and it's watchdog timer, so added a chunk to your DEVICE statement to turn it off.
Your code wasn't badly written, just a bit lengthy and could have stood to be shortened up a bit, things combined here and there...


'***********CHRISTMAS STAR PROGRAM FOR OPERATING *************
'**********A 16 ARM STAR WITH 8 LEDS ON EACH ARM *************
'******ARMS CONNECTED TO PORTS A AND C AND EACH "RING" ******
'***************CONNECTED TO A PIN OF PORT D ******************
'************AUTHOR DAVID MARKS DEC 2008 ***********************8
@ DEVICE pic16f887,intrc_osc_noclkout,wdt_off
ansel=0 : delay var word : fastflash var word : temp var byte
fastflash = 150
PORTD=0 : PORTA=0 : PORTC=0 : TRISD=0 : TRISA=0 : TRISC=0
ring var portd : arma var portc : armb var porta
loop:
'********************************************
'EXPANDING WHITE CIRCLES
'********************************************
For delay = 400 to 0 step -25
arma = $55 : armb = $55 : gosub ringer
next delay
arma = 0 : armb = 0
'************************************************* *
'EXPANDING RED CIRCLES
'************************************************* *
For delay = 400 to 0 step -25
arma = $aa : armb = $aa : gosub ringer
next delay
'************************************************
'EXPANDING MULTICOLOUR CIRCLES
'************************************************
For delay = 400 to 0 step -25
arma = $ff : armb = $ff : gosub ringer
next delay
'************************************************* ****
'EXPANDING WHITE DISC
'************************************************* ****
arma=0 : armb=0
For delay = 400 to 0 step -25
arma = $55 : armb = $55 : gosub ringer : ring = 0
next delay
'************************************************* *****
'flash all white
'************************************************* *****
fOR DELAY = 0 TO 100
ring = $ff : pause fastflash : ring = 0 : pause fastflash
next delay
'************************************************* *****
'EXPANDING RED DISC
'************************************************* *****
arma=0 : armb=0
For delay = 400 to 0 step -25
arma = $aa : armb = $aa : gosub ringer : ring = 0
NEXT DELAY
'*********************************************
'FLASH ALL RED
'*********************************************
fOR DELAY = 0 TO 100
ring = $ff : pause fastflash : ring = 0 : pause fastflash
next delay
'*********************************************
'EXPANDING MULTICOLOUR DISC
'*********************************************
arma=$ff : armb=$ff
For delay = 400 to 0 step -25
gosub ringer : ring = 0
next delay
'************************************************* ******************
'flashall
'************************************************* ******************
arma=$ff : armb=$ff
For delay = 400 to 0 step -25
ring = $ff : pause delay : ring = 0 : Pause delay
next delay
For delay = 0 to 100
ring = $ff : pause fastflash : ring = 0
next delay
'****************************************
'ROTATE WHITE
'****************************************
ring = $ff
for delay = 400 to 50 step -30
for temp = 0 to 7 step 2
arma.0[temp] = 1 : armb.0[temp] = 1
pause delay
arma.0[temp] = 0 : armb.0[temp] = 0
next temp
next delay
'*********************************************
'ROTATE MULTI
'*********************************************
ring = $ff
for delay = 300 to 50 step -10
arma = $83 : armb = $83 : pause delay : arma = 0 : armb = 0
pause delay : arma = $06 : armb = $06 : pause delay : arma = 0
armb = 0 : arma = $30 : armb = $30 : pause delay : arma = 0
armb = 0 : arma = $c0 : armb = $c0 : pause delay : arma = 0 : armb = 0
armb = 0
next delay
goto loop
ringer: for temp = 0 to 7 : ring.0[temp] = 1 : pause delay : ring.0[temp] = 0
pause delay : next temp : return
How about that?





And for all those that have missed it...
Here's some colons I had to get off my chest :)


@ DEVICE pic16f887,intrc_osc_noclkout,wdt_off
ansel=0:delay var word:fastflash var word:temp var byte:fastflash=150:PORTD=0
porta=0:portc=0:trisd=0:trisa=0:trisc=0:ring var portd:arma var portc
armb var porta:armb var porta
loop: for delay=400 to 0 step -25:arma=$55:armb=$55:gosub ringer:next delay
arma=0:armb=0:for delay=400 to 0 step -25:arma=$aa:armb=$aa:gosub ringer
next delay:for delay=400 to 0 step -25:arma=$ff:armb=$ff:gosub ringer
next delay:arma=0:armb=0:For delay=400 to 0 step -25:arma=$55:armb=$55
gosub ringer:ring=0:next delay:for delay=0 to 100:ring=$ff:pause fastflash
ring=0:pause fastflash:next delay:arma=0:armb=0:for delay=400 to 0 step -25
arma=$aa:armb=$aa:gosub ringer:ring=0:next delay:for delay=0 to 100:ring=$ff
ring=$ff:pause fastflash:ring=0:pause fastflash:next delay:arma=$ff:armb=$ff
for delay=400 to 0 step -25:gosub ringer:ring=0:next delay:arma=$ff:armb=$ff
for delay=400 to 0 step -25:ring=$ff:pause delay:ring=0:pause delay
next delay:for delay=0 to 100:ring=$ff:pause fastflash:ring=0:next delay
ring=$ff:for delay=400 to 50 step -30:for temp=0 to 7 step 2:arma.0[temp]=1
armb.0[temp]=1:pause delay:arma.0[temp]=0:armb.0[temp]=0:next temp:next delay
ring=$ff:for delay=300 to 50 step -10:arma=$83:armb=$83:pause delay:arma=0
armb=0:pause delay:arma=6:armb=6:pause delay:arma=0:armb=0:arma=$30:armb=$30
pause delay:arma=0:armb=0:arma=$c0:armb=$c0:pause delay:arma=0:armb=0:armb=0
next delay:goto loop
ringer: for temp=0 to 7:ring.0[temp]=1:pause delay:ring.0[temp]=0:pause delay
next temp:return
END

DavidFMarks
- 10th December 2008, 18:17
No go so far I'm afraid tried the new code but there are a number of errors which I haven't checked out yet. Tried switching watchdog timer off and have put lots of capacitance across the 4.8 volt supply to the pickit2. (There are only three octal darlingtonds in circuit and there is no sign that the voltage drops when they are all on. The program runs until the "expanding multicolour disc" section. It then appears to go about seven times round the for next loop (For delay = 400 to 0 step -25) . and then starts again at the beginning of the program i.e. It resets. BTW Like the look of the shortened code although I haven't figured it all out yet !

skimask
- 10th December 2008, 18:51
How long does the program run before it resets? I mean exactly how long?
Put a stopwatch on it...from power on until it resets. Try to be as accurate as possible.

DavidFMarks
- 10th December 2008, 19:33
Three minutes 43 seconds (got slightly further thru the loop that time I think !)

skimask
- 10th December 2008, 20:21
Three minutes 43 seconds (got slightly further thru the loop that time I think !)

Only reason I asked was that it might narrow down whether or not the watchdog timer is actually kicking or not.
According to the datasheet, the max timeout for the WDT is 268 seconds. You got 3m43s, 223 seconds. Not really that close to 268 seconds, but the LFINTOSC is an uncalibrated clock. It's typical value is 31khz. It could run from 15khz (9m13s) to 45khz (3m4s), so your 223 seconds falls inside that range.

Try dropping all of the pauses by a factor of 10 and see if it kicks out in the same spot or not.

Also, looks to me like there are more LEDs on in 'Expanding Multicolor Disc' than the rest.
What are you using for a power supply?

DavidFMarks
- 10th December 2008, 22:20
I tried reducing the start point of the if then that controls the delay from 400 down to 200 delay. The program now runs for 1 min 55 but gets further into the program. In fact it gets part way thru the "flashall" section. The power to the pickit demo board, the three darlington drivers and the opto couplers which operate the power transistors on the 8 positive lines is derived from a "Picaxe board I had lying around which has a7805 voltage reg and is being supplied from a 12volt 700ma power unit.
The normal output voltage which is going to the PIC is 4.8 I have written a bit of code which swithches on all three ports (and hence all 128 leds) and the current taken is about 220 mA which drops the voltage to about 4.2

For what it's worth the darlington outputs and the transistor circuits which light the leds are driven fom a car battery charger with an output of about 13.5 volts. Go on tell me I've done something daft !!! (I'll believe you !!);)

mackrackit
- 10th December 2008, 22:34
How do you have MCLR set?

I use MPASM so you need to change it a bit, but here is my config line for this chip.


@__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF

skimask
- 10th December 2008, 23:37
In fact it gets part way thru the "flashall" section.
Ok, I believe that would rule out the WDT.


The normal output voltage which is going to the PIC is 4.8 I have written a bit of code which swithches on all three ports (and hence all 128 leds) and the current taken is about 220 mA which drops the voltage to about 4.2
The brownout reset, if turned on, kicks at 4.0v. Are you measuring voltage at the regulator/source? Or right at the PIC itself? Might have a voltage drop in there somewhere and the brownout is kicking in.


fom a car battery charger with an output of about 13.5 volts
Those outputs aren't too clean at all.


And are your config bits really being set as you want them to actually be set?

DavidFMarks
- 10th December 2008, 23:42
starting to reveal my ignorance ! I don't really know how I have MCLR set this is an area I do not understand well. I already had trouble because I initially thought I was using MPASM when in fact i was using the melabs version and find it difficult to translate between the two ! I will have a look at the line you provided and try to work out what it should be on my system. As a point of intertest I have bought god knows how many books on PIC programming and have always felt that the config business is very poorly explained most of the stuff my aged brain has coped with but not that. I'll have another look at Melanies post on config and try to work it out together with exactly what MCLR does !

skimask
- 10th December 2008, 23:45
I don't really know how I have MCLR set this is an area I do not understand well.
Are you talking about the function of the MCLR pin?
Or the function of the MCLR 'switch' in the config bits?

mackrackit
- 11th December 2008, 00:11
@ device pic16F887, intrc_osc_noclkout, mclr_off, lvp_off, protect_off, wdt_off


Try that.

DavidFMarks
- 11th December 2008, 00:54
tried to interpret your config line in pm terms got the @device to work with MCLR and Lvp but didn't recognise CP. None of this made any difference. However after a lot more somewhat uneducated fiddling I find that the piece of code which seems to produce the problem is the expanding multicoloured disc bit if I remove it to the end I can get both the rotating bit and the flashall bit working. I have however just spotted a message when I compile which states:
Warn Blink.asm599: [102] code crosses boundary @ 800h
I think I am going to have to settle for what I have got and keep it simple... I am getting in over my head here.. Thought flashing a group of leds would be a doddle !!! although the fact that the flashall bit works would seem to rule out power supply problems as that is switching the whole lot on and off.

mackrackit
- 11th December 2008, 01:23
The above post #41 should be the config for PM.

Read this (post #2)
http://www.picbasic.co.uk/forum/showthread.php?t=40

skimask
- 11th December 2008, 02:57
I have however just spotted a message when I compile which states:
Warn Blink.asm599: [102] code crosses boundary @ 800h
Shouldn't have to worry about that.

What happens if you use ONLY that chunk of code that is failing and nothing else?

DavidFMarks
- 11th December 2008, 09:24
k the latter as I do not really know the significance

mackrackit
- 11th December 2008, 09:34
k the latter as I do not really know the significance

Not sure what "k the latter" is. Does not translate well :D

DavidFMarks
- 11th December 2008, 15:23
YESSSSS!

It's working ! Finally pinned it down to the power supply. If I supply the PIC separately from the optocoupled transistors it all works. very many thanks to all you patient and helpful souls out there without whom this particular star would never have risen in the west (or anywhere else !). When (if ?) I figure ou how to post a picture and/or video I will be happy to do so. Thanks again

Happy Christmas