Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] Trouble making sense of serial / timer interrupt speeds (STM32F103c8)

Status
Not open for further replies.

JakeKarson

Newbie level 1
Joined
Mar 13, 2020
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
19
So on my STM32F103c8(T6) that I program in the Arduino interface, I have setup a hardware timer at 1 kHz and a Serial baud rate of 1.5 MHz. The interrupt handler simply updates a volatile long int t to set it to the current time using micros().

The program is an infinite loop where if a change in t is noticed, the value of t is transmitted over serial in binary using Serial.write(). With the 1 kHz timer, this works fine: if I log the signal with Putty, I get exactly what I expect. However, if I increase the frequency to 2 kHz, I receive nonsense (the signal looks like noise with an amplitude of a billion).

This I do not understand. With 1.5 MHz baud rate, in theory you can send unsigned ints at 46.875 kHz. Why can it do 1 kHz but not even 2? Also, although the microcontroller should support 4.5 Mbit/s USART speeds, a baud rate of 2 MHz does not work either. I need a 8 kHz PID control loop for my project.
 

What oscillator are you using ? (mcu clock speed)
 

Hi,

1.5MBaud is rather high and no usual standard. What is the receiver and what interface, cables, cable length do you use?
...But I assume the baud rate is not the key problem.

"Volatile long int" is a 32 but variable? Please confirm.
If so, it is a multi byte transfer.
If it is sent as raw binary, then 4 bytes have to be transmitted, means 40 bits (with 8N1).

With low data rate (1kHz) there usually is a relatively large gap of idle on the bus, thus it is very likely that the frame = 4 bytes is automatically synced with the use of the gap.
But with faster data rate, the gap becomes smaller and maybe the receiver loses frame sync. Then the reciver does not know which 4 bytes are a frame and thus maybe uses 2 bytes from the previous frame and 2 bytes from the new frame. Giving nonsense output dara at the receiver.

Another possible problem is, that the serialWrite() routine is slow. Arduino isn't the most processing time effective compiler.

A scope picture could give more informations.
Or adding debug lines in your code, like:
* SET an output pin before the serialWrite()
* and CLEAR the output pin after the serialWrite()
With a scope you may detect if the rate is the expected 2kHz, you will see the jitter, and you will see how long the serialWrite() needs.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top