Date: 201808
Local time of day: 1801-2400
Location: ZZZ.Airport, US
Flight conditions: VMC
Light: Dusk
Aircraft: Regional Jet 900 (CRJ900)
Operator: Air Carrier
Operating under: Part 91
Flight plan: IFR
Flight phase: Climb
Airspace: Class B ZZZ
ATC / advisory: TRACON ZZZ
Aircraft component: AHRS/ND
Component problem: Malfunctioning
Reporter organization: Air Carrier
Reporter function: Pilot Flying; Captain
Reporter qualification: Flight Crew Air Transport Pilot (ATP)
Human factors: Distraction; Situational Awareness; Time Pressure; Confusion
Second reporter function: Pilot Not Flying; First Officer
Anomaly: Aircraft Equipment Problem Less Severe; Deviation - Track / Heading All Types; Deviation / Discrepancy - Procedural Clearance
Detector: Person Air Traffic Control; Person Flight Crew
When detected: In-flight
Result: Air Traffic Control Issued New Clearance; Flight Crew Requested ATC Assistance / Clarification; Flight Crew Became Reoriented; Flight Crew Overcame Equipment Problem
Contributing factors: Aircraft; Human Factors
Primary problem: Aircraft

Narrative: We taxied out of ZZZ to Runway XX. I had briefed the departure briefing at the gate prior to taxi-out. The brief included our special considerations for Runway XX to put our aircraft in a DG Mode prior to take off. Just after being cleared to cross Runway XY; I switched the plane from Mag Mode to DG Mode and verified that the standby compass and both left and right headings indicated correctly. Upon taxiing on Runway XX and being cleared for takeoff; headings checked with runway heading.We took off and flew the [departure]. My pilot monitoring checked on with Departure and they assigned us a climb to 6000 feet. Shortly after; we were assigned a left turn to 310; followed by a left turn to 290. Upon leveling at 6000 feet at 250 knots on a heading of 290; I switched the aircraft back to Mag mode. ATC then assigned us direct to ZZZZZ and climb and maintain 15;000 feet. We executed direct ZZZZZ and selected Nav mode. I looked at the MFD and it showed ZZZZZ to our left and the aircraft was turning to the right. I now selected heading mode and notified ATC. He gave us a frequency change to Departure. After checking on with our new departure; we advised them we need a heading and could not proceed direct to ZZZZZ as we were having a navigation issue. He assigned us heading 290 and maintain 14;000 feet. Shortly after he turned us to 320. We received a TA right around this time showing a plane off our left 1000 feet below us.ATC then told us to turn right to 320 we told him we were on a 320 heading. He responded with 'turn more right; I will call for you to stop turning.' We complied. The pilot monitoring asked Departure what heading he was showing us on; he replied with we were [on] a heading of 250 and we told him we were showing we were on a heading of 350 (100 degrees off). Shortly after; he told us to stop our turn. Both the left and the right headings were the same leading us to believe our AHARS heading was correct and our compass heading was wrong; up until we confirmed this was not the case with ATC. In fact; our compass was right and our AHARS was wrong. We requested to level off at 14;000 on a straight heading so we could get our compass and AHARS slaved together. I had the First Officer slave his side to match the compass. Once he was done I transferred the autopilot to his side and slave mine to the compass. I then re-selected Mag mode and verified all the headings now aligned. I transferred the autopilot back to the left side and we told ATC we had fixed the issue and can proceed direct to ZZZZZ. He gave us direct ZZZZZ and climb and maintain 17;000. We had no further incident after this.From switching to DG to Mag mode; I did like I normally do leaving ZZZ; level accelerated flight. I had never had this issue before and am not sure what caused it. As a crew; [we] were discussing which instruments to trust; our compass or PFD's. Both PFD's were the same so we went with that. Only after ATC confirmed our MFD's were wrong were able to discover the compass was right. We should have trusted our compass earlier then we actually did.


Second narrative: Climbing out of ZZZ RWY XX; we were assigned 6000 feet and heading 310. The Captain was pilot flying. He turned the heading bug to 310; both heading indicators read 310 and we rolled wings level. At wings level and 250 knots and level at 6000 feet; we went back to MAG mode from DG. I remember watching both heading indicators match. I remember trying to verify with the compass and the compass was moving and swinging. I thought the compass was not reliable [and] would just tell Maintenance.Next; we received a turn to 290. Once again; Captain turned the heading bug to 290. Our next instruction was direct ZZZZZ climb and maintain 15;000 feet. When trying to go direct to ZZZZZ; the aircraft started banking to the right when our FMS MAP showed we should be going left. The Captain and I both noticed this and the Captain went to HDG mode and lined up ZZZZZ with a heading. I then looked up the heading indicators and both matched but they did not match the compass at all.We then checked on with [ATC] attempting to go direct ZZZZZ. He gave us direct ZZZZZ maintain 14;000. The Captain told me to tell ATC we are unable direct ZZZZZ and request headings. I did just that. I told ATC we are having problems with our FMS [and we] need heading and vectors. ATC sounded confused. ATC told us 290; we turned 290. Then he gave us 320 and we turned what we thought was 320. Then we got a TA. The TA never appeared closer to us than -1000 feet below. ATC told us to keep turning right and don't stop till he says. I asked ATC what heading he had us at and he said 250. Both our heading indicators showed 350. I slewed my heading indicator to roughly what the compass read because that seemed a closer match than the 350. Once my heading indicator was aligned; we put the autopilot into XFR mode so it would pull off of my heading indicator and the Captain slewed to match mine. After that; we verified with ATC that all seemed fixed. We then went direct ZZZZZ in FMS mode and took away the XFR mode.


Synopsis: CRJ-900 flight crew reported a track deviation resulted when the PFD's provided incorrect heading information.