User Tools

Site Tools


tiger_programmable_logic_card

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tiger_programmable_logic_card [2019/05/13 23:50]
jon [Clock]
tiger_programmable_logic_card [2019/05/24 16:54]
jon
Line 232: Line 232:
 ==== Clock ==== ==== Clock ====
  
-To create a free-running clock with user-selectable period and duty cycle you can combine two non-retriggerable one-shot cells. ​ The first cell's trigger is connected to logic high, but because it is non-retriggerable it will simply trigger itself whenever it has, thus outputting a pulse once per delay period. ​ That pulse triggers a second one-shot which generates the clock output whose duration sets the time the output signal is high (i.e. the duty cycle is the ratio of the one-shot duration with the delay period).+To create a free-running clock with user-selectable period and duty cycle you can combine two non-retriggerable one-shot cells. ​ The first cell's trigger is connected to logic high, but because it is non-retriggerable it will simply trigger itself whenever it has, thus outputting a pulse once per delay period. ​ That pulse triggers a second one-shot which generates the clock output whose duration sets the time the output signal is high (i.e. the duty cycle is the ratio of the one-shot duration with the delay period).  From the 4kHz internal clock it is possible to generate up to 2kHz clock by this means.
  
---> Script: clock signal on BNC1 output #+--> Script: clock signal on BNC3 output #
 <code java> <code java>
 // generate a clock signal based on the internal 4kHz clock, e.g. for triggering a camera // generate a clock signal based on the internal 4kHz clock, e.g. for triggering a camera
-// currently hard-codes using cells 1 and 2 and BNC output #1+// currently hard-codes using cells 1 and 2 and BNC output #3
  
 // variables to be edited by user // variables to be edited by user
-double clockFrequencyHz = 100.0;  // clock frequency in Hertz+double clockFrequencyHz = 100;  // clock frequency in Hertz
 double clockDutyCycle = 0.5;     // should be between 0 and 1 exclusive double clockDutyCycle = 0.5;     // should be between 0 and 1 exclusive
  
Line 258: Line 258:
 int addrEdge = 128; int addrEdge = 128;
 double ticsPerSecond = 4000.0; double ticsPerSecond = 4000.0;
-int addrOutputBNC1 ​33+int addrOutputBNC3 ​35
-int addrOneShotClk ​= 1; +int addrDelayNRT ​= 1; 
-int addrOneShotOut ​= 2;+int addrOneShot ​= 2;
  
 // figure out the cycle period and high period in terms of PLC "​tics"​ (4kHz) // figure out the cycle period and high period in terms of PLC "​tics"​ (4kHz)
-int clockPeriodTics = (int) (ticsPerSecond/​clockFrequencyHz + 0.5) - 1; +int clockPeriodTics = (int) (ticsPerSecond/​clockFrequencyHz + 0.5)
-int clockHighTics = (int) (clockPeriodTics * clockDutyCycle) ​+ 1;+print("​have " + (clockPeriodTics-1) + " (+1) tics in one-shot for actual frequency of " + ticsPerSecond/​(clockPeriodTics))
 +int clockHighTics = (int) (clockPeriodTics * clockDutyCycle);​
  
 // turn off updates to speed communication // turn off updates to speed communication
Line 270: Line 271:
 mmc.setProperty(plcName,​ propUpdates,​ valNo); mmc.setProperty(plcName,​ propUpdates,​ valNo);
  
-// do programming of one-shot cells +// do programming of one-shot ​and delay cells 
-mmc.setProperty(plcName,​ propPosition, ​addrOneShotClk);+mmc.setProperty(plcName,​ propPosition, ​addrDelayNRT);
 mmc.setProperty(plcName,​ propCellType,​ valOneShotNRT);​ mmc.setProperty(plcName,​ propCellType,​ valOneShotNRT);​
-mmc.setProperty(plcName,​ propCellConfig,​ clockPeriodTics);​+mmc.setProperty(plcName,​ propCellConfig, ​(clockPeriodTics-1));
 mmc.setProperty(plcName,​ propCellInput1,​ addrInvert + addrEdge); ​ // trigger cell as fast as we can, but NRT prevents re-triggering when active mmc.setProperty(plcName,​ propCellInput1,​ addrInvert + addrEdge); ​ // trigger cell as fast as we can, but NRT prevents re-triggering when active
 mmc.setProperty(plcName,​ propCellInput2,​ addrInvert + addrEdge); ​ // clock on every tic mmc.setProperty(plcName,​ propCellInput2,​ addrInvert + addrEdge); ​ // clock on every tic
  
-mmc.setProperty(plcName,​ propPosition, ​addrOneShotOut);+mmc.setProperty(plcName,​ propPosition, ​addrOneShot);
 mmc.setProperty(plcName,​ propCellType,​ valOneShotNRT);​ mmc.setProperty(plcName,​ propCellType,​ valOneShotNRT);​
 mmc.setProperty(plcName,​ propCellConfig,​ clockHighTics);​ mmc.setProperty(plcName,​ propCellConfig,​ clockHighTics);​
-mmc.setProperty(plcName,​ propCellInput1, ​addrOneShotClk);  // trigger cell as fast as we can, but NRT prevents re-triggering when active+mmc.setProperty(plcName,​ propCellInput1, ​addrDelayNRT);  // trigger cell as fast as we can, but NRT prevents re-triggering when active
 mmc.setProperty(plcName,​ propCellInput2,​ addrInvert + addrEdge); ​ // clock on every tic mmc.setProperty(plcName,​ propCellInput2,​ addrInvert + addrEdge); ​ // clock on every tic
  
 // connect to BNC output // connect to BNC output
-mmc.setProperty(plcName,​ propPosition, ​addrOutputBNC1); +mmc.setProperty(plcName,​ propPosition, ​addrOutputBNC3); 
-mmc.setProperty(plcName,​ propCellConfig, ​addrOneShotOut);+mmc.setProperty(plcName,​ propCellConfig, ​addrOneShot);
  
 // restore updates // restore updates
 mmc.setProperty(plcName,​ propUpdates,​ valUpdatesOriginal);​ mmc.setProperty(plcName,​ propUpdates,​ valUpdatesOriginal);​
 +
 +
  
  
tiger_programmable_logic_card.txt · Last modified: 2019/05/24 16:54 by jon