[–] [S] 1 point 6 months ago (1 child)

thanks for the reply. my goal is in fact to take what is at address 0xf0 and store it at 0x400. I know it resembles another beginner error but it's not this time :)

the example code I've given looks pretty contrived but I'll be using this to write startup code for a microcontroller, and the values starting at src are initial values in flash I need to copy over to dest which is SRAM.

  • source
  • parent
  • context
  •  

    I thought the book I'm reading had typos when I read code that uses this:

    uint32_t src = 0xf0;
    uint32_t dest = 0x400;
    
    int main() {
        *&dest = *&src;
    }
    

    However if you take a look at the decompiled version on godbolt: link this correctly takes the value at the address stored in src, and copies it to the address in dest.

    I'd love some help understanding what going on. The code looks like nonsense to me, "*&" should "cancel out" IMO.

    ========

    Meanwhile here's what I thought the correct code would be:

    uint32_t src = 0xf0;
    uint32_t dest = 0x400;
    
    int main() {
        *(uint32_t*) dest = *(uint32_t*) src;
    }
    

    Doesn't do what's expected, see decompiled: link. What's wrong with this?

    When the RHS is a constant it works fine, and seems to be a common pattern people use.

    [–] 11 points 6 months ago* (last edited 6 months ago) (1 child)

    There should be bounties to encourage getting specific software working on wine.

    And maybe even projects for coordinating work to fix issues wine has with specific software. Something like a wine-adobe-cc community on GitHub where everyone interested can come together.

  • source
  • submitted 6 months ago* (last edited 6 months ago) by to c/c_lang@programming.dev
     

    I'm trying to write a linker file to get C code running on a risc-v MCU (using riscv64-unknown-elf toolchain). My linker script looks like this, simplified:

    MEMORY {
            IRAM (rx) : ORIGIN = 0x00000000, LENGTH = 1024
    }
    
    ENTRY(_start)
    
    SECTIONS {
        .text : ALIGN(4) {
            *(.text)
        } >IRAM
    
    ...
    

    readelf -h correctly shows the entry point's address to be the same as where _start is in the output executable. But I want _start to be at 0x0, not somewhere else, so that when I objcopy it to a flat binary, the start code will be at the beginning. How can I do this?

    Right now I'm having the _start function go in a new section called ".boot" I've defined in the C file using __attribute__((section(".boot"))), then, placing this at the start of .text in the linker script like so

    ...
        .text : ALIGN(4) {
            *(.boot)
            *(.text)
    ...
    

    But IDK if this how it should be done.

    Thanks in advance :)

     

    Im working on a board for controlling a few linear actuators. They will at full load draw something like 10A, and will be powered by a 24V (or so) LiPo pack.

    I have a few H-bridges and as expected when the power is cut off, there is an inductive kickback of about 10A. No PWM, they will be turned on and off occasionally only.

    I havent been able to fibd anything on if a LiPo pack would be able to take this reverse current, or if it needs some sort of protection. It also lasts for quite a short time but I'm new to batteries so I want to be sure its not a problem.

    Would apprecaite any help :)

     

    This is from a section on why decoupling capacitors should be attached to CMOS chips. It shows current spikes during transitions. Which then because of the inductance of traces connecting power to the chip, will cause the power rail voltage to droop.

    But why is the ground voltage also shown to rise? What does it even mean for ground voltage to rise when ground is what voltage is measured against?

    [–] 2 points 11 months ago*

    Other than what others have suggested:

    • Do get an etch resist pen. The toner occasionally, even when it goes well, might not transfer on some spots of the copper plate. So you'll need the etch resist marker to color in breaks in paths etc. and fix these little issues.
    • The acid or whatever you use to etch away the copper might not work on some spots. Leading to shorts or otherwise unwanted connections. So do check with a multimeter the paths and pads that are close to make sure there arent shorts. You can scratch away unwanted copper with a blade.

    I dont think theres much more to add, its quite a simple process. Have fun :)

  • source
  • parent
  • context
  • [–] 5 points 11 months ago (8 children)

    The toner transfer method would be I think the most DIY method you can use. Make your pcbs entirely by yourself at home.

    Naturally wont give you as professional a result: no silkscreen, limited to 2-layer pcbs (2 sides of a copper plate).

    But it is a lot faster that having it manufactured (takes me like 1 hour for a pcb) and maybe this is debatable but it makes me feel like I have more room to make mistakes.

  • source
  • [–] 1 point 1 year ago* (last edited 11 months ago)

    Hi Im also a student but with a very a small budget. I figured I'd share some of the very cheap chinese boards Ive found. Cheap means some disadvantages ofcourse. Purchased one of these recently.

    1. The first are boards with Altera's Cyclone IV on them. Boards with the EP4CE6 (6K LEs) and EP4CE10 (10K LEs) can be found on AliExpress.

    Cyclone IV is supported by Quartus Lite so dev tools will be free. For the fpga itself Intel has documentation but for the peripherals on the board (if its a more fully-featured board) you either rely on the seller sending you pin numbers or finding it online documented by others.

    I got one with EP4CE6 (no VGA jack or other bells and whistles, just some LEDs and buttons) for what comes out as 10 euros or so. There are others that resemble proper dev boards (with connectors and stuff like 7-segment displays) costing something like 25 euros.

    1. There are also Sipeed Tang FPGA boards. They use Gowin FPGAs and Gowin's IDE is free. The Tang Nano 9k has been shown to run the PicoRV32 RISC-V core. It costs 15 euro on Aliexpress. The downside is that Gowin tools ofcourse wont be as good as Intel's Quartus.

    Also interesting to note that the Tang Nano 4K has a Cortex M3 on it so I think it counts as an Fpga-Soc? I think its fun and might get one some time.

  • source
  • [–] 3 points 1 year ago* (last edited 1 year ago)

    Here's a script I use a lot that creates a temporary directory, cds you into it, then cleans up after you exit. Ctrl-D to exit, and it takes you back to the directory you were in before.

    Similar to what another user shared replying to this comment but mine is in bash + does these extra stuff.

    #!/bin/bash
    
    function make_temp_dir {
        # create a temporary directory and cd into it.
        TMP_CURR="$PWD";
        TMP_TMPDIR="$(mktemp -d)";
        cd "$TMP_TMPDIR";
    }
    
    function del_temp_dir {
        # delete the temporary directory once done using it.
        cd "$TMP_CURR";
        rm -r "$TMP_TMPDIR";
    }
    
    function temp {
        # create an empty temp directory and cd into it. Ctr-D to exit, which will
        # delete the temp directory
        make_temp_dir;
        bash -i;
        del_temp_dir;
    }
    
    temp
    
  • source
  • parent
  • context
  • [–] [S] 1 point 1 year ago (1 child)

    Thanks for your reply, that certainly a method I will try using.

    But in the case of my problem I think it won't work. Since adc_data is in the consequent of the implication, it will again be sampled in the prepone region and so take on the value before adc_data_en was asserted high, don't you think?

    In my code I set adc_data to its new value and at the same time set adc_data_en high. Perhaps I'm not supposed to do things this way? Is the usual practice to set something like adc_data to it's new value some time before the enable is asserted?

  • source
  • parent
  • context
  •  

    This is for an ADC. What I'm trying to do: when adc_sample goes low, grab hold of a value. Then when adc_data_en goes high, compare it with adc_data. Here's what I have so far:

        property adc_deduces_voltage;
            bit [7:0] true_voltage;
    
            @(negedge adc_sample) (`true,true_voltage=input_channel) 
            ##1 @(posedge adc_data_en) 
            // Values are sampled in the prepond region. This would be before
            // adc_data_en is high, giving us old values. To make up for this, wait
            // for one more clock cycle so that sampled values will be just after
            // adc_data_en is high.
            ##1 @(posedge clock) (adc_data == true_voltage, $display("Pass. Actual: %d, ADC: %d", true_voltage, adc_data);
        endproperty
        assert property (adc_deduces_voltage);
    

    Note the comment I inserted. The hacky bit of my code is waiting for the next rising edge of the clock so that I can avoid the issue of things being sampled in the prepone region.

    Any thoughts on improving this? Is there a better way to do this?

    Also, what if I wanted to do something like: wait for negedge adc_sample, then posedge adc_data_en then 20 clock cycles later carry out checks?

     

    I'm using an Arduino and through a library working with an IC (MCP2515, a CAN controller) over SPI. The IC indicates interrupts by causing a falling edge on an interrupt pin.

    Components are connected using jumper wires on a breadboard.

    • When a logic analyzer is not attached, the IRQ gets called a few hundred times. It should only be called once. I thought it must be noise on the external interrupt pin but a pull-up doesn't help. I've tried the internal pullup and an external one.
    • Trying to see if there is a ton of interrupts from the IC, or an error internal to the Arduino, I attach my logic analyzer. Now it works perfect.

    Any idea what might cause such a weird issue? Looking around I haven't found anything.

    EDIT: I found a Reddit post for a different circuit where a user suggested placing a small capacitor to make the edges of a signal rise slower. This has fixed my problem.

    Since I've already created a post: does anyone know why I was getting an unending number of interrupts? Why would the edges of the interrupt signal changing too fast cause something like this?

     

    Not sure if this is a dumb question but this has me quite puzzled.

    The legs on TO220 packages are very small. How is it that there are e.g MOSFETS rated as being able to continuously conduct ~100A? e.g IRF1404Z

    From what I understand such large currents need busbars on PCBs and these appear a lot larger than the legs on these components.

     

    I'm making a driver for a small 15V, hall sensored, 9-slot BLDC motor I got off of AliExpress. It has u,v,w inputs. Three hall outputs and Vcc, Gnd for them. No datasheet :)

    I understand the working principle: I'll have to use the hall sensors to figure out the location of the rotor, then power the appropriate windings.

    Trouble is, I don't know how the windings for the three phases are arranged within the motor. So I don't know which pin to give power to, because I don't know which windings within the motor will then be powered.

    How can I figure out where the windings are for each phase?

    I'm guessing I've got to manually spin the motor and do some detective work with back-emf measurements and hall sensor outputs to figure this out?

    view more: next ›