cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
7,890 Views
Registered: ‎03-07-2016

send character to pc via UART

Hello,

I am student and working on FPGA based real time data acquisition system. I am using spartan 3E starter kit and virtex ml605 kit. I have connected different sensors to FPGA, and I will use picoblaze (3 or 6) as UART to send sensor  data  to PC. I want to know how to send character and integers to PC one after another.. i.e. I want to diplay 

temperature=32'C,   range= 10 cm ,   force= 10

 temperature=35'C,   range= 21 cm ,   force= 22

etc. on hyperterminal...

can you help me on this topic??

do I need to convert everything into ascii?? or what will be input type for UART module using picoblaze- std_logic or character or integer??

 

0 Kudos
6 Replies
Highlighted
Advisor
Advisor
7,855 Views
Registered: ‎04-26-2015

So the idea is that Picoblaze reads data from a sensor on one of its 8-bit data ports, converts that into a meaningful format, and then emulates a UART to transmit it?

 

You will need to convert everything to ASCII. Some of this is straightforward (eg. the text can just be stored in the Picoblaze's ROM, no conversion needed). Other parts, like converting values from binary to individual decimal digits, is somewhat harder (you have to do division, and Picoblaze doesn't have a divide instruction). Presumably you might also need to do some maths on the values to turn them from raw sensor readings (eg. ADC counts) to degrees or centimeters.

 

 

 

I suggest you start with the basics. Get Picoblaze emulating a UART first, at 9600bps (giving you thousands of clock cycles between bits) and just outputting a simple count (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, ...).

0 Kudos
Highlighted
7,708 Views
Registered: ‎03-07-2016

how to convert variable binary values to ASCII ? OR how to convert character to ASCII ? is there any code available? 

0 Kudos
Highlighted
Advisor
Advisor
7,688 Views
Registered: ‎04-26-2015

Converting unsigned binary to ASCII is fairly straightforward.

 

Say you have a 16-bit value called "X". This is at most five (decimal) digits long. Top (fifth) digit:

 

D5 = X / 10000

(using integer division, so you don't end up with a fractional output)

 

Second-top (fourth) digit:

D4 = (X % 10000) / 1000 

(note that "%" refers to the modulo operator)

 

Third-top (third) digit:

D3 = (X % 1000) / 100

... and so on, until the lowest digit (1st) is:

D1 = (X % 10) / 1

That gets you five decimal digits, but they're still binary. Converting them to ASCII is as simple as ORing them with 0x30 (ie binary 00110000). That way 0111 (7) becomes 00110111 (0x37), which is the ASCII character "7".

 

The trick here, of course, is that Picoblaze doesn't know about division or modulo. An algorithm for Picoblaze might be along these lines:

 

uint16_t value = read_sensor();
const uint16_t powers_of_10[] = {10000,1000,100,10};

for (uint8_t current_index = 0; current_index < 4; current_index++) {

	uint16_t subtract_value = powers_of_10[current_index];

	uint8_t current_digit = 0;
	
	while (value >= subtract_value) {
		value = value - subtract_value;
		current_digit = current_digit + 1;
	}
	
	current_digit |= 0x30;
	uart_write(current_digit);
}

current_digit = value;
current_digit |= 0x30;
uart_write(current_digit);

No division, no multiplication, minimal register space required, and it'll only take a few hundred cycles to run.

0 Kudos
Highlighted
Anonymous
Not applicable
1,747 Views

Hello, I am student i have to finish my project soon as soon possible  my project is    to send data from a sensor to a PC via UART in viva do and i use micro zed board 7010 . I have been using zynq processor  and  axi interconnect and axi UART lite . i generated bit stream and there is no error but i have some problem in sdk how can i initialize UART ..

 also after the communication i have to use just  micro blaze without processor  i mean the PL part do i write vhdl code

 

Thank you for your time

 

 

0 Kudos
Highlighted
Moderator
Moderator
1,734 Views
Registered: ‎11-09-2015

Hi @Anonymous,

 

Our Community Help has a tip that might help you : Tip: If the message is older than 6-12 months, please post a new message rather than adding to the existing thread. Your inquiry will have a better chance of being picked up by an expert if it is a new topic.

 

https://forums.xilinx.com/t5/help/faqpage/faq-category-id/posting#posting

 

I would suggest you create a new topic on the appropriate board

 

Regards,


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos
Highlighted
Mentor
Mentor
1,705 Views
Registered: ‎06-10-2008


I suggest you start with the basics. Get Picoblaze emulating a UART first, at 9600bps (giving you thousands of clock cycles between bits) and just outputting a simple count (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, ...).

Although an old thread, this answer doesn't feel right. For a transmit only solution it might be doable, but when you also need to receive it becomes nearly impossible. Instead don't let the picoblaze emulate a UART, but connect it a UART in the FPGA.

 

And when converting a variable to ASCII for printing, always consider to use hexadecimal or octal codes. They can be created without division, but only require shift, and & or.

0 Kudos