Page 1 of 2

Control FG085 from serial port

Posted: Tue Aug 27, 2013 5:24 pm
by jye1
Dear folks, we recently received email from a customer asking for information about the rotary encoder. He was doing a project to control FG085 from an Arduino by emulating the keypad. Inspired by his project we modified the firmware to allow the instrument be controllable via the serial port. This could be interesting to those who want FG085 work in a programmatic way. Please see attachment for the hex file and document. Any feedback is appreciated.

The firmware is for chip U5. It was based on firmware version 113-08501-130. It has everything that -130 has. Please remember also upgrade U6 to 113-08502-050 if it contains earlier version. Otherwise the instrument won't work correctly.
(15.35 KiB) Downloaded 635 times
(566.2 KiB) Downloaded 826 times

Re: Control FG085 from serial port

Posted: Wed Sep 04, 2013 9:13 pm
by jye1
A bug found (thanks to Yuzo from Japan!) in the firmware which caused frequency can not be changed from serial connection unless manual change has been done at least once. This is the corrected one:
(15.32 KiB) Downloaded 673 times

Re: Control FG085 from serial port

Posted: Sun Sep 15, 2013 10:49 am
by vsoft
I have ordered the FG085 just because it allows programmatic control.

The How To Control document says:
Because microcontrollers (or PC) could send button codes much faster than that from key pad
it will cause button codes lost if FG085 can not handle quick enough. To prevent this from
happening you can send special button code 0xA1 which enables postpone code reception
until the present code has been processed.
Two questions:

1. How fast does FG085 handle commands? How many times per second it can change frequency and amplitude? Any estimates?
2. Please explain how the postpone code reception works. Would it hold writing from my PC application to a serial port (via USB)?

Re: Control FG085 from serial port

Posted: Tue Sep 24, 2013 10:50 pm
by jye1
There is a 300-byte FIFO reception buffer for the serial port. Incoming data are saved to the buffer by background subroutines. At foreground the microcontroller handles keypad, serial buffer, and display in turn in the main loop. At serial buffer handling, once started, it normally will process all saved bytes in the buffer before exit. This would result in button loss if multiple button frames have already been saved in the buffer when the microcontroller starts the processing. What the special button code 0xA1 does was to tell the microcontroller do not process next button until a received button has been executed.

By estimation most buttons (from the keypad or serial port) are handled in milliseconds because they usually only affect display change. Unit buttons, which terminate an input sequence, could take about 100 ms to execute due to the communication with the DDS chip (U6, ATmega48).

The microcontroller only returns character 'G' when a frame is successfully received. It does not affect any PC activities. It is the responsibility of external applications to hold off sending to avoid overflowing the 300-byte reception buffer.

Re: Control FG085 from serial port

Posted: Wed Sep 25, 2013 5:07 am
by vsoft
Thank you, it sounds clear!

Re: Control FG085 from serial port

Posted: Tue Oct 08, 2013 3:34 am
by jye1
Another special command was added to place cursor to intended location (i.e. Freq, Amp, or Ofs). This command only takes effect when the generator is under CW mode. With this command remembering cursor position is not required.

Updated document and firmware:
(550 KiB) Downloaded 775 times
(15.42 KiB) Downloaded 691 times

Re: Control FG085 from serial port

Posted: Thu Oct 24, 2013 6:25 pm
by vsoft
The new commands that set current cursor position are very helpful, thank you very much!

Everything works fine as can be seen on this short video:

The only problem is that control frames are sometimes ignored even though they are acknowledged by 'G' response - that is my first impression after a few hours of experiments with the FG.
For example, sending a sequence of frames to set amplitude like 0xa2, 'A', '0', '.', '5','3','1','H' (here I only show the frame payload for clarity sake) might set the value 0.3 V, and then within ~200ms all frames are apparently ignored.

I expected shorter latency - though I understand that the device has not been designed as a musical instrument.

There is just one command missing: it would make me totally satisfied if I could set desired waveform regardless of the current selection.

Re: Control FG085 from serial port

Posted: Sat Oct 26, 2013 12:42 am
by jye1
Thank you for the video. Unfortunately it couldn't be opened within China :( .

For the sequence you gave the amplitude should be set to 0.5V and '3', '1' would be dropped because of resolution limitation.

I will think about adding a waveform selection command. Ideally all parameters should be able to be set by straightforward commands. Because there is very little (about 1%) code space left we can't implement that way. Waveform selection is relatively simple. I think it should be ok.

Re: Control FG085 from serial port

Posted: Sat Oct 26, 2013 8:49 pm
by vsoft

A short snippet of the video.

Re: Control FG085 from serial port

Posted: Sat Oct 26, 2013 11:52 pm
by jye1
Thank you for the video. The shown behavior was correct. Frequency resolution is 1Hz. Amplitude and offset resolution is 0.1V. Any extra digits entered will be truncated.