Control FG085 from serial port

jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Control FG085 from serial port

Post 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.
113-08512-011.rar
(15.35 KiB) Downloaded 848 times
DN085-12v02_HowToControlFG085ViaSerialPort.rar
(566.2 KiB) Downloaded 1054 times
jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Re: Control FG085 from serial port

Post 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:
113-08512-012.rar
(15.32 KiB) Downloaded 909 times
vsoft
Posts: 9
Joined: Sat Sep 14, 2013 10:12 am

Re: Control FG085 from serial port

Post 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)?
jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Re: Control FG085 from serial port

Post 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.
vsoft
Posts: 9
Joined: Sat Sep 14, 2013 10:12 am

Re: Control FG085 from serial port

Post by vsoft »

Thank you, it sounds clear!
jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Re: Control FG085 from serial port

Post 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:
DN085-12v03_HowToControlFG085ViaSerialPort.rar
(550 KiB) Downloaded 998 times
113-08512-013.rar
(15.42 KiB) Downloaded 918 times
vsoft
Posts: 9
Joined: Sat Sep 14, 2013 10:12 am

Re: Control FG085 from serial port

Post 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:
http://www.youtube.com/watch?v=NbYevaa57f0

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.
jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Re: Control FG085 from serial port

Post 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.
vsoft
Posts: 9
Joined: Sat Sep 14, 2013 10:12 am

Re: Control FG085 from serial port

Post by vsoft »

http://victorx.eu/live/fg085s.zip

A short snippet of the video.
jye1
Posts: 1221
Joined: Wed Feb 20, 2013 4:58 pm

Re: Control FG085 from serial port

Post 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.
Post Reply