![]() |
Forum Index : Microcontroller and PC projects : PicoMite Alpha Firmware
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
I think TIMER is going negative... I'd ignored it for a while. When I came to try Timer=0 it said that valid values were 0 - 4.somethingE -something else (sorry, I can't remember the numbers). I'll wait and see what happens later. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9992 |
a18 PicomiteV5.07.00a18.zip fixes issue with timer= Lots of internal work preparing for I/O. More work on flash and option storage New OPTION OPTION CPUSPEED cpuspeedinkhz This allows you to set the cpu speed - after option reset it will be the "new" default 125,000 I've been running completely reliably at 250,000KHz and that has been the speed for all recent alphas. I'm wondering if some of the issue people have been reporting is because their chips don't like the overclock. Use option reset, flash erase all and var clear to clean up before and after loading the alpha Edited 2021-06-07 01:36 by matherp |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
Looks like it's a speed issue on my dodgy Pico. I've just this min been running it with a17 on it at 125000 and it seems to be ok. Raspberry pi point out that their default speed is 133000 and running faster is "unsupported" so it's quite likely that that's the speed (or maybe slightly more) that they are tested at. I don't know if they do what it says, but I also tried 133000 and 140000. It seems to be working. Pressing reset does what I expected. Edit: Using a18 - run the dodgy board up to 200000 and apparently ok. Edited 2021-06-07 02:03 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3298 |
With a17, my dodgy pico flashes the LED and presents the MMBasic prompt after power-cycling, unlike before. FWIW, "As" is still duplicated in "LIST FUNCTIONS". And with a18--all ok. Edited 2021-06-07 02:20 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
cdeagle Senior Member ![]() Joined: 22/06/2014 Location: United StatesPosts: 263 |
Zipped file of NPOE.BAS attached npoe.zip |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
I've just been running the "good" one at a range of speeds from 50000 up to 260000. If you go too high it does tell you an interesting acceptable range though. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
romba6![]() Newbie ![]() Joined: 04/07/2020 Location: United KingdomPosts: 37 |
Thank you Peter - a17 perfect at default - fails at 200000. so no worries. Will see what I can get out of the other pico |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
It's worth getting flash_nuke.uf2 from the Raspberry Pi Pico pages in case you set OPTION CPUSPEED too high. :) It'll wipe the flash and hence the options, getting you out of a sticky situation. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3298 |
What about a flash command like FLASH READ n,"filename.bas" ' Reads a program from SD & loads to the specified flash spot This might enable something like Thwill's chained tests. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2396 |
WARNING: had problems when setting: option cpuspeed 265000 the pico's USB console port was gone - rather permanently. reflashing with alpha 18 didn't fix it, reflashing with MicroPython worked, but reflashing with alpha 18 resulted in no USB console port again. solution was to flash with an earlier alpha, then with alpha 18. might i suggest placing the saved options into a block of flash that is overwritten by 0xFF whenever the mmbasic .uf2 file is flashed? ie, effectively include in the .uf2 file a set of default (blank) options. the same for the index into the 10 program slots so that they are always erased too. the pico i'm testing with worked fine from 48MHz to 260MHz. at 48MHz the speed was almost exactly the same as the original MX150-based micromite, while the current consumption was around 13mA. changing CPU speeds did knock the USB subsystem (under linux) out of action in a fairly unpredictable manner around 50% of the time. i now have the magic incantations to unbind/rebind USB on 'speed dial' so can do a quick repair without rebooting. when using option cpuspeed nnn it may be worthwhile looking at just writing the option, then printing a message that the change will take effect after the next restart of the pico. cheers, rob :-) addendum: why the choice of specifying the cpu speed in kHz, instead of MHz like the MX17O version of mmbasic does? Edited 2021-06-07 03:19 by robert.rozee |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9992 |
a19 PicomiteV5.07.00a19.zip Full PWM support PWM channel, frequency, [duty1] [,duty2] PWM channel, OFF e.g. SETPIN 1,PWM0A SETPIN 2,PWM0B PWM 0,1000,33,67 PWM 0,OFF The setpin can be changed until the PWM command is issued. At that point the pin becomes locked to PWM until PWM n,OFF is issued There are 8 separate PWM frequencies available (0 - 7) and up to 16 outputs with individually controlled duty cycle. You can output on either PWMnA or PWMnB or both for each channel - no restriction Minimum frequency is given by the equation 65535 < (OPTION CPUSPEED * 1000)/256 This gives a minimum frequuency of 7.5Hz with a clock speed of 125MHz Maximum speed is OPTION CPUSPEED/4 Of course at very fast speeds the duty cycles will be increasingly limited Re: locking up by overclocking. I've limited the maximum to 250MHz which seems to run (just about) on all processors. I will also provide a stand-alone program that can reflash the options to default. Given how easy the Pico is to flash, this is better than the usual pin-held-low or repeat character approaches Valid channels for PWM and other special functions are given in the attached table and the codes for SETPIN are as in the table. const struct s_PinDef PinDef[NBRPINS + 1]={ { 0, 99, "NULL", UNUSED ,99}, // pin 0 { 1, 0, "GP0 ", DIGITAL_IN | DIGITAL_OUT | UART0TX | SPI0RX | I2C0SDA | PWM0A,99}, // pin 0 { 2, 1, "GP1 ", DIGITAL_IN | DIGITAL_OUT | UART0RX | I2C0SCL | PWM0B ,99}, // pin 1 { 3, 99, "GND ", UNUSED ,99}, // pin 2 { 4, 2, "GP2 ", DIGITAL_IN | DIGITAL_OUT | SPI0SCK | I2C1SDA | PWM1A ,99}, // pin 3 { 5, 3, "GP3 ", DIGITAL_IN | DIGITAL_OUT | SPI0TX | I2C1SCL | PWM1B ,99}, // pin 4 { 6, 4, "GP4 ", DIGITAL_IN | DIGITAL_OUT | UART1TX | SPI0RX | I2C0SDA | PWM2A ,99}, // pin 5 { 7, 5, "GP5 ", DIGITAL_IN | DIGITAL_OUT | UART1RX | I2C0SCL | PWM2B ,99}, // pin 6 { 8, 99, "GND ", UNUSED ,99}, // pin 7 { 9, 6, "GP6 ", DIGITAL_IN | DIGITAL_OUT | SPI0SCK | I2C1SDA | PWM3A ,99}, // pin 8 { 10, 7, "GP7 ", DIGITAL_IN | DIGITAL_OUT | SPI0TX | I2C1SCL | EXT_PWM3B ,99}, // pin 9 { 11, 8, "GP8 ", DIGITAL_IN | DIGITAL_OUT | UART1TX | SPI1RX | I2C0SDA | PWM4A ,99}, // pin 10 { 12, 9, "GP9 ", DIGITAL_IN | DIGITAL_OUT | UART1RX | I2C0SCL | PWM4B ,99}, // pin 11 { 13, 99, "GND ", UNUSED ,99}, // pin 12 { 14, 10, "GP10", DIGITAL_IN | DIGITAL_OUT | SPI1SCK | I2C1SDA | PWM5A ,99}, // pin 13 { 15, 11, "GP11", DIGITAL_IN | DIGITAL_OUT | SPI1TX | I2C1SCL | PWM5B ,99}, // pin 14 { 16, 12, "GP12", DIGITAL_IN | DIGITAL_OUT | UART0TX | SPI1RX | I2C0SDA | PWM6A ,99}, // pin 15 { 17, 13, "GP13", DIGITAL_IN | DIGITAL_OUT | UART0RX | I2C0SCL | PWM6B ,99}, // pin 16 { 18, 99, "GND ", UNUSED ,99}, // pin 17 { 19, 14, "GP14", DIGITAL_IN | DIGITAL_OUT | SPI1SCK | I2C1SDA | PWM7A ,99}, // pin 18 { 20, 15, "GP15", DIGITAL_IN | DIGITAL_OUT | SPI1TX | I2C1SCL | PWM7B ,99}, // pin 19 { 21, 16, "GP16", DIGITAL_IN | DIGITAL_OUT | UART0TX | SPI0RX | I2C0SDA | PWM0A ,99}, // pin 21 { 22, 17, "GP17", DIGITAL_IN | DIGITAL_OUT | UART0RX | I2C0SCL | PWM0B ,99}, // pin 22 { 23, 99, "GND ", UNUSED ,99}, // pin 23 { 24, 18, "GP18", DIGITAL_IN | DIGITAL_OUT | SPI0SCK | I2C1SDA | PWM1A ,99}, // pin 24 { 25, 19, "GP19", DIGITAL_IN | DIGITAL_OUT | SPI0TX | I2C1SCL | PWM1B ,99}, // pin 25 { 26, 20, "GP20", DIGITAL_IN | DIGITAL_OUT | I2C0SDA | PWM2A ,99}, // pin 26 { 27, 21, "GP21", DIGITAL_IN | DIGITAL_OUT | I2C0SCL | PWM2B ,99}, // pin 27 { 28, 99, "GND ", UNUSED ,99}, // pin 28 { 29, 22, "GP22", DIGITAL_IN | DIGITAL_OUT | PWM3A ,99}, // pin 29 { 30, 99, "RUN ", UNUSED ,99}, // pin 30 { 31, 26, "GP26", DIGITAL_IN | DIGITAL_OUT | ANALOG_IN | I2C1SDA | PWM5A , 0 }, // pin 31 { 32, 27, "GP27", DIGITAL_IN | DIGITAL_OUT | ANALOG_IN | I2C1SCL | PWM5B , 1 }, // pin 32 { 33, 99, "AGND", UNUSED ,99}, // pin 33 { 34, 28, "GP28", DIGITAL_IN | DIGITAL_OUT | ANALOG_IN | PWM6A , 2 }, // pin 34 { 35, 99, "VREF", UNUSED ,99}, // pin 35 { 36, 99, "3V3 ", UNUSED ,99}, // pin 36 { 37, 99, "3V3E", UNUSED ,99}, // pin 37 { 38, 99, "GND ", UNUSED ,99}, // pin 38 { 39, 99, "VSYS", UNUSED ,99}, // pin 39 { 40, 99, "VBUS", UNUSED ,99}, // pin 40 { 41, 25, "GP25", DIGITAL_OUT | PWM4B ,99 }, // pin 41 }; Edited 2021-06-07 04:34 by matherp |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
I thought I'd put together a bit of *very* provisional documentation for my own use 'cos I forget stuff. It may come in useful to someone. :) Picomite.zip Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1958 |
@ Mixtel90......thanks for that, very helpful "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4240 |
Sounds useful, but until my SD card adapter arrives and I have a chance to do a deep dive on this I don't know if it's enough. I'm only familiar with the CMM 1&2 so the limitations of the "micro"-mite will be new territory for me. I am guessing that if all else fails I can use Python to read and write to the PicoMite over the serial connection and thus make it dance to whatever tune I like, including finding and executing a sequence of test programs - perhaps the threat of Python alone might be sufficient to motivate Peter to include some enabling functionality in the firmware ![]() Anyway joking aside the progress is as always phenomenal and leaves me in envy of his time, stamina and technical prowess. On a related matter can I expect MMBasic on the Picomite to have any mechanism for sharing code, e.g. LIBRARY or #INCLUDE or would that be straying back into microcomputer territory again ? Best wishes, Tom Edited 2021-06-07 08:33 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
led-bloon![]() Senior Member ![]() Joined: 21/12/2014 Location: AustraliaPosts: 207 |
a19 Fully loaded - Just a silly one .. mis-typed option cpuspeed 25000 (ilo 250000) Got: Error : 25000 is invalid (valid is 48000 to 0) led Miss you George |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
It's correct at the bottom end. 50% isn't bad for an alpha release. :) @lizby Re. FLASH READ That might not be possible. I suspect that it'll probably depend on whether there is buffer RAM available to accept the incoming file in the minimum readable block size before writing it to flash in the minimum block size while still having space in RAM for the routine that's handling the transfer. RAM is handled in fixed block sizes, it isn't contiguous, so I'm guessing that everything would have to fit into one block. @thwill I had considered asking about a shared library, accessed from whichever flash area is loaded at the time. I have a feeling that it may not be possible for the same reason as above - because it contains proglets it probably has to be in RAM. One approach might have been to use one of the flash areas as the library and #include it by copying into an area of RAM while retaining the program. Whether that's remotely feasible I've no idea. @matherp Sorry, I'm having a "thick" morning. If the choice of PWM speeds is 0-7 why do you allocate 1000 to get a frequency of 1kHz? Do you mean that there are 8 PWM *ports*, PWM0, PWM1, PWM2 etc. with outputs A and B on each? A minor correction, smaller font size and tidied up the line lengths. Picomite.zip Edited 2021-06-07 18:45 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9992 |
There are 8 PWM channels (0-7) each of which can have its own frequency and up to 2 pins on each channel ( A and B) with the same or different duty cycles |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4811 |
Installed a19 and tried the pwm's. Did not work until I went through the sequence of option reset, flash erase all, and var clear. I ran into one strange thing. When you start a PWM and the program ends, the PWM does not stop. That in itself is not so strange (althgough stopping the PWM when the program hits and END could also be logical), but I would expect when you alter the program, and run it again that PWM's would accept the changes. They do not. Peter, would you at start (run) of the program perform a "pwm 0,off, .... pwm 8,off. Is there a possibility to het the "servo" commands back in ? Technically it is very possible to use PWM, but with integer percents in PWM that is not a lot of resolution. PicomiteVGA PETSCII ROBOTS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 9992 |
a20 PicomiteV5.07.00a20.zip I2C and I2C2 now working - see example program for BMP180 below CPU_Speed error reporting fixed PWM command accepts floats for duty cycles I think this is the case in all versions That was a bug which should now be fixed Option EXPLICIT Option DEFAULT FLOAT Const i2caddr=&b1110111 Const MS7=7 'set default wait period Const signed=1 Const unsigned=0 ' Dim i2cin$ 'max size for integer conversion Dim UT%,UP% Dim ac1%,ac2%,ac3,ac4%,ac5%,ac6%,b1%,b2%,mb%,mc%,md% 'bmp180 parameters Dim x1%,x2%,b5%,b6%,x3,b3%,b4%,b7%,OSS% Dim temperature%,pressure% Dim altitude,QNH,pressureinHpa Dim OSSdata%(4) Dim OSSscale%(4) On error skip 1 SetPin 14,i2c1sda SetPin 15,i2c1scl I2C2 OPEN 400,1000 init: OSS%=1 'set oversampling ratio ' OSS%=0 ' Uncomment this line to check algorithm against datasheet OSSdata%(0)=&H34 'commands to sample pressure% with different levels of overs ampling OSSdata%(1)=&H74 OSSdata%(2)=&Hb4 OSSdata%(3)=&HF4 OSSscale%(0)=1 'scale factors for calcs when oversampled OSSscale%(1)=2 OSSscale%(2)=4 OSSscale%(3)=8 ' I2C2 WRITE i2caddr,1,1,&HAA 'send read calibration data command I2C2 READ i2caddr,0,22,i2cin$ 'read in calibration data ac1%=Str2bin(int16,Mid$(i2cin$,1,2),big) ac2%=Str2bin(int16,Mid$(i2cin$,3,2),big) ac3=Str2bin(int16,Mid$(i2cin$,5,2),big) ac4%=Str2bin(uint16,Mid$(i2cin$,7,2),big) ac5%=Str2bin(uint16,Mid$(i2cin$,9,2),big) ac6%=Str2bin(uint16,Mid$(i2cin$,11,2),big) b1%=Str2bin(int16,Mid$(i2cin$,13,2),big) b2%=Str2bin(int16,Mid$(i2cin$,15,2),big) mb%=Str2bin(int16,Mid$(i2cin$,17,2),big) mc%=Str2bin(int16,Mid$(i2cin$,19,2),big) md%=Str2bin(int16,Right$(i2cin$,2),big) ' ' Uncomment this block to check algorithm against datasheet ' ' ac1%=408 ' ac2%=-72 ' AC3=-14383 ' ac4%=32741 ' ac5%=32757 ' ac6%=23153 ' b1%=6190 ' b2%=4 ' mb%=-32768 ' mc%=-8711 ' md%=2868 main: I2C2 WRITE i2caddr,0,2,&HF4,&H2E 'send temp conversion Pause MS7 'wait for temperature% conversion I2C2 WRITE i2caddr,1,1,&HF6 'send read data I2C2 READ i2caddr,0,2,i2cin$ 'read 2 bytes UT%=Str2bin(uint16,i2cin$,big) ' UT%=27898 ' Uncomment this line to check algorithm against datasheet I2C2 WRITE i2caddr,0,2,&HF4,ossdata%(oss%) 'send pressure% conversion Pause (oss%+1)*ms7 'wait for the p ressure% conversion I2C2 WRITE i2caddr,1,1,&HF6 'send read data I2C2 READ i2caddr,0,3,i2cin$ 'read 3 bytes UP%=Str2bin(uint32,Chr$(0)+i2cin$,big) UP%=UP%>>(8-oss%) 'scale the oUT%pUT% by the numb%er of unused bits in the xl sb byte ' UP%=23843' Uncomment this line to check algorithm against datasheet calc_temp() calc_pressure() pressureinHpa=pressure%/100 Print "Temperature = ",Str$(temperature%/10,4,1)," Deg C" Print "Local pressure = ",Str$(pressure%/100,4,1)," Hectopascal/mb" Input "QNH in Hpa/Mb ? ",QNH altitude=calcaltitude(QNH,pressureinHpa) Print "Current altitude in feet = ",altitude Print "Reverse calculate Sea level pressure = ",calcQNH(altitude,pressureinHp a)," Hectopascal/mb" End ' ' calc_temperature%: calculate the temperature% from the raw temperature% given the calibration parameters ' Sub calc_temp x1%=(UT%-ac6%)*ac5%\powerof2(15) x2%=mc%*powerof2(11)/(x1%+md%) 'This needs to be a floating divide to match t he datasheet b5%=x1%+x2% temperature%=(b5%+8)\powerof2(4) End Sub ' ' calc_pressure: calculate the pressure% from the raw pressure% given the calib ration parameters and temperature% oUT%pUT% ' Sub calc_pressure b6%=b5%-4000 x1%=(b2%*(b6%*b6%/powerof2(12)))\powerof2(11) x2%=ac2%*b6%\powerof2(11) x3=x1%+x2% b3%=(((ac1%*4+x3)*ossscale%(oss%))+2)\4 x1%=AC3*b6%\POWEROF2(13) x2%=(b1%*(b6%*b6%/POWEROF2(12)))\POWEROF2(16) x3=((x1%+x2%)+2)\4 b4%=ac4%*(Abs(x3+32768))\powerof2(15) b7%=Abs(UP%-b3%)*(50000\ossscale%(oss%)) pressure%=(b7%*2)\b4% x1%=(pressure%\powerof2(8))*(pressure%\powerof2(8)) x1%=(x1%*3038)\powerof2(16) x2%=(-7357*pressure%)\powerof2(16) pressure%=pressure%+(x1%+x2%+3791)\powerof2(4) End Sub ' Function calcQNH(currentaltitude,localpressure) calcQNH=(localpressure*100)/((1-(currentaltitude*0.3048/44330))^5.255)/100 End Function ' Function log10(x) log10=Log(x)/2.302585093 End Function ' Function calcaltitude(sealevelpressure, localpressure) Local a As float, b As float calcaltitude=((10^(log10(localpressure/sealevelpressure)/5.2558797))-1)/-6.87 55856 *1000000 End Function ' Function powerof2(i As integer) As integer powerof2=(1<<i) End Function |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7458 |
*confused* SetPin 14,i2c1sda SetPin 15,i2c1scl I2C2 OPEN 400,1000 The I2Cs are I2C (channel 1) and I2C2 (channel 2), so shouldn't the SETPINs refer to i2c2sda and i2c2scl in this example? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
![]() ![]() ![]() ![]() |
![]() |