Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
STM8S103F3 Development Board (HCDVBD0034) 
Author Message

Joined: Sat May 13, 2017 12:43 pm
Posts: 16
Post Re: STM8S103F3 Development Board (HCDVBD0034)
Now it's just a small step to playing a tune in the background:

* a words to represent musical notes
* maybe some kind of ADSR simulation using the PWM duty cycle
* some kind of action table
* a background task that interprets the action table

Actions can also be percussion elements, e.g. an annoy beep from the buzzer output. In Forth anything goes!


Sat Jul 08, 2017 8:07 pm
Profile

Joined: Wed Aug 21, 2013 7:38 am
Posts: 44
Post Re: STM8S103F3 Development Board (HCDVBD0034)
Any ideas on calibrating TIM1 to give more accurate frequencies? 32kHz = 31.75


Sat Sep 16, 2017 5:26 pm
Profile

Joined: Sat May 13, 2017 12:43 pm
Posts: 16
Post Re: STM8S103F3 Development Board (HCDVBD0034)
31.75kHz is within 0.8% of 32kHz. Application note AN2822 describes calibration procedures for the internal oscillator. The calibration steps are 1%: in your case decreasing CLK_HSITRIMR by one would reduce the error to 0.2%. If your application needs better accuracy you either need a reference frequency, or a crystal.


Tue Sep 19, 2017 7:08 pm
Profile

Joined: Wed Aug 21, 2013 7:38 am
Posts: 44
Post Re: STM8S103F3 Development Board (HCDVBD0034)
Cool, I will try that. I do have perfect pitch so it should be more tolerable.
Trimming the clock does now seem to work on another chip. :shock: On certain chips it didn't. :?:

I now use
ls ~/Desktop/Forth/HSI.f and then copy the confirmed file name and paste it.

This file is loaded in picocom with ctrl-A ctrl-S ~/Desktop/Forth/HSI.f

\ contents of HSI.f
\ Pin PC3 trim freq and confirm register readback at 16 kHz
\ I previously used, say f7 as frequency7, as a word. This was confusing as it was valid hex and a word, so a potential future programming conflict.

FILE \ note no longer a supported word
NVM
: CLK_HSITRIMR $50CC ;
: z3 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.45 lowest freq
: z2 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.52
: z1 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.70
: z0 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 15.87 kHz reset value
: z7 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.05
: z6 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.24
: z5 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.43
: z4 CLK_HSITRIMR C! CLK_HSITRIMR C@ . ; \ 16.62 highest freq
: cx $50C0 $F dump ;
RAM
HAND \ note no longer a supported word
initTIM1
decimal
16000 Hz
z6 <enter> 6 ok

Three-bit two's-complement integers
Bits, Unsigned value, Two's complement value

011 3  3 
010 2  2 
001 1  1 
000 0  0 
111 7  −1 
110 6  −2 
101 5  −3 
100 4  −4 

https://en.wikipedia.org/wiki/Two%27s_complement


Last edited by barewires on Fri Oct 06, 2017 2:39 pm, edited 2 times in total.



Tue Sep 19, 2017 11:44 pm
Profile

Joined: Wed Aug 21, 2013 7:38 am
Posts: 44
Post Re: STM8S103F3 Development Board (HCDVBD0034)
Debugging the STM8S is easy to do by dumping the contents of blocks of data within the memory map.

words
IRET SAVEC RESET RAM NVM LOCK ULOCK ADC@ ADC! WORDS .S DUMP ALLOT VARIABLE CREATE DOES> ] IMMEDIATE : ; OVERT ." $" ABORT" AFT REPEAT WHILE AHEAD ELSE THEN IF AGAIN UNTIL BEGIN +LOOP LOOP DO NEXT FOR COMPILE [COMPILE] LITERAL CALL, C, , ' [ NAME> \ ( .( ? . U. TYPE U.R .R CR SPACES SPACE KEY DECIMAL HEX <# SIGN HOLD #S # #> ERASE FILL CMOVE HERE COUNT +! DEPTH PICK 0= ABS NEGATE NOT 1+ 1- 2+ 2- 2* 2/ EXG */ */MOD M* * UM* / MOD /MOD M/MOD UM/MOD WITHIN MIN MAX < U< = DNEGATE 2DUP ROT ?DUP BG TIM BL OUT last '?KEY 'EMIT BASE - 0< OR AND XOR + UM+ I OVER SWAP DUP 2DROP DROP NIP >R R@ R> C! C@ ! @ B! 2C@ 2C! 2@ 2! EXIT EXECUTE LEAVE EMIT ?KEY TX! ?RX hi 'BOOT OUT! COLD ok

\ real programmers only use hex (or octal or binary) ;)
https://xkcd.com/378/
https://explainxkcd.com/378/
https://www.youtube.com/watch?v=UIKGV2cTgqA
Remember octal is just like decimal - if your missing two fingers.

