{"action":"created","issue":{"url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/9","repository_url":"https://api.github.com/repos/SpinalHDL/SpinalDoc","labels_url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/9/comments","events_url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/9/events","html_url":"https://github.com/SpinalHDL/SpinalDoc/issues/9","id":162209980,"number":9,"title":"7-Seg Display and Spinal FSM","user":{"login":"laserbeak","id":3384800,"avatar_url":"https://avatars.githubusercontent.com/u/3384800?v=3","gravatar_id":"","url":"https://api.github.com/users/laserbeak","html_url":"https://github.com/laserbeak","followers_url":"https://api.github.com/users/laserbeak/followers","following_url":"https://api.github.com/users/laserbeak/following{/other_user}","gists_url":"https://api.github.com/users/laserbeak/gists{/gist_id}","starred_url":"https://api.github.com/users/laserbeak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laserbeak/subscriptions","organizations_url":"https://api.github.com/users/laserbeak/orgs","repos_url":"https://api.github.com/users/laserbeak/repos","events_url":"https://api.github.com/users/laserbeak/events{/privacy}","received_events_url":"https://api.github.com/users/laserbeak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-06-24T19:01:15Z","updated_at":"2016-06-24T20:09:12Z","closed_at":null,"body":"Hello,\r\nNot sure what the appropriate way to ask for help would be, so I'm asking here. I've been trying to drive a 7-Seg with the FSM feature, but Haven't been getting any luck. the 7-Seg just outputs the number 9. My latest attempt:\r\n\r\n```\r\nclass SevenSegFSM extends Component {\r\n  val io = new Bundle {\r\n    val HEX0 = out UInt (7 bit)\r\n  }\r\n\r\n  val segROM = Vec(UInt(7 bit),10)\r\n  segROM(0) := 0x40   //1000000\r\n  segROM(1) := 0x79   //1111001\r\n  segROM(2) := 0x24   //0100100\r\n  segROM(3) := 0x30   //0110000\r\n  segROM(4) := 0x19   //0011001\r\n  segROM(5) := 0x12   //0010010\r\n  segROM(6) := 0x2    //0000010\r\n  segROM(7) := 0x58   //1011000\r\n  segROM(8) := 0x0    //0000000\r\n  segROM(9) := 0x10   //0010000\r\n\r\n  val sighex0 = Reg(UInt(7 bit)) init(0)\r\n\r\n  val hexFSM = new StateMachine{\r\n    val stateA = new State with EntryPoint\r\n    val stateB = new StateDelay(cyclesCount = 27000000)\r\n    val stateC = new State\r\n\r\n    val counter = Reg(UInt(4 bit)) init(0)\r\n\r\n    stateA\r\n      .whenIsActive(goto(stateB))\r\n\r\n    stateB\r\n      .whenCompleted(\r\n        goto(stateC)\r\n      )\r\n        .whenIsActive({\r\n        counter := counter +1\r\n        sighex0 := segROM(counter)\r\n        when(counter === 0x9){\r\n          goto(stateC)\r\n        }\r\n      })\r\n\r\n    stateC\r\n      .whenIsActive {\r\n        counter := counter + 1\r\n        sighex0 := segROM(counter)\r\n        when(counter === 0x9) {\r\n          goto(stateA)\r\n        }\r\n      }\r\n  }\r\n\r\n  io.HEX0 := sighex0\r\n}\r\n\r\nobject SevenSegFSM {\r\n  def main(args: Array[String]) {\r\n    SpinalVhdl(new SevenSegFSM)\r\n  }\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/comments/228449841","html_url":"https://github.com/SpinalHDL/SpinalDoc/issues/9#issuecomment-228449841","issue_url":"https://api.github.com/repos/SpinalHDL/SpinalDoc/issues/9","id":228449841,"user":{"login":"Snoopy87","id":8439073,"avatar_url":"https://avatars.githubusercontent.com/u/8439073?v=3","gravatar_id":"","url":"https://api.github.com/users/Snoopy87","html_url":"https://github.com/Snoopy87","followers_url":"https://api.github.com/users/Snoopy87/followers","following_url":"https://api.github.com/users/Snoopy87/following{/other_user}","gists_url":"https://api.github.com/users/Snoopy87/gists{/gist_id}","starred_url":"https://api.github.com/users/Snoopy87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Snoopy87/subscriptions","organizations_url":"https://api.github.com/users/Snoopy87/orgs","repos_url":"https://api.github.com/users/Snoopy87/repos","events_url":"https://api.github.com/users/Snoopy87/events{/privacy}","received_events_url":"https://api.github.com/users/Snoopy87/received_events","type":"User","site_admin":false},"created_at":"2016-06-24T20:09:12Z","updated_at":"2016-06-24T20:09:12Z","body":"Hello,\r\n\r\nYou have an issue with your state machine...\r\n\r\nYour state machine goes from stateA to stateB. When stateB is active, the counter is incremented at each clock cycle, so after nine clock cycles, you exit from stateB to stateC... in stateC you do the same think as the stateB... Your 7-segments display all numbers but it goes to fast to see it. \r\n\r\nTry the code below, I do some modifications\r\n\r\n```\r\nclass SevenSegFSM extends Component {\r\n\r\n    val io = new Bundle {\r\n      val HEX0 = out Bits (7 bit)\r\n    }\r\n\r\n    val segROM = Vec(Bits(7 bit),10)\r\n    segROM(0) := \"1000000\"\r\n    segROM(1) := \"1111001\"\r\n    segROM(2) := \"0100100\"\r\n    segROM(3) := \"0110000\"\r\n    segROM(4) := \"0011001\"\r\n    segROM(5) := \"0010010\"\r\n    segROM(6) := \"0000010\"\r\n    segROM(7) := \"1011000\"\r\n    segROM(8) := \"0000000\"\r\n    segROM(9) := \"0010000\"\r\n\r\n    val hexFSM = new StateMachine{\r\n\r\n      val stateA = new StateDelay(cyclesCount = 27000000) with EntryPoint\r\n      val stateB = new State\r\n\r\n      val counter = Reg(UInt(4 bit)) init(0)\r\n      val sighex0 = Reg(Bits(7 bit)) init(0)\r\n\r\n\r\n      stateA\r\n        .whenCompleted(\r\n          counter := counter + 1\r\n          goto(stateB)\r\n        )\r\n\r\n      stateB\r\n        .whenIsActive { \r\n          sighex0 := segROM(counter)\r\n          goto(stateA)\r\n        }\r\n    }\r\n\r\n    io.HEX0 := hexFSM.sighex0\r\n  }\r\n```\r\n\r\n\r\nif you have any questions please don't hesitate to contact us\r\n"}}
{"actor":{"display_login":"Snoopy87"}}