<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1273&stc=1&d=116630151 9">
Bravo Steve!
Nice explaination.
SteveB
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1273&stc=1&d=116630151 9">
Bravo Steve!
Nice explaination.
SteveB
Gracias, Merci, thank you,falemnderit, σασ ευχαριστώ, danke, grazie, ขอบคุณ, teşekkür ederim ,...,..
![]()
Last edited by mister_e; - 16th December 2006 at 20:50.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
You guys crack me up !
Ok' I'm working my way through this version using the 16F873A, but I've hit a small issue which is so basic I can't see why it responds the way it does (it worked with the 16F628a).
I have set port A to all inputs and added
I have a 10k pull up resistor between pin 4 (RA2) and +5v with a tactile switch between pin 4 and GND.Code:SW1 var PORTA.2 ;pattern selection switch
I've added the code
So in therory if the switch (sw1) is low then swcount is increased by 1, until it is > than 7 and if so then its swcount is reset to 1. This way the pattern is selected by pressing the switch.Code:if SW1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to swcount pause 60 ;debounce delay If swcount>7 then swcount=1 ;error trap for exceeding max patterns
However in practice, the PIC simply ignores any input on RA2, but more confusingly, it runs each pattern once in sequence, ie it cycles through the patterns as if the button is being pressed, so swcount must in some way be changing as the remainder of the code works if the above lines are remed out and swcount is manual set to 1, 2, 3 etc, which results in just the selected pattern running.
Its probably me having a blonde moment (no offence to any fair haired madiens out thereCode:Pot PORTA.1,scale,D ;used to read value from 10k pot and set the speed read patt[swcount],steps ;read the first value of the selected patter and place it in the variable steps for C = 1 to steps ;for / next loop READ PATT[SWCOUNT]+ C,PORTB ;reads the step value for selected pattern and send it to PORTB PAUSE D ;delay for speed NEXT GOTO MAIN) - but can anyone shed some light why this isn't working.
Exactly what value have you put into ADCON1 to "set port A to all inputs" yet still get the Pot command to work? It seems as though you still might have some of them set as Analog Inputs.Originally Posted by malc-c
SteveB
Last edited by SteveB; - 17th December 2006 at 01:57.
Steve,
Here is the complete code (less the data for light patterns)
In this example I've removed the wire from the 10 pot and set SW to the same pin as I have the pot working fine - and it works. If I set SW to RA0, RA2, RA3 etc the LEDs run through each pattern from 1 - 7 in a loop.Code:;************* set up PIC ******************** ADCON1=$0F CMCON = 7 ' Digital inputs CCP1CON = 0 ' PWM off TRISA=%11111111 'set PORTA as all input TRISB=%00000000 'set PORTB as all output PORTB=0 PORTA=0 SW1 var PORTA.1 ;pattern selection switch ;************* set up variables *************** Patt var byte [8] ;used to store the sequences Patt[1]=Patt1 Patt[2]=Patt2 Patt[3]=Patt3 Patt[4]=Patt4 Patt[5]=Patt5 Patt[6]=Patt6 Patt[7]=Patt7 C var byte ;used to advance through pattern D var byte ;used for the speed the sequence runs at scale var byte ;used in the POT command Scale = 254 steps var byte ;used for storing the number of steps in a sequence swcount var byte ;used to select the required sequence required swcount=1 ;set for testing only or default sequence ;**************** main program ******************** main: if sw1=0 then swcount=swcount+1 ;check to see if up button pressed, if so add 1 to SWcount pause 60 ;debounce delay If swcount>7 then swcount=1 ;error trap for exceeding max patterns ;Pot PORTA.1,scale,D ;used to read value from 10k pot and set the speed read patt[swcount],steps ;read the first value of the selected patter and place it in the variable steps for C = 1 to steps ;for / next loop READ PATT[SWCOUNT]+ C,PORTB ;reads the step value for selected pattern and send it to PORTB PAUSE 250 ;delay for speed NEXT GOTO MAIN
As you stated, it must be something is the setting of port A for digital. However I will at some point want one pin to be det up to use the A to D conversion as I want to input the line signal from a CD player to get the LEDs to flash / run to music at some stage in the future, all other inputs.
Sorry if it seems so basic, but as the other Steve can vouch for.. I'm very rusty on the PBP coding !
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1277&stc=1&d=116632121 9">
Have a look at the chart above, which shows the lower nibble of ADCON1 (it's in the datasheet in section 11). ADCON1 = $0F sets PORTA.2 (pin4 ) as the Vref-. Try ADCON1=$07. This will make all PORTA pins digital.
This should allow the Pot on PORTA.1 (pin 3) and the switch on PORTA.2 (pin4 ).
I haven't looked real closely at the rest of the code yet, but this should help.
SteveB
EDIT: I should have read up on the POT command (never had a use for it), so I had to make a couple of changes.
Last edited by SteveB; - 17th December 2006 at 01:56.
Yup it should fix the problem. THE ADCON1=$0F setting was good for the previous PIC18F2550... wich, i feel, will gather dust for awhile
I never used POT command, i prefer to use a real A/D converter instead. ADCIN or the eternal write/read PIC register solution. For an audio trigger... i would use a analog comparator instead as they react way faster.
Last edited by mister_e; - 17th December 2006 at 09:51.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks