First ever STM8 project! A simple function generator using an AD9833 - Page 1
Forum section: electronics / projects

author: prosper
author_rank: Regular Contributor
timestamp: April 26, 2021, 10:05:55 pm
content: Today I (mostly) completed my very first ever project using the STM8 microcontroller, and my first complete project using an environment other than Arduino. There are a bunch of features I want to implement sometime, but I achieved my main goal: to bumble around and get a development environment set up and working using SDCC and open source tools, and then to figure out the ST SPL.The project itself is fairly straightforward. All it does is control an AD9833 DDS module, and displays the current settings on an LCD. But along the way, I got to figure out how to:- write a driver from scratch using the datasheets- implement software filtering and smoothing (and oversampling) on the ADC- write my own delay routines using the timer peripherals- get on-chip debugging working (and use the debugger to configure the alternate function registers)- get printf() working to output to the LCD.... and a bunch of other new-to-me stuff.I documented everything as I went along on github and the accompanying wiki:https://github.com/prosper00/STM8-AD9833-Function-Generatorhttps://github.com/prosper00/STM8-AD9833-Function-Generator/wiki

author: rhodges
author_rank: Frequent Contributor
timestamp: April 27, 2021, 12:10:29 am
content: Good job! With a past including Z80, 6809, PIC, and some others, I really like STM8. ARM and STM32 is great, but if you don't need all that, why go there?For your browsing pleasure, feel free to look at my public STM8 libraries and projects here:https://github.com/unfrozenThe wiki pages describe how to use the functions. Welcome to the club!

author: prosper
author_rank: Regular Contributor
timestamp: April 27, 2021, 12:49:11 am
content: I'll check it out, for sure. I really like working with the stm8, it seems pretty ideal for a lot of tasks, and its nice n cheap. I do wish there was a version with a USB host/device peripheral though

author: HB9EVI
author_rank: Frequent Contributor
timestamp: April 27, 2021, 08:47:12 am
content: Nice job!however I'd recommend avoiding routines as printf() and use instead lowlevel lcd_out() functions

author: Renate
author_rank: Super Contributor
timestamp: April 27, 2021, 11:52:16 am
content: Function generators are interesting because everyone makes them and no two are the same.Quote from: prosper on April 27, 2021, 12:49:11 amI like USB peripherals and I have a bunch that I've made.If you program USB from scratch you might have some problems getting the first one to work.Having a hardware USB protocol analyzer can be very helpful.My function generator is an AD9850, ATMega32u4 and no hardware controls.

author: prosper
author_rank: Regular Contributor
timestamp: April 27, 2021, 02:39:49 pm
content: Quote from: HB9EVI on April 27, 2021, 08:47:12 amWhy, exactly? The main downside I can see is that printf() is a bit fat, and uses a quarter of my available flash. But I do like the ability to format output

author: prosper
author_rank: Regular Contributor
timestamp: April 27, 2021, 02:43:15 pm
content: Quote from: RenateI have lately been familiarizing myself with the CH55x chips - dirt cheapo chinese USB micros with a 1-t 8051 core. Having never done USB before, it's a learning experience. I can see the value of a hardware USB analyzer for sure. My 'scope is only barely fast enough for USB, so I've been reliant on wireshark to see what's going on.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: April 27, 2021, 03:22:33 pm
content: Quote from: prosper on April 27, 2021, 02:39:49 pmexactly because of that; these functions are not made to run on such a small device, they are slow and bloated. There are easy ways to format output without printf() or the string.h functions. with modulo and divide-by-10 you can easily format a float number without any need for printf().

author: Renate
author_rank: Super Contributor
timestamp: April 27, 2021, 03:59:21 pm
content: Quote from: HB9EVI on April 27, 2021, 03:22:33 pmFloat? OMG, who uses that?Use fixed point (fractional) numbers.All the cool people do!

author: prosper
author_rank: Regular Contributor
timestamp: April 27, 2021, 05:32:46 pm
content: SDCC also provides a few (non-libc) printf alternatives such as printf_small() and printf_tiny():Code:/** This tiny printf uses minimal code space, and it is fully reentrant* and register bank neutral (usually safe to call from within an* interrupt routine). Code size is under 270 bytes. Only one library* function is called (_gptrget, 41 bytes), in addition to calls to* putchar().** Five simple formats are supported**%dsigned 16 bit integer decimal (-32768 to 32767)*%uunsigned 16 bit integer decimal (0 to 65535)*%sstring, takes a 24 bit generic pointer*%ccharacter. You must explicitly cast to char in SDCC*%x16 bit integer in hex (0 to FFFF)** For a more complete printf that supports longs, floating point and* field width, try using printf_fast() or printf_large().*/