Ham

30 Reputation

4 Badges

8 years, 44 days

MaplePrimes Activity


These are replies submitted by Ham


I think you misunderstood me by Reversing. 

So, using what you did and a bit more, here is the best final result.

  restart;
  with(Logic):
  separation:= 1:
  logic:= &xor x[1] &xor x[2] &xor x[3]:
  TTOrginal:=TruthTable( logic, form=MOD2):
  result:= Q:
  # Now to Swap order of columns so out Timing Digram looks correct. IE final answer  is at the bottom
  TT:= DataFrame(seq(TTOrginal[j],j=upperbound(TTOrginal,2)..1,-1),
       columns=ListTools:-Reverse([ColumnLabels(TTOrginal)[1..-2][],result])):
  yAxisLabels:= ColumnLabels(TT):
  rows:= upperbound( TT, 1 ):
  columns:= upperbound( TT, 2):
  shift:= 1:  # shift y axis up so that result does not end on the axis line. Looks better and easier to upderst
  xAxis:= time:
  lineColours:= [red,seq(blue,i=2..columns)]:
  plotOptions:= xAxis=0..rows-1, title = cat("Timing Diagram for ", result),titlefont=[times,bold,18],
                color=lineColours,
                tickmarks= [ [],[seq( [i*(1+separation)+shift =0, 1+i*(1+separation)+shift=1][], i=0..columns-1)]],
                axis[1]= [gridlines= [[seq(i=i,i=0..rows)],colour= gray,linestyle= dash]]:
  toPW:=M->piecewise(seq( [xAxis<i, M[i]][], i=1..rows,1)):
  timeValues:= seq( toPW(TT[i])+ (1+separation)*(i-1)+ shift, i=1..columns,1):
  timePlots:= plot( [timeValues], plotOptions):
  labelValues:= seq( [(-1 + 3/rows),0.5 +shift+i*(1+separation), yAxisLabels[i+1]], i=0..columns-1,1):
  labelPlots:= plots:-textplot([labelValues], font=[times,bold,12]):
  plots:-display(timePlots, labelPlots);
 tabulate_id:= Tabulate(TTOrginal,width=35):
 DocumentTools:-SetProperty([tabulate_id, 'fillcolor'[2 .. (), 2 .. ()], white],[tabulate_id,width,"40%"]):
 DocumentTools:-SetProperty([tabulate_id, title,"Truth Table"],[tabulate_id,exterior,all]):
 DocumentTools:-SetProperty([tabulate_id, fillcolor[1, columns+1], red],[tabulate_id,width,"40%"]):
 DocumentTools:-SetProperty([tabulate_id, 'visible'[1 ..(), 1], false]):

 

``


 

Download Timing_Diagram_v2.mw

 

Thanks for the excellent replies. I was thinking about maually plotting each line!!

Still do not understand the piecewise function yet, but got the following working and reasonably close to what is expected in a Timing diagram.

  restart;
  with(Logic):
  TT:=TruthTable( x[1] &xor x[2] &xor x[3] &or x[4], form=MOD2):
  TT := SubsColumnLabel(TT, -1, Q):
  separation:= 2:
  yAxisLabels:= ColumnLabels(TT):

  rows:= upperbound( TT, 1 ):
  columns:= upperbound( TT, 2):
  xAxis:= time:
  lineColours:= [seq(blue,i=1..columns-1)]:
  lineColours:=[op(lineColours),'red']:
  plotOptions:= xAxis=0..rows-1, title = "Timing diagram",titlefont=[times,bold,18],
                color=lineColours,
                tickmarks= [ default,[seq( j= j mod 2, j=0..(rows-1),1)]],
                axis[1]= [gridlines= [[seq(j=j,j=0..rows)],colour= gray,linestyle= dash]]:
  toPW:=M->piecewise(seq( [xAxis<j, M[j]][], j=1..rows,1)):
  timeValues:= seq( toPW(TT[j])+ separation*(j-1), j=1..columns,1):
  timePlots:= plot( [timeValues], plotOptions):
  labelValues:= seq( [-1,(j-1)*separation+.5,yAxisLabels[j]], j=1..columns,1):
  labelPlots:= plots:-textplot([labelValues], font=[times,bold,12]):
  plots:-display(timePlots, labelPlots);
  tabulate_id:= Tabulate(TT,width=40):
  DocumentTools:-SetProperty([tabulate_id, 'fillcolor'[2 .. (), 2 .. ()], white],[tabulate_id,width,"40%"]):
  DocumentTools:-SetProperty([tabulate_id, title,"Truth Table"],[tabulate_id,exterior,all]):
  DocumentTools:-SetProperty([tabulate_id, fillcolor[1, 6], red],[tabulate_id,width,"40%"]):
  DocumentTools:-SetProperty([tabulate_id, 'visible'[1 ..(), 1], false]):
 

 

 

 

How do I reverse the order of the graphs so that x[1] is at the top and Q is at the bottom. I.E reverse the order.

Is my code efficient enough? And also I want separation between graphs to be between 1 and  2 (e.g. 1.5), however I could not get the separation to scale correctly.

Could not get Tabulate to display the Title, even though I could set it. Weird!

Once it it is reasonably sorted, I will request that MapleSoft add a timing graph to the Logic Package. Really it should be there.

Again A massive thanks to both of you.

Download Timing_Diagram.mw

I have had several versions of Maple that all did the same. At least I am not going crazy.

Will use the 1D Input.

:)

Page 1 of 1