Bogy Posted June 21 Share Posted June 21 Hi, I'm new to the forum and a beginner with fpga's. I connected the buttons, leds and pins 0..13 through AXI_GPIO. And it works. How can I use a timer to implement a function similar to analogWrite from arduino? In the design I included two AXI Timers, the first one I already use to measure time. Thank you, Bogdan Link to comment Share on other sites More sharing options...
0 Bogy Posted June 22 Author Share Posted June 22 Hi, Finally I found the example that uses ADC. In Vitis 2024 it cannot be imported, but I was able to draw inspiration from there. In Vivado I added "Digilent Vivado Library" and used the PWM IP from there. When generating the platform, the PWM.h and PWM.c is generated. \export\platform_03\hw\sdt\drivers\PWM_v1_0\src\PWM.h sw\standalone_ps7_cortexa9_0\hw_artifacts\drivers\PWM_v1_0\src\PWM.h But these files are not found either by include or by the linker. I copied them into the application, but what would be the correct method to add them from the platform (in Vitis 2024)? Thank you, Bogdan Link to comment Share on other sites More sharing options...
0 Bogy Posted June 24 Author Share Posted June 24 Hello, I continued with the tests and encountered another problem. I set PWM to contain 4 channels and an AXI GPIO also with 4 channels. .xdc: ## RGB LEDs set_property -dict { PACKAGE_PIN L15 IOSTANDARD LVCMOS33 } [get_ports { pwm[0] }]; #IO_L22N_T3_AD7N_35 Sch=led0_b set_property -dict { PACKAGE_PIN G17 IOSTANDARD LVCMOS33 } [get_ports { pwm[1] }]; #IO_L16P_T2_35 Sch=led0_g set_property -dict { PACKAGE_PIN N15 IOSTANDARD LVCMOS33 } [get_ports { pwm[2] }]; #IO_L21P_T3_DQS_AD14P_35 Sch=led0_r #pwm on dp4 set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports { pwm[3] }]; #IO_L21P_T3_DQS_34 Sch=ck_io[4] set_property -dict { PACKAGE_PIN U14 IOSTANDARD LVCMOS33 } [get_ports { gpio_dp0_dp3_tri_o[0] }]; #IO_L11P_T1_SRCC_34 Sch=ck_io[0] set_property -dict { PACKAGE_PIN V13 IOSTANDARD LVCMOS33 } [get_ports { gpio_dp0_dp3_tri_o[1] }]; #IO_L3N_T0_DQS_34 Sch=ck_io[1] set_property -dict { PACKAGE_PIN T14 IOSTANDARD LVCMOS33 } [get_ports { gpio_dp0_dp3_tri_o[2] }]; #IO_L5P_T0_34 Sch=ck_io[2] set_property -dict { PACKAGE_PIN T15 IOSTANDARD LVCMOS33 } [get_ports { gpio_dp0_dp3_tri_o[3] }]; #IO_L5N_T0_34 Sch=ck_io[3] I can set 0/1 on dp0..3 and control the right rgb led with pwm, but on dp4 - I have no pwm signal. Where am I wrong? I hope I'm on the correct forum and section? :) Thank you, Bogdan Link to comment Share on other sites More sharing options...
0 Bogy Posted June 27 Author Share Posted June 27 Hello everyone, I posted this question a few days ago and added some updates since then. I would really appreciate any help or guidance on this matter. Thank you in advance! Link to comment Share on other sites More sharing options...
0 artvvb Posted June 27 Share Posted June 27 Hey @Bogy On 6/22/2024 at 4:16 AM, Bogy said: I copied them into the application, but what would be the correct method to add them from the platform (in Vitis 2024)? We don't have much experience with Vitis 2024.1 yet. As I understand it, the MSS files used to describe the drivers and make sure they are includable have been replaced by a JSON description - this means that the IP drivers likely need an update. You may be able to use Vitis Classic instead, which should already be installed, and be able to use the original files. As you've seen, copying the files into the application project manually is a good workaround. On 6/24/2024 at 3:02 AM, Bogy said: I can set 0/1 on dp0..3 and control the right rgb led with pwm, but on dp4 - I have no pwm signal. Where am I wrong? I hope I'm on the correct forum and section? :) To hazard a guess, when setting PWM duty cycles, please make sure you're calling PWM_Set_Duty four times, once for each of the PWM outputs. Thanks, Arthur Link to comment Share on other sites More sharing options...
0 Bogy Posted June 27 Author Share Posted June 27 Hi Arthur, Thanks for the reply. On the Vitis side, I think it will be easier to find solutions. As I am at the beginning and do not know either of the two environments, I chose Vitis 2024 (2023 initially) because it resembles VSCode and I have the impression that I navigate more easily between the sources and the included files. I think that I am doing something wrong in Vivado, probably because until now I have only programmed microcontrollers and I have not dealt with the hardware architecture. If more information is needed, I can provide it. // pwm constexpr u32 pwm_clocks = 102041; constexpr u32 pwm_scale = 400; constexpr u32 u_sec = 10000; void RGBLED_SetColor(u8 r, u8 g, u8 b) { PWM_Set_Duty(XPAR_PWM_0_BASEADDR, pwm_scale * b, 0); PWM_Set_Duty(XPAR_PWM_0_BASEADDR, pwm_scale * g, 1); PWM_Set_Duty(XPAR_PWM_0_BASEADDR, pwm_scale * r, 2); } void Motor_SetSpeed(u8 speed) { PWM_Set_Duty(XPAR_PWM_0_BASEADDR, pwm_scale * speed, 3); } void PWM_Init() { // Set PWM period to 102041 for a frequency of approximately 490 Hz (arduino) PWM_Set_Period(XPAR_PWM_0_BASEADDR, pwm_clocks); RGBLED_SetColor(0, 0, 0); Motor_SetSpeed(0); PWM_Enable(XPAR_PWM_0_BASEADDR); } u8 c = 0; for (c = 0; c < 255; c++) { RGBLED_SetColor(0, 0, c); usleep(u_sec); } RGBLED_SetColor(0, 0, 0); for (c = 0; c < 255; c++) { Motor_SetSpeed(c); usleep(u_sec); } Motor_SetSpeed(0); Led is ok, 0 on dp4. Thank you, Bogdan Link to comment Share on other sites More sharing options...
0 artvvb Posted June 27 Share Posted June 27 Hey Bogdan, Could you provide the full main loop for your C source? There's some code missing, particularly where it jumps from the end of PWM_Init to what seems to be the middle of a main function. For the hardware project, your constraints look correct. Assuming your project is set up with block and connection automation defaults, consider that the clock frequency for the PWM controller is 50 MHz. In the following screenshot, I've selected the FCLK pin driving the PWM, and the block pin properties pane shows 50 MHz: In the above, the only manual configuration was to set the PWM's "Number of PWMs" param to 4, and to make the "pwm" port external. You can view hardware sources for the PWM core in the IP packager (right-click, repackage IP), or online here: https://github.com/Digilent/vivado-library/blob/master/ip/PWM_2.0/hdl/PWM_v2_0.sv, and here: https://github.com/Digilent/vivado-library/blob/master/ip/PWM_2.0/hdl/PWM_AXI.sv. The important part to note is that the PWM counter in the first file runs at the AXI clock frequency - it rolls over after 102041 clock periods with a 50 MHz clock, so the full PWM period ought to be around 2 ms. There's a good shot that the signal isn't running at the frequency your arduino example code expects, though you should still be seeing the signal on the chipkit header pin. Simulating these source files in Vivado's built-in simulator could be a decent step toward understanding what exactly they're trying to do. Thanks, Arthur Link to comment Share on other sites More sharing options...
0 Bogy Posted June 28 Author Share Posted June 28 Hey Arthur, I have attached main.cpp - main.cpp The commented code is for an I2C test for which I created another post the other day - that one doesn't work for me either :(. The Block Design in Vivado is: Thank you, Bogdan Link to comment Share on other sites More sharing options...
0 Bogy Posted July 1 Author Share Posted July 1 Hello, I generated the same project in Vitis Classic and it worked. I finally found the problem. In Vivado, I initially made a configuration, after which I kept adding additional IPs and pins. Although I regenerated the bitstream every time and in Vitis I gave "Switch XSA" + clean both on the application and on the platform, it seems that they did not regenerate - and practically the application worked on the first version of the platform. In Vitis Classic, it automatically finds drivers\PWM_v1_0\src\PWM.h (.c), in Vitis Unified IDE it does not, instead it is much simpler to mix cpp and c code. In both I2C does not work. I also made an additional project only with PS and I activated I2C0 and I use XIicPs - I can't test anything on i2c. Thanks in advance for any suggestion related to project settings and i2c. Thanks, Bogdan Link to comment Share on other sites More sharing options...
Question
Bogy
Hi,
I'm new to the forum and a beginner with fpga's.
I connected the buttons, leds and pins 0..13 through AXI_GPIO.
And it works.
How can I use a timer to implement a function similar to analogWrite from arduino?
In the design I included two AXI Timers, the first one I already use to measure time.
Thank you,
Bogdan
Link to comment
Share on other sites
8 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now