Using the version 0.95.006 of GCB. Trying to get a decent range using the random command...
This is what I am doing
#chip 16F1825, 32
#DEFINE USART_BAUD_RATE 9600
#define USART_BLOCKING
'Dir PORTC.0 In 'AD port AN4 pin 10
randomize 2341 'ReadAD(AN4)
do
rn = Random
HSerprint rn
wait 200 ms
loop
The numbers I get for variable rn range from 48 to 57 and that is it. I tried using the AD for randomize and all sorts of numbers, but still same results. I really need to see numbers in the 0 to 255 range as indicated in the manual. What am I doing wrong here?
Thanks!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@viscomjim. Try HSerprint str(rn), and, please change the randomize 2341 as this will always seed the same value, and, you may get the same sequence. Refer to the Help file for a working example.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi and thanks for the reply, however, I used different seed values and even used reading the floating adc pin for randomize and still get the same range of numbers, they are not in the same order, just the same range. I'm trying to get a larger range. Any ideas? I did use the help file example with the same results. Not sure what to do...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi mmotte, that functions looks pretty cool. I will have a go at it to see the results. Evan, thanks for taking a look, I hope I didn't make a bonehead mistake. I look forward to your findings.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What the heck... I need to try again! I can't see what I am doing wrong here. Will keep you posted once I get back to my setup. Jeez....(scratching head)
I noticed in your code you set "Randomize PORTA" instead of PORTD, can you give that a try and see if you get the same type of results?
Thanks
Jim
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#Chip16f1829,32'USART settings #define USART_BAUD_RATE 9600 Dir PORTc.6 Out Dir PORTc.7 In #define USART_DELAY 5 ms #define USART_BLOCKING wait 500 ms ; ----- Define Hardware settings dir portc out ; ----- Constants ; ----- Variables ; ----- Quick Command Reference: ; ----- Main body of program commences here. HSerPrint "Random Test" HSerPrintCRLF 'Userandomize,withthevalueonPORTDastheseedRandomizePORTA'Generaterandomnumbers,andoutputonPORTADoPORTC=RandomHSerPrintByteCRLFportCWait1sLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using the version 0.95.006 of GCB. Trying to get a decent range using the random command...
This is what I am doing
The numbers I get for variable rn range from 48 to 57 and that is it. I tried using the AD for randomize and all sorts of numbers, but still same results. I really need to see numbers in the 0 to 255 range as indicated in the manual. What am I doing wrong here?
Thanks!!!
Not sure what is happening here, but 48 to 57 are the ASCII values for the digits 0 to 9
@David. Good point.
@viscomjim. Try HSerprint str(rn), and, please change the randomize 2341 as this will always seed the same value, and, you may get the same sequence. Refer to the Help file for a working example.
Hi and thanks for the reply, however, I used different seed values and even used reading the floating adc pin for randomize and still get the same range of numbers, they are not in the same order, just the same range. I'm trying to get a larger range. Any ideas? I did use the help file example with the same results. Not sure what to do...
viscomjim
function myrnd
RLF myrndnum,W
RLF myrndnum,W
BTFSC myrndnum,4
XORLW 1
BTFSC myrndnum,5
XORLW 1
BTFSC myrndnum,3
XORLW 1
MOVWF myrndnum
myrnd = myrndnum
end function
function getRndLtr
Loop1:
Letter = myrnd AND 0x7F
if Letter > 90 then goto Loop1
if Letter < 65 then goto Loop1
getRndLtr = Letter
end function
function getRndNum
Loop2:
Letter = myrnd AND 0x7F
if Letter > 57 then goto Loop2
if Letter < 48 then goto Loop2
getRndNum = Letter
end function
These worked pretty good several years ago.
73
M
@mmotte. I will investigate this RANDOM issue as this should work as documented.
I will check using the latest compiler. I will be using the same chip class so this should be a valid test.
Hi mmotte, that functions looks pretty cool. I will have a go at it to see the results. Evan, thanks for taking a look, I hope I didn't make a bonehead mistake. I look forward to your findings.
Using the latest build. I got. This looks correct.
Random Test
138
135
108
24
165
71
97
121
226
174
80
252
130
141
154
201
37
235
From this program
Last edit: Anobium 2016-06-14
What the heck... I need to try again! I can't see what I am doing wrong here. Will keep you posted once I get back to my setup. Jeez....(scratching head)
I noticed in your code you set "Randomize PORTA" instead of PORTD, can you give that a try and see if you get the same type of results?
Thanks
Jim
Next test also looks good.
Random Test
128
238
222
60
255
208
42
227
63
32
112
130
167
58
157
218
92
105
217
239
77
76
239
51
172
167
51
117
224
254
56
142
162
94
112
201
Using code on a 16f1829
Same code as above using the 0.95 2016-02-24 build, also look ok on the 16f1829.
I used the Low Pin Count Board and the LEDs are flashing away reflecting the value displayed on the terminal.
Random Test
217
35
146
26
92
156
66
12
180
I also removed as much code as practical and all seems ok. I removed the additional HSERserial commands, delays etc. Tested ok 16f1829.
If it still fails, post a ZIP with the source, the asm ... everything really. :-)
thanks Evan for checking that. When I get back to my setup, I will give this a whirl again. Sorry for taking your time. Will post back!
Well, I'm a ding dong. Code works as it should. I made a STUPID mistake on my setup and all is well now. Sorry for the time waster.