Words can be decoded by:
hex
' ramdump . 9B58 ok

' called TICK gives the address of the machine code associated with the word and prints it with dot . It is always best to give your dump a spread before and after to see the full context. $ is hex and it shows the code beginning at $9B58 as 83 0 0 ...
Now look at the value before 'ramdump' and you will see it is 7 which is the number of bytes in the word 'ramdump.'

This area of flash is called the dictionary. Anything typed into eForth OS command line is interpreted immediately as a previous word command, a number or discarded. Colon begins a new word and semicolon ends it, the compiler then stores the new word in flash or RAM which then adds it to the dictionary.

\ the dump command needs to be fixed to show byte leading zeros and the html spacing here is bad.

$9B40 3F dump
9B40 64 75 6D 70 83 48 0 83 0 A CD 91 16 81 9B 3C dump_H____M____<
9B50 7 72 61 6D 64 75 6D 70 83 0 0 83 3 FF CD 91 _ramdump______M_
9B60 16 81 9B 50
A 69 6E 74 76 65 63 74 6F 72 73 83 ___P_intvectors_
9B70 80 0 83 0 7F CD 91 16 81 9B 64 6 62 75 66 66 _____M____d_buff ok

eForth is too small to store the source code so it is best to keep a text file in a project directory or folder. Using picocom the command ctrl-a ctrl-s will ask for the file name to be loaded.

In a text console I like to print out the file name to be sure.
ls /home/pi/Desktop/ForthPidrive/dumps.f
Then I copy the details and paste it into the eForth command.

NVM or nvm (Forth doesn't care) puts the following code into Non Volatile Memory = flash. RAM then restores new input default into RAM or ram.

NVM
: w words ;
: uniqid $4860 $1F dump ;
: eedump $4000 $27F dump ;
: optdump $4800 $0A dump ;
: ramdump 0 $3FF dump ;
: intvectors $8000 $7F dump ;
: buffer $350 $4F dump ;
: flashdump $8080 $1EFF dump ;
: gpiodump $5000 $7FF dump ;
: alldump CR uniqid CR eedump CR optdump CR intvectors CR gpiodump
CR buffer CR ramdump CR flashdump CR ;
RAM

Here CR is an eForth word equal to carriage return. eForth only has an 80 character buffer so it is required to separate long lines. Of course all commands are separated by space.

Debugging in this manner is exactly like it was done in the mid 60s to late 70s if one couldn't afford a development system or computer then the price of a house or two.

The beauty of eForth means that once the target has been blasted, one can throw away the source system like the Billion Dollar Brain (terrible movie) or in Tron, the MCP no longer is needed - End of Line.

MCP is in no way related to the 5 year old who passed the Miracle Soft exams. This is, after all, about real computing.
http://www.bbc.co.uk/news/technology-30054140

Non of this would be possible without the twisted minds of: Chuck, Thomas and C.H. Ting and others.
https://github.com/TG9541/stm8ef/wiki
https://hackaday.io/project/16097-efort ... 8s-gadgets
https://hackaday.io/project/18286-misc- ... 8-stm8s003
http://www.greenarraychips.com/home/about/bios.html


Sat Sep 30, 2017 2:31 pm
Profile

Joined: Wed Aug 21, 2013 7:38 am
Posts: 44
Post Re: STM8S103F3 Development Board (HCDVBD0034)
Running eForth on many of HC STM8S products, I highly recommend Thomas' excellent project.
https://github.com/TG9541/stm8ef

NVM
: eedump $4000 $27F dump ;
RAM
HEX
eedump
4000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ________________
...
4270 4F 43 54 31 37 20 32 30 31 37 0 32 32 31 37 0 OCT17 2017_2217_ ok

When I blast the chips with eForth I place the text date and version number in high eeprom.
There is currently no way to see which version is loaded but I have requested this feature. I need the sub-minor number added.
hi
stm8eForth v2.2
ok
One day it will hopefully be:
stm8eForth v2.2.17

Filling eeprom requires unlocking memory.
ULOCK
4000 26F 41 FILL \ note FILL does not write to the final location, bug or feature?

eedump
4000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
...
4260 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 0 AAAAAAAAAAAAAAA_
4270 4F 43 54 31 37 20 32 30 31 37 0 32 32 31 37 0 OCT17 2017_2217_ ok

The beauty of eForth is being able to change built-in words to suit, by adding new words for testing or even over-writing factory words.
HEX
NVM
: myfill ULOCK SWAP 1 + SWAP FILL eedump LOCK ;
RAM
4000 26F 39 myfill

LOCK \ when finally done writing to eeprom


Wed Oct 18, 2017 4:46 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 16 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD