Author Topic: First ever STM8 project! A simple function generator using an AD9833  (Read 3564 times)

0 Members and 1 Guest are viewing this topic.

Offline prosperTopic starter

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ca
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-Generator
 https://github.com/prosper00/STM8-AD9833-Function-Generator/wiki
 
The following users thanked this post: edavid

Offline rhodges

  • Frequent Contributor
  • **
  • Posts: 364
  • Country: us
  • Available for embedded projects.
    • My public libraries, code samples, and projects for STM8.
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #1 on: April 27, 2021, 12:10:29 am »
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/unfrozen

The wiki pages describe how to use the functions. Welcome to the club!
Currently developing embedded RISC-V. Recently STM32 and STM8. All are excellent choices. Past includes 6809, Z80, 8086, PIC, MIPS, PNX1302, and some 8748 and 6805. Check out my public code on github. https://github.com/unfrozen
 

Offline prosperTopic starter

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ca
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #2 on: April 27, 2021, 12:49:11 am »
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
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #3 on: April 27, 2021, 08:47:12 am »
Nice job!

however I'd recommend avoiding routines as printf() and use instead lowlevel lcd_out() functions
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1783
  • Country: de
    • Renate's Android Page
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #4 on: April 27, 2021, 11:52:16 am »
Function generators are interesting because everyone makes them and no two are the same.

I do wish there was a version with a USB host/device peripheral though.

I 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. >:D

My function generator is an AD9850, ATMega32u4 and no hardware controls.
 

Offline prosperTopic starter

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ca
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #5 on: April 27, 2021, 02:39:49 pm »
Nice job!

however I'd recommend avoiding routines as printf() and use instead lowlevel lcd_out() functions

Why, 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
« Last Edit: April 27, 2021, 02:44:37 pm by prosper »
 

Offline prosperTopic starter

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ca
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #6 on: April 27, 2021, 02:43:15 pm »
Quote from: Renate
I 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. >:D

My function generator is an AD9850, ATMega32u4 and no hardware controls.

I 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.
« Last Edit: April 27, 2021, 02:45:35 pm by prosper »
 

Offline HB9EVI

  • Frequent Contributor
  • **
  • Posts: 722
  • Country: ch
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #7 on: April 27, 2021, 03:22:33 pm »
Nice job!

however I'd recommend avoiding routines as printf() and use instead lowlevel lcd_out() functions

Why, 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

exactly 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().
 

Offline Renate

  • Super Contributor
  • ***
  • Posts: 1783
  • Country: de
    • Renate's Android Page
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #8 on: April 27, 2021, 03:59:21 pm »
... you can easily format a float number ...
Float? OMG, who uses that?
Use fixed point (fractional) numbers.
All the cool people do! >:D
 

Offline prosperTopic starter

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ca
Re: First ever STM8 project! A simple function generator using an AD9833
« Reply #9 on: April 27, 2021, 05:32:46 pm »
SDCC also provides a few (non-libc) printf alternatives such as printf_small() and printf_tiny():

Code: [Select]
/*
 * 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
 *
 * %d signed 16 bit integer decimal (-32768 to 32767)
 * %u unsigned 16 bit integer decimal (0 to 65535)
 * %s string, takes a 24 bit generic pointer
 * %c character.  You must explicitly cast to char in SDCC
 * %x 16 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().
 */
« Last Edit: April 27, 2021, 05:41:39 pm by prosper »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->