typically your sub should follow your chords, it should be the bass note of the chord (root, first inversion, second inversion, ect) Typically its helpful to either write your melody to your chords or write your chords to your melody but if you try to tackle them completely separately thats how youre going to end up with clashing tones and dissonance you dont want.