The Rambam in Sefer Hamitzvot mitzva 4 describes the mitzvah of fearing Hashem, היא הציווי שנצטווינו להאמין ביראתו יתעלה ובמוראו, ובל נהיה שאננים ובוטחים - אלא (נחכה) [ונחוש] לביאת עונשו ית' בכל-עת. וזהו אמרו יתעלה: "את-ה' אלוקיך תירא" (דברים ו, יג). In the Yad in Yesoday HaTorah (2:2) he describes it וְהֵיאַךְ הִיא הַדֶּרֶךְ לְאַהֲבָתוֹ וְיִרְאָתוֹ. בְּשָׁעָה שֶׁיִּתְבּוֹנֵן הָאָדָם בְּמַעֲשָׂיו וּבְרוּאָיו הַנִּפְלָאִים הַגְּדוֹלִים וְיִרְאֶה מֵהֶן חָכְמָתוֹ שֶׁאֵין לָהּ עֵרֶךְ וְלֹא קֵץ מִיָּד הוּא אוֹהֵב וּמְשַׁבֵּחַ וּמְפָאֵר וּמִתְאַוֶּה תַּאֲוָה גְּדוֹלָה לֵידַע הַשֵּׁם הַגָּדוֹל. כְּמוֹ שֶׁאָמַר דָּוִד (תהילים מב ג) "צָמְאָה נַפְשִׁי לֵאלֹהִים לְאֵל חָי". וּכְשֶׁמְּחַשֵּׁב בַּדְּבָרִים הָאֵלּוּ עַצְמָן מִיָּד הוּא נִרְתָּע לַאֲחוֹרָיו וִיפַחֵד וְיוֹדֵעַ שֶׁהוּא בְּרִיָּה קְטַנָּה שְׁפָלָה אֲפֵלָה עוֹמֶדֶת בְּדַעַת קַלָּה מְעוּטָה לִפְנֵי תְּמִים דֵּעוֹת. כְּמוֹ שֶׁאָמַר דָּוִד (תהילים ח ד) "כִּי אֶרְאֶה שָׁמֶיךָ מַעֲשֵׂי אֶצְבְּעֹתֶיךָ" (תהילים ח ה) "מָה אֱנוֹשׁ כִּי תִזְכְּרֶנּוּ." The Achronim ask that in the Sefer Hamitzvort he describes it as what we generally call yirat haonesh but in the Yad he desribes it as yirat harommamut?
The Avodat Hamelech and others take the approach that both levels work to fulfill the mitzvah, The Emes Y'Yaakov here says the mitzvah is to fear Hashem, why one fears Hashem does not matter. In other words, the mitzvah of yirah is fulfilled as long as one has the fear of the Lord in them. That is fulfilled as long as one is afraid of Hashem. Why one fears Hashem may be motivated by altruistic reasons or merely to avoid punishment. However, either way is a fulfillment of the mitzvah, just in one case it is done lishma and in the other case it is not not (see Rambam Teshuva Ch. 10.)
However, why does the Rambam choose to tell us the mitzvah in terms of the lower level of yirah? The Panim Yafot explains the possuk the Rambam cites is talking about yirat haonesh:
Therefore, it reasons that the Rambam who cites this possuk as the source of the mitzvah, describes it as the yirah of the onash. In the Yad, the Rambam is discussing the level one should strive for, which is the yiray haromamut (based upon Pneninim M'bey Midrasha.)