![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I've been trying to fix the above error but it won't fix I've tried doubling the buffer size [678] Local integer buff(1200) but it still throws up this error after a while Error: Not enough memory Is there a way to clear a buffer before reusing it? local integer buff(1200) I need to find a way to empty the buffer at the end of the subroutine? |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4036 |
The error means MMBasic hasn't enough memory so making the buffer bigger just makes it worse. John |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I’m trying to do this rain2 to = 0 on 1st of 1st at 6AM with the following code [code] IF day = 01 AND month = 01 AND TIME$ = “06:00:00” THEN rain2 = 0 ENDIF [/code] I’m just not sure how to reset the value of rain2 to 0 rain2 = 0 or should be rain2$ = “0” or rain2 = “0” Rain2 is an integer |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
Rain2 = 0 For an integer assignment |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
This is probably going to sound a stupid question IF you have the following SETPIN 97, DOUT PIN(97) = 1 will make pin 97 3.3Volts? IF during the program you then PIN(97) = 0 Should this then make Pin 97 0 volts/ground? The reason I'm asking is I#m playing with an Explore 100 and its giving me about 9mV instead of 0V |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Hi Lew. You need to start thinking in terms of voltage ranges if you want to look at logic levels in terms of their analogue values. Your 9mV is a very good LOW. logic 0 isn't necessarily 0V and logic 1 isn't necessarily 3.3v, but they will be close enough and here's why: As an example (and only as an example, you can do the leg work), the sheet I have permanently on my wall next to me is (table 29-8) for the PIC32MX1xx/2xx VIL and VIH. This shows the tolerances for input voltages and tells me Logic 0 on a general purpose input is anywhere from 0V (GND) to 0.2*VDD. A logic 1 is 0.65*VDD, or 0.8V+0.25*VDD for a 5V tolerant input. So if you are running at pretty much spot-on 3.3VDD, you can expect any input measuring from 660mV down to 0v to be interpreted as a 0 and 2.14V (or 1.62V) and above to be interpreted as a logic 1. In between these levels is classed as "indeterminate" and all bets are off as to how the PIC will interpret the level. Therefore your 9mV is well in this range. You need to consult the datasheets for the PIC you are using - you are expecting things to be precise and they aren't... ever. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Ah, back to the drawing board then I was "hoping" to use it to ground the pin on an audio board to get the audio board to play |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
... as an enable? or for power? will probably work for either... 0.009V is a good 0V. so long as the current requirements don't exceed the pin it will be fine. A mentor of mine (ex-RAF - long dead, bless him) used to say "It's as near as b*ll*cks is to swearing" ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It was to use instead of switches on THIS I could use control it through the serial port but I have no clue whatsoever how to convert Arduino code to Micromite code and the only example they give is Arduino ![]() |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
Yeah, thought so... when they say "GND" they mean "nominally GND" = as near as... we call it logic 0, the actual voltage is usually not important - the datasheet for that device will tell you what it considers as logic 0 in the same way as the PIC data sheet does, but I wouldn't worry about it... all the manufacturers tend to agree and make their stuff "nominally" in the same ball-park so their devices can all talk to each other - makes $$$ sense So it looks like you need a lo on any of the 0-10 inputs for 125mS to start it: "When the # pin is connected to GND for more than about 125 milliseconds it will trigger" Micromite will drive this just fine. Each of the # pins has a 100K pull-up. If the amplifier board is being powered by more than 3.3V you will need to connect them to a 5V tolerant pin on the MM or with a 1K or 1.5K series resistor to any other pin. But other than that there is nothing to stop you driving this from a MM - Arduino code has nothing to do with it. for each pin you need this set up: PIN(x)=1 SETPIN x,DOUT,OC ' need this open collector makes the PIC pull lo but not drive hi then to trigger each pin: PULSE x,125 ' read the pulse command - page 67 of the MMBasic manual or if you don't like that PIN(x)=0 PAUSE 125 PIN(x)=1 same thing. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
The one I have must be faulty, it wont work Works fine on the computer to load and play files, but wont play grounding any of the pins, through the MM or manually |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
What are you feeding the output sound into? does that work with another sound source? What are the filenames you used? It wants names following a specific format - start with "T" then have two digits following. so "T00FRED.wav" is OK, but "FRED.wav" is not the xx is the associated pin number. Also if the files are .ogg, you need at least 200mS low on the pin (not 125ms) |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
T01.wav, T02.wav and so on I even downloaded their example sound file to double check and use that to test |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I've ordered a new module, seems like the one I have is faulty ON a different subject [code][240] FieldArray$(Count) = "" Error: Index out of bounds >[/code] Would a watchdog timer restart that? Or is there any way to automatically run the program again if it stops like that? |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
You cannot run the module if the USB port is connected to a computer. The unit must be powered from a power module only or via the power pins to be in GPIO mode (run using the play inputs). |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
[240] FieldArray$(Count) = "" Error: Index out of bounds Index out of bounds in that case usually means your count variable used to index into your array is larger than the size of the array. If you are accessing it in a for next loop you need to adjust the "to" count. Otherwise you might need to do bounds checking before referencing the array if you do not know (within the code segment you are writing) your source of the index will always be within range. Create a constant which is used to define the size of the array. Before you access the array make sure the index (count) is less than the size constant. |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
@lew247 Lew, Re WATCHDOG timer, it will just restart MMBasic at the timeout, regardless of what it is doing at the time so, no, WATCHDOG won't get you around your problem. With a combination of ON ERROR SKIP, and RUN, you could restart your program BUT YOU WOULDN'T WANT TO as the error message is telling you you have done something wrong programatically and the data you expected to go into the array did not because the pointer, COUNT, is pointing beyond the size of your array. Azure, above, has pointed out this problem and possible ways to detect this condition. panky. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's to count the number of fields coming into the com port an separate them. It "normally" works perfectly, it fails when I touch the weather forecast buttons too fast and probably is in the middle of running the function when I touch the next days button so it then fails because it's expecting FieldArray$(Count) = "" to be 0 when it might have several fields. Here's the code (including comments) kindly provided by MicroBlocks [code]Function GetFieldArray( Record$, Delimiter$, KeepQuotes ) LOCAL Index, Char, InQuote, Count InQuote = 0 Count = 0 ' If no delimiter is provided use a comma IF Delimiter$ = "" then Delimiter$ = "," ' Loop through all the characters FOR Index = 1 to LEN(Record$) Char = ASC(MID$(Record$, Index, 1)) IF Char = 34 THEN ' Flip InQuote between 0 and 1. ' A 1 will signal that the next characters ' are within quotes and delimiters should be ignored InQuote = NOT InQuote ENDIF ' Only check for delimiters when not within two quotes IF NOT InQuote AND INSTR(Delimiter$, chr$(char)) >= 1 THEN Count = Count + 1 ELSE ' Only collect characters for the requested field. 'Add the character and only add quotes when KeepQuotes is 1 IF Char <> 34 OR KeepQuotes THEN GetFieldArray$(Count) = GetFieldArray$(Count) + chr$(char) ENDIF ENDIF ENDIF NEXT GetFieldArray = Count + 1 End Function [/code] |
||||
Azure![]() Guru ![]() Joined: 09/11/2017 Location: AustraliaPosts: 446 |
Lewis the error is not coming from that routine. It is coming from the line mentioned in the error handler [line 240 in your code] I suspect whatever you are doing at that point has count outside the array size. |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |