Matthew Barr (@matthewbarr)

Logic and digital circuit design in ASIC and FPGA, embedded firmware and software design, 30 years.

Re: Determining the index of a value in a struct

Reply posted 1 year ago (08/05/2021)
Hi Max, my understanding is that the compiler handles memory layout behind the scenes for the two representations in the union, and there is no language defined,...

Re: How to fix CAN Bit Stuffing Error

Reply posted 2 years ago (04/05/2021)
I emphatically agree with MichaelKellet's great answer. Definitely have a look at CANbus activity using a scope with CANbus serial decode capability. You can learn...

Re: casting to union type vs struct type

Reply posted 2 years ago (03/31/2021)
A cast tells the compiler that the storage (raw byte data) associated with an object of one type should instead be interpreted as a different type.When one of the...

Re: casting to union type vs struct type

Reply posted 2 years ago (03/30/2021)
You may have trouble casting if there is a memory size or a memory alignment boundary mismatch between variable and struct.In general you should be looking for...

Re: Communication protocol suggestions

Reply posted 2 years ago (03/22/2021)
I agree with your comment on CANopen. MODBUS is straightforward but plug-and-play is problematic because the single Master must initiate all communications. You...

Re: Cache memory vs volatile

Reply posted 2 years ago (03/19/2021)
Indeed, it depends entirely on what the compiler knows about the variable and how it handles it. As the comment indicates in your code example, it would be unsafe...

Re: Cache memory vs volatile

Reply posted 2 years ago (03/19/2021)
Great answer Mark. Variables that can be written by non-interrupt code and by an interrupt service routine are another common situation where a volatile declaration...

Re: SDKs and project management

Reply posted 2 years ago (02/08/2021)
Yes, when I used the Lantronix XPort they distributed their SDK in the form of a VMware linux image. Seems kind of cumbersome for everyday lighweight project use,...

Re: SDKs and project management

Reply posted 2 years ago (02/08/2021)
Great observation, I couldn't agree more. Ideally someone would be able to commit just project source files and build recipe (project files, Makefiles, whatever)...

Re: How do you test Ethernet? (Manufacturing)

Reply posted 2 years ago (12/08/2020)
Yes, much better, I've developed those test hooks and related phy/link tests for IEEE 802.3ae SerDes designs. Remote (vs. local) loopback capabilities are often...

Re: How do you test Ethernet? (Manufacturing)

Reply posted 2 years ago (12/06/2020)
Hi Matthew,I have manufacturing test experience with one relevant product which consisted of a number of small board assemblies, one with a 1000BASE-T interface.The...

Re: Software driver SPI I/O expander

Reply posted 2 years ago (11/29/2020)
Without knowing the real time requirements of your application it is hard to be very emphatic about a recommended approach. You are absolutely correct to worry...

Re: Karnaugh Map Minimizations

Reply posted 2 years ago (11/24/2020)
Hi Max, I think your map decodings look good, if you missed anything then so did I. In your discussion it might be worth noting that you can also decode 0's and...
Yes! Toggle switches are painful to debounce, you put a scope on the thing and you can't believe what you're seeing...
Hi Max, interesting question, "circuits/funtions" covers a lot of territory!There are canned debounce ICs available from various sources. Easy and reliable, this...

Re: RF integrating with pic

Reply posted 2 years ago (09/02/2020)
Oh, from your original post I didn't realize you were this far along, the slow reveal!What you have done makes sense, and you might want to spend some time debugging...

Re: RF integrating with pic

Reply posted 2 years ago (09/01/2020)
You have a lot of choices, and it seems like standard wireless protocols (BLE, Zigbee) and LoRa wireless transceivers would work but are probably overkill. If you...

Re: Advice on resetting local function variables

Reply posted 2 years ago (06/27/2020)
Yes!You might eliminate the local variable target and explicitly cast:rampAccumulator = ((uint32_t) value) << 8;

Re: Advice on resetting local function variables

Reply posted 2 years ago (06/27/2020)
For these kinds of variables I will typically define them in a C source file outside of the functions that use them, and create one or more init functions as...

Re: Software Bugs

Reply posted 3 years ago (05/27/2020)
> Do you think that it would be feasible to write the Fighter's software in assembly language?Yes> If so, do you think the software bugs' quantity would be...

Re: Improvement in Software design

Reply posted 3 years ago (05/05/2020)
I agree with Michael, it isn't obvious why you return struct2 as opposed to just letting fn() fill in the return information you care about in struct1.If you really...

Re: Does anyone have experience in RFSoCs?

Reply posted 3 years ago (04/21/2020)
The best way to come up to speed on a complex SoC device like this is to start with an example project. Familiarize yourself with the device architecture and board,...

Re: strcmp help please

Reply posted 3 years ago (04/08/2020)
Yes, agree with all that! C++ brings its own baggage to the party, but class instantiation, encapsulation and consistency checks are worth the cost. With C you...

Re: strcmp help please

Reply posted 3 years ago (04/07/2020)
OK, I just took a closer look at this. I've never tried to make this work with one buffer. I've typically used two buffers, a receive buffer where an RX interrupt...

Re: strcmp help please

Reply posted 3 years ago (04/07/2020)
Yes, absolutely correct, you have to pay attention to that. Using string lengths to trigger the comparison makes sense whether you use strncmp() or strcmp() because...

Re: strcmp help please

Reply posted 3 years ago (04/07/2020)
Yes! I couldn't agree more emphatically with this. Spend as little time in the ISRs as possible, keep them dead simple. Perform all of your string or message handling...

Re: strcmp help please

Reply posted 3 years ago (04/07/2020)
As others have pointed out, strcmp() requires NUL terminated strings.You also have the option of using strncmp() if you know your string length. A NUL termination...
Based on the devices you connect to your microcontroller, you either need a serial interface or you don't.You typically use SPI or I2C to communicate (configure,...

Re: Rolling over before reaching 256 (8051)

Reply posted 3 years ago (02/08/2020)
...

Re: Rolling over before reaching 256 (8051)

Reply posted 3 years ago (02/08/2020)
Hi mik3ca,It sounds like you want to be able to encode 256^3 possible values with only 253^3 encodings? This is like looking for a way to encode 4 values in...

Re: Rolling over before reaching 256 (8051)

Reply posted 3 years ago (02/08/2020)
Yes! COBS is a great approach, it allows you to use a single 0x00 between packets to delimit packet boundaries. COBS guarantees 0x00 doesn't appear in the encoded...

Re: Event Driven Frameworks

Reply posted 3 years ago (01/14/2020)
With 4k words program memory and particularly with 192 precious bytes of RAM, you are going to need a very lean event-driven real time framework in order to have...

Re: 74F07N Hex Buffer And a Pixel Question!

Reply posted 3 years ago (12/27/2019)
Ignoring the cable for the moment, the 470 ohm resistor determines how fast your signal will transition from low to high. The open collector driver sinks current...

Re: Digital PID controller implementation in C++

Reply posted 3 years ago (12/05/2019)
That's interesting, different from how I've learned to look at integral error.I've been taught that integral error is intended to prevent the system from running...

Re: Digital PID controller implementation in C++

Reply posted 3 years ago (12/02/2019)
Yes, or simply re-initialize (zero) the integral error when exiting blocked mode and let it start re-accumulating. Likewise with derivative error, re-initialize...

Re: Digital PID controller implementation in C++

Reply posted 3 years ago (11/27/2019)
It looks like your bumpless transfer assignment is supposed to prevent this from happening:m_U1 = *m_Trk; // u(k-1) <- last actually used control value (for...
Good luck with this. An organization that doesn't have the discipline to develop and embrace their own design best practices may be unwilling to embrace a starting...
Various design standards (coding, safety, regulatory compliance, etc.) more commonly apply to an industry. If you're working in a particular space you have to use...

Re: Hall sensor Pattern

Reply posted 3 years ago (11/06/2019)
Yes! I would write == TRUE instead of != FALSE (or just omit the != FALSE) but same logic in any case. I believe you can better optimize your C1 and C2 computations:C1...

Re: Hall sensor Pattern

Reply posted 3 years ago (11/04/2019)
1. IDLE/ACTIVE is used to keep track of whether or not you have a conversion running. You may be able to discern this from ADC status registers, in which case you...

Re: Hall sensor Pattern

Reply posted 3 years ago (11/01/2019)
I think you're on the right track, but with a super-loop you generally want to keep everything non-blocking, particularly when you care about real time behavior....

Re: Hall sensor Pattern

Reply posted 3 years ago (10/29/2019)
I'm sorry, I don't have any familiarity with that TI DSP platform. It sounds like there is a problem driving the top side switches based on the current Hall state...

Re: FIR Convolution Compile Error

Reply posted 3 years ago (10/17/2019)
The tools seem to be trying to tell you that somewhere you have an output pin definition or configuration problem. If this is a configurable device the so-called...

Re: Industrial RS485 converters

Reply posted 3 years ago (10/06/2019)
With high speed differential line drivers, typically a vast majority of the current and power dissipation is associated with driver stage. At high data rates the...

Re: Industrial RS485 converters

Reply posted 3 years ago (10/05/2019)
That's a long distance, which will probably limit your data rate. The fact that you are point to point (vs. multi drop) should help.I'm puzzled about your UART...

Re: Digital PID controller in velocity form

Reply posted 3 years ago (08/13/2019)
Interesting approach to anti-windup, I've not seen this before and it makes great sense. If I understand correctly, the idea is to prevent integral state accumulation...

Re: Hall sensor Pattern

Reply posted 3 years ago (08/06/2019)
Short answer is yes!I'm guessing someone wants you to get this working, then extend to closed loop operation. The commutation block in your diagram should perform...

Re: Hall sensor Pattern

Reply posted 3 years ago (08/05/2019)
I think there's a problem in your understanding here. Duty cycle is not computed or derived from anything in this open loop operation case, it is an input to the...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/27/2019)
If they've got code examples for a basic BLDC controller I'd start there.The very first thing you should do is get a dead simple demo project to build, load and...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/27/2019)
Yes, very nice! Note that your back-EMF phase sequence top-to-bottom is A-C-B rather than A-B-C. Again, the important thing is to apply power from the bridge consistently...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/27/2019)
Hey, that looks reasonable! I'd re-order your table this way, this should be the electrical cycle commutation state sequence from top top bottom:Switching StateH1H2H3A+B-010A+C-110B+C-100B+A-101C+A-001C+B-011You...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/27/2019)
Yes on the electrical cycles, 8 poles (4 pole pairs) should give you 4 electrical cycles per mechanical revolution. You'll see one complete cycle on each Hall sensor...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/25/2019)
With motor phases attached to a resistor "Y" and Hall sensors powered, I manually cranked a motor in both directions and captured back-EMF and Hall sensor waveforms...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/24/2019)
Here's a brief article talking about 60 vs. 120 Hall spacing, you should be able to tell from the posedge relationships relative to a full cycle:Parker 60 120...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/24/2019)
First a quick sanity check, Hall sensors are typically powered from 5V and the outputs are open drain, requiring pullup resistors to the 5V supply. (There is often...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/22/2019)
I think the voltage for this exercise is not particularly important, the important thing is use a reasonable current level! There's very little phase resistance,...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/21/2019)
OK, I have to call shenanigans on Figure 10 and Tables 1 and 2 in the Microsemi document! If you're trying to learn from this atypical if not just plain incorrect...

Re: Hall sensor Pattern

Reply posted 3 years ago (07/19/2019)
Here are a couple plots showing the relationships between line-to-neutral back-EMF, Hall sensor inputs and the related bridge driver states for a particular motor....

Re: Hall sensor Pattern

Reply posted 3 years ago (07/19/2019)
I fundamentally agree with mr_bandit's answer. You really have 3 options:1. Obtain the Hall sensor wrt. phase timing information for your motor.2. Reverse engineer...
I just want to add that today's commercial motor control solutions are far more sophisticated and elegant than a simple trapezoidal control solution.It is common...
The minimum pieces you need to develop are a core control loop or loops, bridge (gate driver) commutation state decode from PWM and Hall state, an average current...
It sounds like you're controlling the 6 inputs to the bride gate drivers directly from low voltage outputs on your micro.What sort of PWM scheme are you considering?...

Re: What do *you* call "Deeply Embedded"

Reply posted 3 years ago (06/21/2019)
Yes indeed! I think most would agree that firmware for a fixed-function sensor with some type of serial interface and no human UI qualifies as deeply embedded,...

Re: What do *you* call "Deeply Embedded"

Reply posted 3 years ago (06/21/2019)
This seems more of a marketing than technical distinction, based mainly on complexity. Any attempt to define "deeply" based on clear objective criteria (memory...

Re: MSP432+BLE+ Debugger interfacing

Reply posted 3 years ago (06/14/2019)
Hi Moga, if you are thinking that you will easily be able to flash the BLE device from the debug probe through the MSP432, I suspect you are going to be disappointed.For...

Re: MPLab and XC8 file organization

Reply posted 3 years ago (06/10/2019)
I was going to answer, but now I don't have to! I agree with all the comments and suggestions in Mr_Bandit's answer. In particular, read the data sheet, there is...

Re: Datalogger for an embedded system

Reply posted 4 years ago (03/12/2019)
I think something like that would work. The issue I see looking at your "skip" examples in an earlier post is that you've got many special cases to consider due...

Re: Datalogger for an embedded system

Reply posted 4 years ago (03/11/2019)
One thought on header numbers, I think there is a way to eliminate your "skip" case so you only have to detect a non-sequential header number boundary. Lets assume...

Re: Datalogger for an embedded system

Reply posted 4 years ago (03/11/2019)
Interesting. Not knowing any better, I had assumed that you would be looking for the wrap-around boundary associated with the most recently written header so you...

Re: Datalogger for an embedded system

Reply posted 4 years ago (03/10/2019)
Hi Steven,I wrote essentially the same flash logger as you describe not that long ago. The total number of circular buffer slots was not large, so a linear search...

Re: Shorting GPIO internally = reset and no problem?

Reply posted 4 years ago (01/27/2019)
They're using the sign to indicate the direction of current flow, negative when sourcing (Voh) and positive when sinking (Vol).For a digital push/pull output,...

Re: Shorting GPIO internally = reset and no problem?

Reply posted 4 years ago (01/27/2019)
That 25 mA number is probably an absolute maximum rating, you don't want to operate there. Look at the Voh and Vol specs, they'll give you a min high and max low...

Re: Shorting GPIO internally = reset and no problem?

Reply posted 4 years ago (01/27/2019)
If you have a GPIO that you are using as a digital input, you would set the the data output register to a 1 and configure the output control as open drain. Don't...
It sounds like your protocol really only needs one address, the client address. You would need sender and recipient if you wanted to support client-to-client communications,...
:-)Even in the 8051 world you can find inexpensive devices with 64k code space and more, and with 2k-8k XRAM. As an added bonus you can even program them in C,...

Re: Stack - interrupt, function call?

Reply posted 4 years ago (01/04/2019)
We have a consensus!

Re: Stack - interrupt, function call?

Reply posted 4 years ago (01/04/2019)
The short answer is that it depends on the processor architecture, there is no one-size-fits-all answer to your question. One processor may save minimal architectural...
Here's the argument for having more time to process RX data with a simple ISR and buffer.With an RX buffer of N character times and a simple ISR, you basically have N...
Wow. Kudos for nutting this out in assembler and getting it to the point of functional even with some performance issues. It isn't obvious why you're coding in assembler...
It sounds like you may have a problem reliably framing receive packets, particularly in the presence of errors where you have to flush data so you have an empty...
Yes on the client/server nomenclature!
You've accounted for the 2 + 2 ms to send + receive 11 bytes at 56 kbps, and have added 6 ms for processing time.That's would be 6 ms processing time total, 3 ms...

Re: Adding a percentage to a 16-bit number in 8051

Reply posted 4 years ago (12/06/2018)
Normally one would write code like this in C, you'd do the math with floats and convert back to integer. The overhead is not bad, particularly if you avoid division,...

Re: Help designing Embedded PI Controller

Reply posted 4 years ago (11/22/2018)
The Wikipedia PID control page has a nice pseudo-code algorithm near the bottom, PID with Kd=0 collapses to PI. Their computation is slightly rearranged, they factor...

Re: Help designing Embedded PI Controller

Reply posted 4 years ago (11/21/2018)
The dt term is usually the discrete PI controller update period in seconds. For a fixed Ki it will decrease the contribution of the integral term at each update...

Re: Help designing Embedded PI Controller

Reply posted 4 years ago (11/21/2018)
Turning down Kp is certainly the main knob to control overshoot at startup, Kp is essentially your loop gain.If you request a target RPM of 3000 starting from 0...

Re: Help designing Embedded PI Controller

Reply posted 4 years ago (11/21/2018)
As BVRamesh has pointed out, you have to determine an appropriate low RPM limit for your application and factor this into your control loop update interval. You...
I think you have this right, exact terminology may vary depending on what you're reading or who you're talking to. What is called clock latency in the first diagram...

Re: SPI communication

Reply posted 4 years ago (06/13/2018)
In general it should not be necessary to send an all 0's pad byte in front of a defined data transfer for a particular SPI slave device.  If it is necessary, the...

Re: Bit error rate (bit off topic)

Reply posted 5 years ago (03/01/2018)
You might take a look at the Wikipedia page on bit error rate, a good starting point for many topics.I don't know anything about your transmission environment, so...

Re: Help with reverse polarity(strange) SMA connector

Reply posted 5 years ago (11/23/2017)
RF is not my bag, but if you search for "rp sma male to sma female adapter" or "rp sma male to sma female cable" I think you'll find what you're looking for. For...
I have no experience with this TI platform which makes this little more than a guess, but it appears that the load on the AUDIO signal changes when you plug in...

Re: Power supply for router.

Reply posted 5 years ago (09/26/2017)
Assuming your LM1117 is good to 800 mA, try setting the lab supply current limit to 800 mA and see how things go. If you then see a hang with the lab supply, perhaps...

Re: Disabilitate the cache of Leon 3 in Tsim

Reply posted 5 years ago (07/08/2017)
First a disclaimer, I am not familiar with Leon 3 so this comment may be off mark.You wrote: "I'm sure that the bits in the register are changed but when I do the...

Re: BusOff state question

Reply posted 6 years ago (05/11/2017)
I am at risk of telling you more than I absolutely know, but I think you are getting transmit errors with CANH/L shorted that you would not see with a normally...

Re: BusOff state question

Reply posted 6 years ago (05/10/2017)
Does "disturbance" mean that you simply don't respond to a request, or do you actively interfere with bus activity?If the disturbance is the temporary absence of...

Re: Communication protocol implementation

Reply posted 6 years ago (04/04/2017)
Wow, you have my sympathy here, assignments where someone else has done the conceptual work and you get to finish it can be difficult. It really depends on how clean...

Re: Communication protocol implementation

Reply posted 6 years ago (04/04/2017)
As already mentioned, this is a very general question with no background context, so providing any specific suggestions is guesswork.Are you dealing with a point-to-point...

Re: MCUs with hardware ids.

Reply posted 6 years ago (03/16/2017)
There are Silicon Labs 8-bit MCUs that have 4 8-bit registers, SN0 SN1 SN2 and SN3, that define a unique 32-bit device serial number. See the data sheet for the...
Yes, good point. Offline in Table 4 really means Offline or Offline Bias. The transceiver won't go into Offline Bias without the right activity on CANH/L and being configured...
CAN bus is a bus just as the name implies, transceiver CANH and CANL pins are all directly connected in parallel with a termination at each end of the bus. The...
I think the answer you are looking for is in Table 34 on page 38. See Vo(dif) and Vo(rec). Refer to the voltages related to CAN Offline mode, Table 4 on page 8...

Use this form to contact matthewbarr

Before you can contact a member of the *Related Sites:

  • You must be logged in (register here)
  • You must confirm you email address